Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use explicit atomic operations.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 1 Nov 2017 09:14:09 +0000 (10:14 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 1 Nov 2017 13:10:35 +0000 (14:10 +0100)
src/simix/smx_synchro.cpp
src/simix/smx_synchro_private.hpp

index 78c4935..6194069 100644 (file)
@@ -364,14 +364,13 @@ void SIMIX_cond_unref(smx_cond_t cond)
 
 void intrusive_ptr_add_ref(s_smx_cond_t *cond)
 {
 
 void intrusive_ptr_add_ref(s_smx_cond_t *cond)
 {
-  auto previous = (cond->refcount_)++;
+  auto previous = cond->refcount_.fetch_add(1);
   xbt_assert(previous != 0);
 }
 
 void intrusive_ptr_release(s_smx_cond_t *cond)
 {
   xbt_assert(previous != 0);
 }
 
 void intrusive_ptr_release(s_smx_cond_t *cond)
 {
-  auto count = --(cond->refcount_);
-  if (count == 0) {
+  if (cond->refcount_.fetch_sub(1) == 1) {
     xbt_assert(xbt_swag_size(cond->sleeping) == 0,
                 "Cannot destroy conditional since someone is still using it");
     xbt_swag_free(cond->sleeping);
     xbt_assert(xbt_swag_size(cond->sleeping) == 0,
                 "Cannot destroy conditional since someone is still using it");
     xbt_swag_free(cond->sleeping);
index 7349982..5846b04 100644 (file)
@@ -31,15 +31,12 @@ public:
   // boost::intrusive_ptr<Mutex> support:
   friend void intrusive_ptr_add_ref(MutexImpl* mutex)
   {
   // boost::intrusive_ptr<Mutex> support:
   friend void intrusive_ptr_add_ref(MutexImpl* mutex)
   {
-    // Atomic operation! Do not split in two instructions!
-    XBT_ATTRIB_UNUSED auto previous = (mutex->refcount_)++;
+    XBT_ATTRIB_UNUSED auto previous = mutex->refcount_.fetch_add(1);
     xbt_assert(previous != 0);
   }
   friend void intrusive_ptr_release(MutexImpl* mutex)
   {
     xbt_assert(previous != 0);
   }
   friend void intrusive_ptr_release(MutexImpl* mutex)
   {
-    // Atomic operation! Do not split in two instructions!
-    auto count = --(mutex->refcount_);
-    if (count == 0)
+    if (mutex->refcount_.fetch_sub(1) == 1)
       delete mutex;
   }
 
       delete mutex;
   }