mirror of
https://github.com/amd/blis.git
synced 2026-05-11 09:39:59 +00:00
use GCC intrinsic instead of pthread_mutex for atomic increment and fetch
This commit is contained in:
@@ -44,14 +44,18 @@ int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t
|
||||
barrier->n_threads = count;
|
||||
barrier->sense = 0;
|
||||
barrier->threads_arrived = 0;
|
||||
#ifdef BLIS_USE_PTHREAD_MUTEX
|
||||
pthread_mutex_init( &barrier->mutex, NULL );
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_barrier_destroy(pthread_barrier_t *barrier)
|
||||
{
|
||||
if( barrier == NULL ) return 0;
|
||||
#ifdef BLIS_USE_PTHREAD_MUTEX
|
||||
pthread_mutex_destroy( &barrier->mutex );
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -61,9 +65,13 @@ int pthread_barrier_wait(pthread_barrier_t *barrier)
|
||||
bool_t my_sense = barrier->sense;
|
||||
dim_t my_threads_arrived;
|
||||
|
||||
#ifdef BLIS_USE_PTHREAD_MUTEX
|
||||
pthread_mutex_lock( &barrier->mutex );
|
||||
my_threads_arrived = ++(barrier->threads_arrived);
|
||||
pthread_mutex_unlock( &barrier->mutex );
|
||||
#else
|
||||
my_threads_arrived = __sync_add_and_fetch(&(barrier->threads_arrived), 1);
|
||||
#endif
|
||||
|
||||
if( my_threads_arrived == barrier->n_threads ) {
|
||||
barrier->threads_arrived = 0;
|
||||
|
||||
@@ -44,7 +44,9 @@ typedef int pthread_barrierattr_t;
|
||||
|
||||
struct pthread_barrier_s
|
||||
{
|
||||
#ifdef BLIS_USE_PTHREAD_MUTEX
|
||||
pthread_mutex_t mutex;
|
||||
#endif
|
||||
bool_t sense;
|
||||
dim_t threads_arrived;
|
||||
dim_t n_threads;
|
||||
|
||||
Reference in New Issue
Block a user