From 1b8c8375d70e405a7a2321350af6c840cf5adff6 Mon Sep 17 00:00:00 2001 From: Harshil Bhatt Date: Tue, 4 Jul 2023 02:01:32 +0530 Subject: [PATCH] posix: Implement pthread_barrieratter functions Added pthread_barrieratter_init() #59936, pthread_barrieratter_destroy() #59935, pthread_barrieratter_getpshared() #59937 and pthread_barrieratter_setpshared() #59939. Signed-off-by: Harshil Bhatt --- include/zephyr/posix/posix_types.h | 1 + include/zephyr/posix/pthread.h | 37 +++++++++++++++++------------- lib/posix/barrier.c | 34 +++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 16 deletions(-) diff --git a/include/zephyr/posix/posix_types.h b/include/zephyr/posix/posix_types.h index a2191f0fece227..fbfc976d6fb976 100644 --- a/include/zephyr/posix/posix_types.h +++ b/include/zephyr/posix/posix_types.h @@ -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; diff --git a/include/zephyr/posix/pthread.h b/include/zephyr/posix/pthread.h index 5b807880775118..b11c61a9f6ed84 100644 --- a/include/zephyr/posix/pthread.h +++ b/include/zephyr/posix/pthread.h @@ -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 * @@ -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 @@ -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 */ diff --git a/lib/posix/barrier.c b/lib/posix/barrier.c index f6122b13f9e74f..7e2598b1bde840 100644 --- a/lib/posix/barrier.c +++ b/lib/posix/barrier.c @@ -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;