diff --git a/src/lock.h b/src/lock.h index 89c450792e1f2334514df37e50d017da4322f99a..681221bc04423c82369c3dae14a944a7b282898d 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