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