Skip to content

Commit

Permalink
posix: Implement pthread_barrieratter functions
Browse files Browse the repository at this point in the history
Added pthread_barrieratter_init() zephyrproject-rtos#59936,
pthread_barrieratter_destroy() zephyrproject-rtos#59935,
pthread_barrieratter_getpshared() zephyrproject-rtos#59937 and
pthread_barrieratter_setpshared() zephyrproject-rtos#59939.

Signed-off-by: Harshil Bhatt <harshilbhatt2001@gmail.com>
  • Loading branch information
harshilbhatt2001 committed Jul 8, 2023
1 parent fed377f commit 1b8c837
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 16 deletions.
1 change: 1 addition & 0 deletions include/zephyr/posix/posix_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ BUILD_ASSERT(sizeof(pthread_condattr_t) >= sizeof(struct pthread_condattr));
typedef uint32_t pthread_barrier_t;

typedef struct pthread_barrierattr {
int pshared;
} pthread_barrierattr_t;

typedef uint32_t pthread_rwlockattr_t;
Expand Down
37 changes: 21 additions & 16 deletions include/zephyr/posix/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ static inline int pthread_mutexattr_destroy(pthread_mutexattr_t *m)

#define PTHREAD_BARRIER_SERIAL_THREAD 1

/*
* Barrier attributes - type
*/
#define PTHREAD_PROCESS_PRIVATE 0
#define PTHREAD_PROCESS_PUBLIC 1

/**
* @brief POSIX threading compatibility API
*
Expand All @@ -323,29 +329,30 @@ int pthread_barrier_destroy(pthread_barrier_t *b);
* @brief POSIX threading compatibility API
*
* See IEEE 1003.1
*
* Note that pthread attribute structs are currently noops in Zephyr.
*/
static inline int pthread_barrierattr_init(pthread_barrierattr_t *b)
{
ARG_UNUSED(b);

return 0;
}
int pthread_barrierattr_init(pthread_barrierattr_t *b);

/**
* @brief POSIX threading compatibility API
*
* See IEEE 1003.1
*/
int pthread_barrierattr_destroy(pthread_barrierattr_t *b);

/**
* @brief POSIX threading compatibility API
*
* Note that pthread attribute structs are currently noops in Zephyr.
* See IEEE 1003.1
*/
static inline int pthread_barrierattr_destroy(pthread_barrierattr_t *b)
{
ARG_UNUSED(b);
int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared);

return 0;
}
/**
* @brief POSIX threading compatibility API
*
* See IEEE 1003.1
*/
int pthread_barrierattr_getpshared(const pthread_barrierattr_t *ZRESTRICT attr,
int *ZRESTRICT pshared);

/* Predicates and setters for various pthread attribute values that we
* don't support (or always support: the "process shared" attribute
Expand All @@ -370,8 +377,6 @@ int pthread_mutexattr_getrobust(const pthread_mutexattr_t * int *);
int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int);
int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int);
int pthread_barrierattr_getpshared(const pthread_barrierattr_t *, int *);
int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int);
*/

/* Base Pthread related APIs */
Expand Down
34 changes: 34 additions & 0 deletions lib/posix/barrier.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,40 @@ int pthread_barrier_destroy(pthread_barrier_t *b)
return 0;
}

int pthread_barrierattr_init(pthread_barrierattr_t *attr)
{
__ASSERT_NO_MSG(attr != NULL);

attr->pshared = PTHREAD_PROCESS_PRIVATE;

return 0;
}

int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared)
{
if (pshared != PTHREAD_PROCESS_PRIVATE && pshared != PTHREAD_PROCESS_PUBLIC) {
return -EINVAL;
}

attr->pshared = pshared;
return 0;
}

int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict attr,
int *restrict pshared)
{
*pshared = attr->pshared;

return 0;
}

int pthread_barrierattr_destroy(pthread_barrierattr_t *attr)
{
ARG_UNUSED(attr);

return 0;
}

static int pthread_barrier_pool_init(void)
{
int err;
Expand Down

0 comments on commit 1b8c837

Please sign in to comment.