libroot: Implemented pthread barriers
This is an implementation of pthread barriers pursuant to the relevant specification. Barriers are essentially a special case of conditional variables, such that all threads waiting on one are woken up when the number of waiters reaches a number provided at the initialization of the barrier. In view of that, this implementation mimics the implementation of pthread_cond, except it is more specialized and self-contained. Signed-off-by: Jérôme Duval <[email protected]>
This commit is contained in:
committed by
Jérôme Duval
parent
efd1e1eee8
commit
0e0f49e799
@@ -114,6 +114,20 @@ extern int pthread_mutexattr_setpshared(pthread_mutexattr_t *mutexAttr,
|
||||
int processShared);
|
||||
extern int pthread_mutexattr_settype(pthread_mutexattr_t *mutexAttr, int type);
|
||||
|
||||
/* barrier functions */
|
||||
extern int pthread_barrier_init(pthread_barrier_t *barrier,
|
||||
const pthread_barrierattr_t *attr, unsigned count);
|
||||
extern int pthread_barrier_destroy(pthread_barrier_t *barrier);
|
||||
extern int pthread_barrier_wait(pthread_barrier_t *barrier);
|
||||
|
||||
/* barrier attribute functions */
|
||||
extern int pthread_barrierattr_destroy(pthread_barrierattr_t *attr);
|
||||
extern int pthread_barrierattr_getpshared(const pthread_barrierattr_t *attr,
|
||||
int *shared);
|
||||
extern int pthread_barrierattr_init(pthread_barrierattr_t *attr);
|
||||
extern int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr,
|
||||
int shared);
|
||||
|
||||
/* condition variable functions */
|
||||
extern int pthread_cond_destroy(pthread_cond_t *cond);
|
||||
extern int pthread_cond_init(pthread_cond_t *cond,
|
||||
|
||||
@@ -60,6 +60,8 @@ typedef struct __timer_t* timer_t;
|
||||
|
||||
typedef struct _pthread_thread *pthread_t;
|
||||
typedef struct _pthread_attr *pthread_attr_t;
|
||||
typedef struct _pthread_barrier pthread_barrier_t;
|
||||
typedef struct _pthread_barrierattr *pthread_barrierattr_t;
|
||||
typedef struct _pthread_mutex pthread_mutex_t;
|
||||
typedef struct _pthread_mutexattr *pthread_mutexattr_t;
|
||||
typedef struct _pthread_cond pthread_cond_t;
|
||||
@@ -69,10 +71,6 @@ typedef struct _pthread_once pthread_once_t;
|
||||
typedef struct _pthread_rwlock pthread_rwlock_t;
|
||||
typedef struct _pthread_rwlockattr *pthread_rwlockattr_t;
|
||||
typedef struct _pthread_spinlock pthread_spinlock_t;
|
||||
/*
|
||||
typedef struct _pthread_barrier *pthread_barrier_t;
|
||||
typedef struct _pthread_barrierattr *pthread_barrierattr_t;
|
||||
*/
|
||||
|
||||
struct _pthread_mutex {
|
||||
__haiku_std_uint32 flags;
|
||||
@@ -82,6 +80,14 @@ struct _pthread_mutex {
|
||||
__haiku_std_int32 owner_count;
|
||||
};
|
||||
|
||||
struct _pthread_barrier {
|
||||
__haiku_std_uint32 flags;
|
||||
__haiku_std_int32 lock;
|
||||
__haiku_std_int32 mutex;
|
||||
__haiku_std_int32 waiter_count;
|
||||
__haiku_std_int32 waiter_max;
|
||||
};
|
||||
|
||||
struct _pthread_cond {
|
||||
__haiku_std_uint32 flags;
|
||||
__haiku_std_int32 unused;
|
||||
|
||||
@@ -37,6 +37,10 @@ typedef struct _pthread_mutexattr {
|
||||
bool process_shared;
|
||||
} pthread_mutexattr;
|
||||
|
||||
typedef struct _pthread_barrierattr {
|
||||
bool process_shared;
|
||||
} pthread_barrierattr;
|
||||
|
||||
typedef struct _pthread_attr {
|
||||
int32 detach_state;
|
||||
int32 sched_priority;
|
||||
|
||||
Reference in New Issue
Block a user