瀏覽代碼

cmThread:Added cmThPtrCAS()

master
kpl 12 年之前
父節點
當前提交
6b445b0f9d
共有 2 個文件被更改,包括 21 次插入6 次删除
  1. 18
    6
      cmThread.c
  2. 3
    0
      cmThread.h

+ 18
- 6
cmThread.c 查看文件

@@ -12,7 +12,6 @@
12 12
 #include <unistd.h>  // usleep
13 13
 //#include <atomic_ops.h>
14 14
 
15
-
16 15
 cmThreadH_t cmThreadNullHandle = {NULL};
17 16
 
18 17
 enum
@@ -102,10 +101,12 @@ cmThThread_t* _cmThThreadFromHandle( cmThreadH_t h )
102 101
 cmThRC_t _cmThWaitForState( cmThThread_t* t, unsigned stateId )
103 102
 {
104 103
   unsigned waitTimeMicroSecs = 0;
104
+
105 105
   while( t->state != stateId && waitTimeMicroSecs < t->waitMicroSecs )
106 106
   {
107
-    usleep( t->waitMicroSecs );
108
-    waitTimeMicroSecs += t->waitMicroSecs;
107
+    //usleep( t->waitMicroSecs );
108
+    usleep( 15000 );
109
+    waitTimeMicroSecs += 15000; //t->waitMicroSecs;
109 110
   }
110 111
 
111 112
   return t->state==stateId ? kOkThRC :  kTimeOutThRC;
@@ -1261,6 +1262,16 @@ bool     cmThUIntCAS(  unsigned* addr, unsigned old, unsigned new )
1261 1262
 bool     cmThFloatCAS( float*    addr, float    old, float    new )
1262 1263
 { return  __sync_bool_compare_and_swap((unsigned*)addr, *(unsigned*)(&old),*(unsigned*)(&new)); }
1263 1264
 
1265
+bool     cmThPtrCAS(   void*    addr, void*    old, void*    neww )
1266
+{
1267
+#ifdef OS_64
1268
+  return  __sync_bool_compare_and_swap((long long*)addr, (long long)old, (long long)neww); 
1269
+#else
1270
+  return  __sync_bool_compare_and_swap((int*)addr,(int)old,(int)neww); 
1271
+#endif
1272
+}
1273
+
1274
+
1264 1275
 
1265 1276
 void     cmThIntIncr(  int*      addr, int      incr )
1266 1277
 {
@@ -1432,7 +1443,8 @@ void* cmTsMp1cCbArg( cmTsMp1cH_t h )
1432 1443
   return p->cbArg;
1433 1444
 }
1434 1445
 
1435
-#define CAS(addr,old,new) __sync_bool_compare_and_swap(addr,old,new)
1446
+//#define CAS(addr,old,new) __sync_bool_compare_and_swap(addr,old,new)
1447
+//#define CAS(addr,old,neww) cmThPtrCAS(addr,old,neww)
1436 1448
 
1437 1449
 cmThRC_t   cmTsMp1cEnqueueSegMsg( cmTsMp1cH_t h, const void* msgPtrArray[], unsigned msgByteCntArray[], unsigned arrayCnt )
1438 1450
 {
@@ -1512,7 +1524,7 @@ cmThRC_t   cmTsMp1cEnqueueSegMsg( cmTsMp1cH_t h, const void* msgPtrArray[], unsi
1512 1524
   {
1513 1525
     old_hp = p->ilp;
1514 1526
     new_hp = hp;
1515
-  }while(!CAS(&p->ilp,old_hp,new_hp));
1527
+  }while(!cmThPtrCAS(&p->ilp,old_hp,new_hp));
1516 1528
 
1517 1529
   // link the prev recd to this recd
1518 1530
   if( old_hp != NULL )
@@ -1527,7 +1539,7 @@ cmThRC_t   cmTsMp1cEnqueueSegMsg( cmTsMp1cH_t h, const void* msgPtrArray[], unsi
1527 1539
     if( old_hp != NULL )
1528 1540
       break;
1529 1541
     
1530
-  }while(!CAS(&p->olp,old_hp,new_hp));
1542
+  }while(!cmThPtrCAS(&p->olp,old_hp,new_hp));
1531 1543
 
1532 1544
   return rc;
1533 1545
 }

+ 3
- 0
cmThread.h 查看文件

@@ -226,6 +226,9 @@ extern "C" {
226 226
   bool     cmThUIntCAS(  unsigned* addr, unsigned old, unsigned neww );
227 227
   bool     cmThFloatCAS( float*    addr, float    old, float    neww );
228 228
 
229
+  // Note: voidPtrPtr is must really be a pointer to a pointer.
230
+  bool     cmThPtrCAS(   void* voidPtrPtr, void*    old, void*    neww );
231
+
229 232
   // Thread safe increment and decrement implemented in terms of
230 233
   // cmThXXXCAS().
231 234
   void     cmThIntIncr(  int*      addr, int      incr );

Loading…
取消
儲存