added memory fence call (this may not be a bug free version), so pcqueue_lock is...
authorGengbin Zheng <gzheng@illinois.edu>
Mon, 15 Oct 2007 22:06:55 +0000 (22:06 +0000)
committerGengbin Zheng <gzheng@illinois.edu>
Mon, 15 Oct 2007 22:06:55 +0000 (22:06 +0000)
src/arch/util/pcqueue.h

index cfee6b7c7384f03dc7e722d0fc1df95b3b3637e4..bc83c32bcf4572ba961cea4ea61c849295d323f1 100644 (file)
@@ -18,6 +18,7 @@
 #ifndef __PCQUEUE__
 #define __PCQUEUE__
 
+
 /*****************************************************************************
  * #define CMK_PCQUEUE_LOCK
  * PCQueue doesn't need any lock, the lock here is only 
  ****************************************************************************/
 /*#define CMK_PCQUEUE_LOCK  1 */
 
+#if CMK_PCQUEUE_LOCK || !defined(CMK_USE_MFENCE) || !CMK_USE_MFENCE
+#undef smp_rmb
+#undef smp_wmb
+#define smp_rmb()
+#define smp_wmb()
+#endif
+
 #define PCQueueSize 0x100
 
 typedef struct CircQueueStruct
@@ -136,6 +144,9 @@ char *PCQueuePop(PCQueue Q)
     CmiLock(Q->lock);
 #endif
     circ = Q->head;
+
+    smp_rmb();
+
     pull = circ->pull;
     data = circ->data[pull];
 #if XT3_ONLY_PCQUEUE_WORKAROUND
@@ -147,7 +158,9 @@ char *PCQueuePop(PCQueue Q)
       circ->data[pull] = 0;
       if (pull == PCQueueSize - 1) { /* just pulled the data from the last slot
                                      of this buffer */
+        smp_rmb();
         Q->head = circ-> next; /* next buffer must exist, because "Push"  */
+        CmiAssert(Q->head != NULL);
        
        /* FreeCircQueueStruct(circ); */
         free(circ);
@@ -191,12 +204,17 @@ void PCQueuePush(PCQueue Q, char *data)
 #endif
     /* MallocCircQueueStruct(circ); */
 
+    smp_wmb();
+
     Q->tail->next = circ;
     Q->tail = circ;
+
+    smp_wmb();
   }
   circ1->data[push] = data;
   circ1->push = (push + 1);
   Q->len ++;
+  smp_wmb();
 
 #ifdef CMK_PCQUEUE_LOCK
   CmiUnlock(Q->lock);