Skip to content
Snippets Groups Projects
Commit 0ac73215 authored by Aidan Chalk's avatar Aidan Chalk
Browse files

Implemented a version for #16, tested and works correctly as far as I've found

parent 85b0d88c
No related branches found
No related tags found
No related merge requests found
...@@ -35,6 +35,21 @@ ...@@ -35,6 +35,21 @@
#define lock_unlock( l ) ( pthread_spin_unlock( l ) != 0 ) #define lock_unlock( l ) ( pthread_spin_unlock( l ) != 0 )
#define lock_unlock_blind( l ) pthread_spin_unlock( l ) #define lock_unlock_blind( l ) pthread_spin_unlock( l )
#else #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_type volatile int
#define lock_init( l ) ( *l = 0 ) #define lock_init( l ) ( *l = 0 )
#define lock_destroy( l ) 0 #define lock_destroy( l ) 0
...@@ -46,4 +61,5 @@ ...@@ -46,4 +61,5 @@
#define lock_trylock( l ) ( ( *(l) ) ? 1 : __sync_val_compare_and_swap( l , 0 , 1 ) ) #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( l ) ( __sync_val_compare_and_swap( l , 1 , 0 ) != 1 )
#define lock_unlock_blind( l ) __sync_val_compare_and_swap( l , 1 , 0 ) #define lock_unlock_blind( l ) __sync_val_compare_and_swap( l , 1 , 0 )
#endif
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment