changeset 7:08f0b4da7610

Works with pin2core.. not sure changes made..
author Me
date Wed, 01 Sep 2010 09:16:24 -0700
parents 174a7c2ca340
children 93bf3ffcc1fb
files BlockingQueue.c BlockingQueue.h
diffstat 2 files changed, 22 insertions(+), 12 deletions(-) [+]
line diff
     1.1 --- a/BlockingQueue.c	Wed Jul 28 13:13:01 2010 -0700
     1.2 +++ b/BlockingQueue.c	Wed Sep 01 09:16:24 2010 -0700
     1.3 @@ -136,13 +136,16 @@
     1.4     void **startOfData = Q->startOfData;
     1.5     void **endOfData   = Q->endOfData;
     1.6  
     1.7 -   int  success = FALSE;
     1.8 +   int  gotLock = FALSE;
     1.9  
    1.10     while( TRUE )
    1.11 -    { success =
    1.12 +    {    //this intrinsic returns true if the lock held "UNLOCKED", in which
    1.13 +         // case it now holds "LOCKED" -- if it already held "LOCKED", then
    1.14 +         // gotLock is FALSE
    1.15 +      gotLock =
    1.16           __sync_bool_compare_and_swap( &(Q->extractLock), UNLOCKED, LOCKED );
    1.17              //NOTE: checked assy, and it does lock correctly..
    1.18 -      if( success )
    1.19 +      if( gotLock )
    1.20         {
    1.21           void **insertPos  = Q->insertPos;
    1.22           void **extractPos = Q->extractPos;
    1.23 @@ -162,8 +165,7 @@
    1.24              return out;
    1.25            }
    1.26           else //Q is empty
    1.27 -          { success = FALSE;
    1.28 -            Q->extractLock = UNLOCKED;//have to try again, release for others
    1.29 +          { Q->extractLock = UNLOCKED;//empty, so release lock for others
    1.30            }
    1.31         }
    1.32           //Q is busy or empty
    1.33 @@ -180,12 +182,15 @@
    1.34     void **startOfData = Q->startOfData;
    1.35     void **endOfData   = Q->endOfData;
    1.36  
    1.37 -   int  success = FALSE;
    1.38 +   int  gotLock = FALSE;
    1.39  
    1.40     while( TRUE )
    1.41 -    { success =
    1.42 +    {    //this intrinsic returns true if the lock held "UNLOCKED", in which
    1.43 +         // case it now holds "LOCKED" -- if it already held "LOCKED", then
    1.44 +         // gotLock is FALSE
    1.45 +      gotLock =
    1.46           __sync_bool_compare_and_swap( &(Q->insertLock), UNLOCKED, LOCKED );
    1.47 -      if( success )
    1.48 +      if( gotLock )
    1.49         {
    1.50           void **insertPos  = Q->insertPos;
    1.51           void **extractPos = Q->extractPos;
    1.52 @@ -205,8 +210,7 @@
    1.53              return;
    1.54            }
    1.55           else //Q is full
    1.56 -          { success = FALSE;
    1.57 -            Q->insertLock = UNLOCKED;//have to try again, release for others
    1.58 +          { Q->insertLock = UNLOCKED;//full, so release lock for others
    1.59            }
    1.60         }
    1.61        tries++;
    1.62 @@ -247,6 +251,11 @@
    1.63     return retQ;
    1.64   }
    1.65  
    1.66 +void
    1.67 +freeSRSWQ( SRSWQueueStruc* Q )
    1.68 + {
    1.69 +   free( Q );
    1.70 + }
    1.71  
    1.72  void* readSRSWQ( SRSWQueueStruc* Q )
    1.73   { void *out    = 0;
    1.74 @@ -283,7 +292,7 @@
    1.75         }
    1.76           //Q is empty
    1.77        tries++;
    1.78 -      if( tries > 2 ) return 0; //long enough for writer to finish
    1.79 +      if( tries > 10 ) return NULL; //long enough for writer to finish
    1.80      }
    1.81   }
    1.82  
     2.1 --- a/BlockingQueue.h	Wed Jul 28 13:13:01 2010 -0700
     2.2 +++ b/BlockingQueue.h	Wed Sep 01 09:16:24 2010 -0700
     2.3 @@ -67,8 +67,9 @@
     2.4  SRSWQueueStruc;
     2.5  
     2.6  SRSWQueueStruc* makeSRSWQ();
     2.7 +void  freeSRSWQ( SRSWQueueStruc* Q );
     2.8  void* readSRSWQ( SRSWQueueStruc *Q );
     2.9 -void writeSRSWQ( void *in, SRSWQueueStruc *Q );
    2.10 +void  writeSRSWQ( void *in, SRSWQueueStruc *Q );
    2.11  
    2.12  
    2.13  //========= non-atomic instr S R M W queue ===========