Signed-off-by: Ola Liljedahl <[email protected]>
---
 platform/linux-generic/include/api/odp_barrier.h |  2 +-
 platform/linux-generic/odp_barrier.c             | 17 +++++++++--------
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/platform/linux-generic/include/api/odp_barrier.h 
b/platform/linux-generic/include/api/odp_barrier.h
index 1790ea3..03e889d 100644
--- a/platform/linux-generic/include/api/odp_barrier.h
+++ b/platform/linux-generic/include/api/odp_barrier.h
@@ -42,7 +42,7 @@ typedef struct odp_barrier_t {
  * @param barrier    Barrier
  * @param count      Thread count
  */
-void odp_barrier_init(odp_barrier_t *barrier, int count);
+void odp_barrier_init(odp_barrier_t *barrier, uint32_t count);
 
 
 /**
diff --git a/platform/linux-generic/odp_barrier.c 
b/platform/linux-generic/odp_barrier.c
index 87be2a1..2f14e2f 100644
--- a/platform/linux-generic/odp_barrier.c
+++ b/platform/linux-generic/odp_barrier.c
@@ -8,11 +8,10 @@
 #include <odp_sync.h>
 #include <odp_spin_internal.h>
 
-void odp_barrier_init(odp_barrier_t *barrier, int count)
+void odp_barrier_init(odp_barrier_t *barrier, uint32_t count)
 {
        barrier->count = count;
-       barrier->bar   = 0;
-       odp_sync_stores();
+       odp_atomic_init_u32(&barrier->bar, 0);
 }
 
 /*
@@ -33,16 +32,18 @@ void odp_barrier_wait(odp_barrier_t *barrier)
        uint32_t count;
        int wasless;
 
-       odp_sync_stores();
-       wasless = barrier->bar < barrier->count;
+       __atomic_thread_fence(__ATOMIC_SEQ_CST);
        count   = odp_atomic_fetch_inc_u32(&barrier->bar);
+       wasless = count < barrier->count;
 
        if (count == 2*barrier->count-1) {
-               barrier->bar = 0;
+               /* Wrap around *atomically* */
+               odp_atomic_sub_u32(&barrier->bar, 2 * barrier->count);
        } else {
-               while ((barrier->bar < barrier->count) == wasless)
+               while ((odp_atomic_load_u32(&barrier->bar) < barrier->count)
+                               == wasless)
                        odp_spin();
        }
 
-       odp_mem_barrier();
+       __atomic_thread_fence(__ATOMIC_SEQ_CST);
 }
-- 
1.9.1


_______________________________________________
lng-odp mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to