Merge branch 'release-4-6'
[alexxy/gromacs.git] / src / gromacs / gmxlib / thread_mpi / barrier.c
index 42ef5213d024a537feb5357ec1e40f6b46022aa6..e1c5279897c64c0d8e79a20c89bb372f85c19664 100644 (file)
@@ -68,8 +68,8 @@ void tMPI_Barrier_init(tMPI_Barrier_t *barrier, int count)
 
 int tMPI_Barrier_wait(tMPI_Barrier_t *barrier)
 {
-    int    cycle;
-    int    status;
+    int cycle;
+    int status;
 
     /* We don't need to lock or use atomic ops here, since the cycle index
      * cannot change until after the last thread has performed the check
@@ -84,11 +84,11 @@ int tMPI_Barrier_wait(tMPI_Barrier_t *barrier)
     /* Decrement the count atomically and check if it is zero.
      * This will only be true for the last thread calling us.
      */
-    if (tMPI_Atomic_add_return( &(barrier->count), -1 ) <= 0)
+    if (tMPI_Atomic_fetch_add( &(barrier->count), -1 ) <= 1)
     {
         tMPI_Atomic_memory_barrier();
         tMPI_Atomic_set(&(barrier->count), barrier->threshold);
-        tMPI_Atomic_add_return(&(barrier->cycle), 1);
+        tMPI_Atomic_fetch_add(&(barrier->cycle), 1);
 
         status = -1;
     }