From 0ac7321513c9ac7210f31a3fa2cd42af02c49a72 Mon Sep 17 00:00:00 2001 From: Aidan Chalk <aidan.chalk@stfc.ac.uk> Date: Wed, 3 May 2017 15:12:50 +0100 Subject: [PATCH] Implemented a version for #16, tested and works correctly as far as I've found --- src/lock.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lock.h b/src/lock.h index 89c4507..681221b 100644 --- a/src/lock.h +++ b/src/lock.h @@ -35,6 +35,21 @@ #define lock_unlock( l ) ( pthread_spin_unlock( l ) != 0 ) #define lock_unlock_blind( l ) pthread_spin_unlock( l ) #else + #ifdef HAVE_OPENMP + #define lock_type omp_lock_t + #define lock_init( l ) ( omp_init_lock( l ) ) + #define lock_destroy( l ) ( omp_destroy_lock( l ) ) + INLINE static int lock_lock ( omp_lock_t *l ) { + omp_set_lock( l ); + return 0; + } + INLINE static int lock_trylock ( omp_lock_t *l ) { + return (omp_test_lock( l )==0); + } + #define lock_unlock( l ) ( omp_unset_lock( l ) ) + #define lock_unlock_blind( l ) ( omp_unset_lock( l ) ) + #else + #define lock_type volatile int #define lock_init( l ) ( *l = 0 ) #define lock_destroy( l ) 0 @@ -46,4 +61,5 @@ #define lock_trylock( l ) ( ( *(l) ) ? 1 : __sync_val_compare_and_swap( l , 0 , 1 ) ) #define lock_unlock( l ) ( __sync_val_compare_and_swap( l , 1 , 0 ) != 1 ) #define lock_unlock_blind( l ) __sync_val_compare_and_swap( l , 1 , 0 ) + #endif #endif -- GitLab