mdbx-test: extend darwin-pthread-barrier for multiprocess-shared.

This commit is contained in:
Leonid Yuriev 2019-08-13 02:37:29 +03:00
parent 3f64d45819
commit 32a5b9089b
2 changed files with 34 additions and 29 deletions

View File

@ -33,50 +33,51 @@
#define __unused __attribute__((unused)) #define __unused __attribute__((unused))
int pthread_barrierattr_init(pthread_barrierattr_t *attr __unused) { return 0; } int pthread_barrierattr_init(pthread_barrierattr_t *attr) {
memset(attr, 0, sizeof(pthread_barrierattr_t));
int pthread_barrierattr_destroy(pthread_barrierattr_t *attr __unused) { int m = pthread_mutexattr_init(&attr->mattr);
return 0; int c = pthread_condattr_init(&attr->cattr);
return m ? m : c;
} }
int pthread_barrierattr_getpshared( int pthread_barrierattr_destroy(pthread_barrierattr_t *attr) {
const pthread_barrierattr_t *__restrict attr __unused, int c = pthread_condattr_destroy(&attr->cattr);
int *__restrict pshared) { int m = pthread_mutexattr_destroy(&attr->mattr);
*pshared = PTHREAD_PROCESS_PRIVATE; return m ? m : c;
return 0;
} }
int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr __unused, int pthread_barrierattr_getpshared(const pthread_barrierattr_t *__restrict attr,
int pshared) { int *__restrict pshared) {
if (pshared != PTHREAD_PROCESS_PRIVATE) { return pthread_condattr_getpshared(&attr->cattr, pshared);
errno = EINVAL; }
return -1;
} int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared) {
return 0; int m = pthread_mutexattr_setpshared(&attr->mattr, pshared);
int c = pthread_condattr_setpshared(&attr->cattr, pshared);
return m ? m : c;
} }
int pthread_barrier_init(pthread_barrier_t *__restrict barrier, int pthread_barrier_init(pthread_barrier_t *__restrict barrier,
const pthread_barrierattr_t *__restrict attr __unused, const pthread_barrierattr_t *__restrict attr,
unsigned count) { unsigned count) {
if (count == 0) { if (count == 0)
errno = EINVAL; return errno = EINVAL;
return -1;
}
if (pthread_mutex_init(&barrier->mutex, 0) < 0) { int rc = pthread_mutex_init(&barrier->mutex, attr ? &attr->mattr : 0);
return -1; if (rc)
} return rc;
if (pthread_cond_init(&barrier->cond, 0) < 0) {
rc = pthread_cond_init(&barrier->cond, attr ? &attr->cattr : 0);
if (rc) {
int errno_save = errno; int errno_save = errno;
pthread_mutex_destroy(&barrier->mutex); pthread_mutex_destroy(&barrier->mutex);
errno = errno_save; errno = errno_save;
return -1; return rc;
} }
barrier->limit = count; barrier->limit = count;
barrier->count = 0; barrier->count = 0;
barrier->phase = 0; barrier->phase = 0;
return 0; return 0;
} }
@ -87,7 +88,10 @@ int pthread_barrier_destroy(pthread_barrier_t *barrier) {
} }
int pthread_barrier_wait(pthread_barrier_t *barrier) { int pthread_barrier_wait(pthread_barrier_t *barrier) {
pthread_mutex_lock(&barrier->mutex); int rc = pthread_mutex_lock(&barrier->mutex);
if (rc)
return rc;
barrier->count++; barrier->count++;
if (barrier->count >= barrier->limit) { if (barrier->count >= barrier->limit) {
barrier->phase++; barrier->phase++;

View File

@ -48,7 +48,8 @@ extern "C" {
#endif #endif
typedef struct { typedef struct {
char unused_pad; pthread_mutexattr_t mattr;
pthread_condattr_t cattr;
} pthread_barrierattr_t; } pthread_barrierattr_t;
typedef struct { typedef struct {