Commit 8e7a1bae authored by Stefan Reif's avatar Stefan Reif
Browse files

Use a lock in the deliveredPacketTable

parent 8a477c84
Pipeline #1910 passed with stages
in 1 minute and 30 seconds
......@@ -40,6 +40,7 @@ PrrtDeliveredPacketTable *PrrtDeliveredPacketTable_create()
check_mem(fpt_prt);
fpt_prt->start = 1;
fpt_prt->bitmap = Bitmap_create(true, SEQNO_SPACE);
pthread_mutex_init(&fpt_prt->lock, NULL);
return fpt_prt;
error:
......@@ -56,6 +57,7 @@ bool PrrtDeliveredPacketTable_destroy(PrrtDeliveredPacketTable *t)
bool PrrtDeliveredPacketTable_test_set_is_number_relevant(PrrtDeliveredPacketTable *t, prrtSequenceNumber_t seqno)
{
pthread_mutex_lock(&t->lock);
bool res = is_position_relevant(t, seqno);
if(res) {
......@@ -64,6 +66,7 @@ bool PrrtDeliveredPacketTable_test_set_is_number_relevant(PrrtDeliveredPacketTab
move_start(t);
}
}
pthread_mutex_unlock(&t->lock);
return res;
}
......@@ -76,15 +79,18 @@ bool PrrtDeliveredPacketTable_test_is_block_relevant(PrrtDeliveredPacketTable *t
bool res = false;
int i;
pthread_mutex_lock(&t->lock);
for(i = 0; i < length; i++) {
res = res || is_position_relevant(t, (prrtSequenceNumber_t) (start + i));
}
pthread_mutex_unlock(&t->lock);
return res;
}
void PrrtDeliveredPacketTable_forward_start(PrrtDeliveredPacketTable *fpt_ptr, prrtSequenceNumber_t new_start)
{
pthread_mutex_lock(&fpt_ptr->lock);
prrtSequenceNumber_t seqno = fpt_ptr->start;
while (seqno != new_start) {
......@@ -95,4 +101,5 @@ void PrrtDeliveredPacketTable_forward_start(PrrtDeliveredPacketTable *fpt_ptr, p
// TODO: make more efficient by using the Bitmap_set_range function
fpt_ptr->start = seqno;
}
\ No newline at end of file
pthread_mutex_unlock(&fpt_ptr->lock);
}
......@@ -10,6 +10,7 @@
typedef struct {
prrtSequenceNumber_t start;
Bitmap* bitmap;
pthread_mutex_t lock;
} PrrtDeliveredPacketTable;
PrrtDeliveredPacketTable * PrrtDeliveredPacketTable_create(void);
......
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