Commit b6e34336 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

add/fix the option to use pthread spin/mutex locks instead of atomics.


Former-commit-id: 0a19e8d9e30d6159fd575e18aa64e63deb208292
parent 0a526dd7
......@@ -21,7 +21,8 @@
#include "inline.h"
#ifdef PTHREAD_LOCK
#ifdef PTHREAD_SPINLOCK
#include <pthread.h>
#define lock_type pthread_spinlock_t
#define lock_init( l ) ( pthread_spin_init( l , PTHREAD_PROCESS_PRIVATE ) != 0 )
#define lock_destroy( l ) ( pthread_spin_destroy( l ) != 0 )
......@@ -29,9 +30,18 @@
#define lock_trylock( l ) ( pthread_spin_lock( l ) != 0 )
#define lock_unlock( l ) ( pthread_spin_unlock( l ) != 0 )
#define lock_unlock_blind( l ) pthread_spin_unlock( l )
#elif defined(PTHREAD_LOCK)
#include <pthread.h>
#define lock_type pthread_mutex_t
#define lock_init( l ) ( pthread_mutex_init( l , NULL ) != 0 )
#define lock_destroy( l ) ( pthread_mutex_destroy( l ) != 0 )
#define lock_lock( l ) ( pthread_mutex_lock( l ) != 0 )
#define lock_trylock( l ) ( pthread_mutex_trylock( l ) != 0 )
#define lock_unlock( l ) ( pthread_mutex_unlock( l ) != 0 )
#define lock_unlock_blind( l ) pthread_mutex_unlock( l )
#else
#define lock_type volatile int
#define lock_init( l ) ( *l = 0 )
#define lock_init( l ) ( *(l) = 0 )
#define lock_destroy( l ) 0
INLINE static int lock_lock ( volatile int *l ) {
while ( __sync_val_compare_and_swap( l , 0 , 1 ) != 0 );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment