X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Frmr%2Fcommon%2Fsrc%2Fring_static.c;h=b54d8152a5feed100c665971cf03608f35b59e57;hb=6d112571b27574ae857da7cb8dc8758ffee4ff60;hp=37bb4dbcf3600a9fa864e151130c92bc654297ad;hpb=ab6d04ce30514b16ba5821fcc788157b4779a4a3;p=ric-plt%2Flib%2Frmr.git diff --git a/src/rmr/common/src/ring_static.c b/src/rmr/common/src/ring_static.c index 37bb4db..b54d815 100644 --- a/src/rmr/common/src/ring_static.c +++ b/src/rmr/common/src/ring_static.c @@ -166,6 +166,7 @@ static inline void* uta_ring_extract( void* vr ) { ring_t* r; uint16_t ti; // real index in data int64_t ctr; // pfd counter + void* data; if( !RING_FAST ) { // compiler should drop the conditional when always false if( (r = (ring_t*) vr) == NULL ) { @@ -199,10 +200,14 @@ future -- investigate if it's possible only to set/clear when empty or going to } */ + data = r->data[ti]; // secure data and clear before letting go of the lock + r->data[ti] = NULL; + if( r->rgate != NULL ) { // if locked above... pthread_mutex_unlock( r->rgate ); } - return r->data[ti]; + + return data; } /* @@ -232,6 +237,12 @@ static inline int uta_ring_insert( void* vr, void* new_data ) { return 0; } + r->data[r->head] = new_data; + r->head++; + if( r->head >= r->nelements ) { + r->head = 0; + } + write( r->pfd, &inc, sizeof( inc ) ); /* future -- investigate if it's possible only to set/clear when empty or going to empty @@ -239,12 +250,6 @@ future -- investigate if it's possible only to set/clear when empty or going to } */ - r->data[r->head] = new_data; - r->head++; - if( r->head >= r->nelements ) { - r->head = 0; - } - if( r->wgate != NULL ) { // if lock exists we must unlock before going pthread_mutex_unlock( r->wgate ); }