Commit 460ad13d authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

ReceiveDataQueue only retrieves first element from BPTree.

parent c0e863ee
Pipeline #1681 failed with stages
in 1 minute and 15 seconds
...@@ -65,27 +65,24 @@ PrrtPacket * PrrtReceiveDataQueue_get_packet_wait(PrrtReceiveDataQueue *q, prrtT ...@@ -65,27 +65,24 @@ PrrtPacket * PrrtReceiveDataQueue_get_packet_wait(PrrtReceiveDataQueue *q, prrtT
PrrtPacket *PrrtReceiveDataQueue_get_packet(PrrtReceiveDataQueue *q, prrtTimestamp_t start, prrtTimestamp_t stop) { PrrtPacket *PrrtReceiveDataQueue_get_packet(PrrtReceiveDataQueue *q, prrtTimestamp_t start, prrtTimestamp_t stop) {
PrrtPacket *packet = NULL; PrrtPacket *packet = NULL;
List *packets = List_create();
check(pthread_mutex_lock(&q->lock) == EXIT_SUCCESS, "Lock failed."); check(pthread_mutex_lock(&q->lock) == EXIT_SUCCESS, "Lock failed.");
if (start > stop) { if (start > stop) {
BPTree_get_range(q->tree, packets, (BPTreeKey_t) start, TIMESTAMP_SPACE-1); packet = BPTree_get_first_in_range(q->tree, (BPTreeKey_t) start, TIMESTAMP_SPACE-1);
BPTree_get_range(q->tree, packets, 0, (BPTreeKey_t) stop); if (packet == NULL) {
packet = BPTree_get_first_in_range(q->tree, 0, (BPTreeKey_t) stop);
}
} else { } else {
BPTree_get_range(q->tree, packets, (BPTreeKey_t) start, (BPTreeKey_t) stop); packet = BPTree_get_first_in_range(q->tree, (BPTreeKey_t) start, (BPTreeKey_t) stop);
} }
if(packet != NULL) {
if(List_count(packets) > 0) {
packet = List_shift(packets);
q->tree = BPTree_delete(q->tree, PrrtDataPacket_packet_timeout(packet)); q->tree = BPTree_delete(q->tree, PrrtDataPacket_packet_timeout(packet));
} }
check(pthread_mutex_unlock(&q->lock) == EXIT_SUCCESS, "Unlock failed."); check(pthread_mutex_unlock(&q->lock) == EXIT_SUCCESS, "Unlock failed.");
List_destroy(packets);
return packet; return packet;
error: error:
......
...@@ -1056,6 +1056,15 @@ void BPTree_get_range(BPTreeNode *root, List *list, BPTreeKey_t key_start, BPTre ...@@ -1056,6 +1056,15 @@ void BPTree_get_range(BPTreeNode *root, List *list, BPTreeKey_t key_start, BPTre
} }
} }
void *BPTree_get_first_in_range(BPTreeNode *root, BPTreeKey_t key_start, BPTreeKey_t key_end) {
BPTreeKey_t i;
BPTreeNode *n = find_leaf(root, key_start);
if (n == NULL) return NULL;
for (i = 0; i < n->num_keys && n->keys[i] < key_start; i++);
if (i == n->num_keys) return NULL;
return ((BPTreeRecord *) n->pointers[i])->value;
}
uint32_t BPTree_size(BPTreeNode *root) { uint32_t BPTree_size(BPTreeNode *root) {
BPTreeNode *n = root; BPTreeNode *n = root;
uint32_t count = 0; uint32_t count = 0;
......
...@@ -75,6 +75,7 @@ BPTreeNode *BPTree_delete(BPTreeNode *root, BPTreeKey_t key); ...@@ -75,6 +75,7 @@ BPTreeNode *BPTree_delete(BPTreeNode *root, BPTreeKey_t key);
BPTreeNode *BPTree_destroy(BPTreeNode *root); BPTreeNode *BPTree_destroy(BPTreeNode *root);
void *BPTree_get(BPTreeNode *root, BPTreeKey_t key); void *BPTree_get(BPTreeNode *root, BPTreeKey_t key);
void BPTree_get_range(BPTreeNode *root, List *list, BPTreeKey_t key_start, BPTreeKey_t key_end); void BPTree_get_range(BPTreeNode *root, List *list, BPTreeKey_t key_start, BPTreeKey_t key_end);
void *BPTree_get_first_in_range(BPTreeNode *root, BPTreeKey_t key_start, BPTreeKey_t key_end);
// Helpers // Helpers
void BPTree_print(BPTreeNode *root); void BPTree_print(BPTreeNode *root);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment