mirror of
https://github.com/amd/blis.git
synced 2026-05-11 09:39:59 +00:00
Merge pull request #244 from kali/pthread-barrier-osx
add an adhoc impl for pthread_barrier
This commit is contained in:
@@ -33,7 +33,7 @@ matrix:
|
||||
# macOS with system compiler (clang)
|
||||
- os: osx
|
||||
compiler: clang
|
||||
env: OOT=0 TEST=0 SDE=0 THR="none" CONF="auto"
|
||||
env: OOT=0 TEST=1 SDE=0 THR="none" CONF="auto"
|
||||
# cortexa15 build and test (qemu)
|
||||
- os: linux
|
||||
compiler: arm-linux-gnueabihf-gcc
|
||||
|
||||
68
testsuite/src/pthread_barrier.h
Normal file
68
testsuite/src/pthread_barrier.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#if !defined(_POSIX_BARRIERS) || (_POSIX_BARRIERS < 0)
|
||||
|
||||
#ifndef PTHREAD_BARRIER_H_
|
||||
#define PTHREAD_BARRIER_H_
|
||||
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
|
||||
typedef int pthread_barrierattr_t;
|
||||
typedef struct
|
||||
{
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
int count;
|
||||
int tripCount;
|
||||
} pthread_barrier_t;
|
||||
|
||||
|
||||
inline int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count)
|
||||
{
|
||||
if(count == 0)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if(pthread_mutex_init(&barrier->mutex, 0) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if(pthread_cond_init(&barrier->cond, 0) < 0)
|
||||
{
|
||||
pthread_mutex_destroy(&barrier->mutex);
|
||||
return -1;
|
||||
}
|
||||
barrier->tripCount = count;
|
||||
barrier->count = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int pthread_barrier_destroy(pthread_barrier_t *barrier)
|
||||
{
|
||||
pthread_cond_destroy(&barrier->cond);
|
||||
pthread_mutex_destroy(&barrier->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int pthread_barrier_wait(pthread_barrier_t *barrier)
|
||||
{
|
||||
pthread_mutex_lock(&barrier->mutex);
|
||||
++(barrier->count);
|
||||
if(barrier->count >= barrier->tripCount)
|
||||
{
|
||||
barrier->count = 0;
|
||||
pthread_cond_broadcast(&barrier->cond);
|
||||
pthread_mutex_unlock(&barrier->mutex);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
pthread_cond_wait(&barrier->cond, &(barrier->mutex));
|
||||
pthread_mutex_unlock(&barrier->mutex);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // PTHREAD_BARRIER_H_
|
||||
#endif // _POSIX_BARRIERS
|
||||
@@ -54,6 +54,9 @@
|
||||
|
||||
// For pthreads API.
|
||||
#include <pthread.h>
|
||||
#if !defined(_POSIX_BARRIERS) || (_POSIX_BARRIERS < 0)
|
||||
#include "pthread_barrier.h"
|
||||
#endif
|
||||
|
||||
//
|
||||
// --- Constants and types -----------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user