# HG changeset patch # User Me # Date 1283357784 25200 # Node ID 08f0b4da76106323f6eb3bd7d2391506f5252a70 # Parent 174a7c2ca340897ab50d7d82715479d0cce0c028 Works with pin2core.. not sure changes made.. diff -r 174a7c2ca340 -r 08f0b4da7610 BlockingQueue.c --- a/BlockingQueue.c Wed Jul 28 13:13:01 2010 -0700 +++ b/BlockingQueue.c Wed Sep 01 09:16:24 2010 -0700 @@ -136,13 +136,16 @@ void **startOfData = Q->startOfData; void **endOfData = Q->endOfData; - int success = FALSE; + int gotLock = FALSE; while( TRUE ) - { success = + { //this intrinsic returns true if the lock held "UNLOCKED", in which + // case it now holds "LOCKED" -- if it already held "LOCKED", then + // gotLock is FALSE + gotLock = __sync_bool_compare_and_swap( &(Q->extractLock), UNLOCKED, LOCKED ); //NOTE: checked assy, and it does lock correctly.. - if( success ) + if( gotLock ) { void **insertPos = Q->insertPos; void **extractPos = Q->extractPos; @@ -162,8 +165,7 @@ return out; } else //Q is empty - { success = FALSE; - Q->extractLock = UNLOCKED;//have to try again, release for others + { Q->extractLock = UNLOCKED;//empty, so release lock for others } } //Q is busy or empty @@ -180,12 +182,15 @@ void **startOfData = Q->startOfData; void **endOfData = Q->endOfData; - int success = FALSE; + int gotLock = FALSE; while( TRUE ) - { success = + { //this intrinsic returns true if the lock held "UNLOCKED", in which + // case it now holds "LOCKED" -- if it already held "LOCKED", then + // gotLock is FALSE + gotLock = __sync_bool_compare_and_swap( &(Q->insertLock), UNLOCKED, LOCKED ); - if( success ) + if( gotLock ) { void **insertPos = Q->insertPos; void **extractPos = Q->extractPos; @@ -205,8 +210,7 @@ return; } else //Q is full - { success = FALSE; - Q->insertLock = UNLOCKED;//have to try again, release for others + { Q->insertLock = UNLOCKED;//full, so release lock for others } } tries++; @@ -247,6 +251,11 @@ return retQ; } +void +freeSRSWQ( SRSWQueueStruc* Q ) + { + free( Q ); + } void* readSRSWQ( SRSWQueueStruc* Q ) { void *out = 0; @@ -283,7 +292,7 @@ } //Q is empty tries++; - if( tries > 2 ) return 0; //long enough for writer to finish + if( tries > 10 ) return NULL; //long enough for writer to finish } } diff -r 174a7c2ca340 -r 08f0b4da7610 BlockingQueue.h --- a/BlockingQueue.h Wed Jul 28 13:13:01 2010 -0700 +++ b/BlockingQueue.h Wed Sep 01 09:16:24 2010 -0700 @@ -67,8 +67,9 @@ SRSWQueueStruc; SRSWQueueStruc* makeSRSWQ(); +void freeSRSWQ( SRSWQueueStruc* Q ); void* readSRSWQ( SRSWQueueStruc *Q ); -void writeSRSWQ( void *in, SRSWQueueStruc *Q ); +void writeSRSWQ( void *in, SRSWQueueStruc *Q ); //========= non-atomic instr S R M W queue ===========