Selaa lähdekoodia

cmThread:Added cmThPtrCAS()

master
kpl 11 vuotta sitten
vanhempi
commit
6b445b0f9d
2 muutettua tiedostoa jossa 21 lisäystä ja 6 poistoa
  1. 18
    6
      cmThread.c
  2. 3
    0
      cmThread.h

+ 18
- 6
cmThread.c Näytä tiedosto

12
 #include <unistd.h>  // usleep
12
 #include <unistd.h>  // usleep
13
 //#include <atomic_ops.h>
13
 //#include <atomic_ops.h>
14
 
14
 
15
-
16
 cmThreadH_t cmThreadNullHandle = {NULL};
15
 cmThreadH_t cmThreadNullHandle = {NULL};
17
 
16
 
18
 enum
17
 enum
102
 cmThRC_t _cmThWaitForState( cmThThread_t* t, unsigned stateId )
101
 cmThRC_t _cmThWaitForState( cmThThread_t* t, unsigned stateId )
103
 {
102
 {
104
   unsigned waitTimeMicroSecs = 0;
103
   unsigned waitTimeMicroSecs = 0;
104
+
105
   while( t->state != stateId && waitTimeMicroSecs < t->waitMicroSecs )
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
   return t->state==stateId ? kOkThRC :  kTimeOutThRC;
112
   return t->state==stateId ? kOkThRC :  kTimeOutThRC;
1261
 bool     cmThFloatCAS( float*    addr, float    old, float    new )
1262
 bool     cmThFloatCAS( float*    addr, float    old, float    new )
1262
 { return  __sync_bool_compare_and_swap((unsigned*)addr, *(unsigned*)(&old),*(unsigned*)(&new)); }
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
 void     cmThIntIncr(  int*      addr, int      incr )
1276
 void     cmThIntIncr(  int*      addr, int      incr )
1266
 {
1277
 {
1432
   return p->cbArg;
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
 cmThRC_t   cmTsMp1cEnqueueSegMsg( cmTsMp1cH_t h, const void* msgPtrArray[], unsigned msgByteCntArray[], unsigned arrayCnt )
1449
 cmThRC_t   cmTsMp1cEnqueueSegMsg( cmTsMp1cH_t h, const void* msgPtrArray[], unsigned msgByteCntArray[], unsigned arrayCnt )
1438
 {
1450
 {
1512
   {
1524
   {
1513
     old_hp = p->ilp;
1525
     old_hp = p->ilp;
1514
     new_hp = hp;
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
   // link the prev recd to this recd
1529
   // link the prev recd to this recd
1518
   if( old_hp != NULL )
1530
   if( old_hp != NULL )
1527
     if( old_hp != NULL )
1539
     if( old_hp != NULL )
1528
       break;
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
   return rc;
1544
   return rc;
1533
 }
1545
 }

+ 3
- 0
cmThread.h Näytä tiedosto

226
   bool     cmThUIntCAS(  unsigned* addr, unsigned old, unsigned neww );
226
   bool     cmThUIntCAS(  unsigned* addr, unsigned old, unsigned neww );
227
   bool     cmThFloatCAS( float*    addr, float    old, float    neww );
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
   // Thread safe increment and decrement implemented in terms of
232
   // Thread safe increment and decrement implemented in terms of
230
   // cmThXXXCAS().
233
   // cmThXXXCAS().
231
   void     cmThIntIncr(  int*      addr, int      incr );
234
   void     cmThIntIncr(  int*      addr, int      incr );

Loading…
Peruuta
Tallenna