Skip to content

Commit 78c8176

Browse files
harshilbhatt2001cfriedt
authored andcommitted
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 <[email protected]>
1 parent 694cd58 commit 78c8176

File tree

3 files changed

+56
-16
lines changed

3 files changed

+56
-16
lines changed

include/zephyr/posix/posix_types.h

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ BUILD_ASSERT(sizeof(pthread_condattr_t) >= sizeof(struct pthread_condattr));
8888
typedef uint32_t pthread_barrier_t;
8989

9090
typedef struct pthread_barrierattr {
91+
int pshared;
9192
} pthread_barrierattr_t;
9293

9394
typedef uint32_t pthread_rwlockattr_t;

include/zephyr/posix/pthread.h

+21-16
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ static inline int pthread_mutexattr_destroy(pthread_mutexattr_t *m)
297297

298298
#define PTHREAD_BARRIER_SERIAL_THREAD 1
299299

300+
/*
301+
* Barrier attributes - type
302+
*/
303+
#define PTHREAD_PROCESS_PRIVATE 0
304+
#define PTHREAD_PROCESS_PUBLIC 1
305+
300306
/**
301307
* @brief POSIX threading compatibility API
302308
*
@@ -323,29 +329,30 @@ int pthread_barrier_destroy(pthread_barrier_t *b);
323329
* @brief POSIX threading compatibility API
324330
*
325331
* See IEEE 1003.1
326-
*
327-
* Note that pthread attribute structs are currently noops in Zephyr.
328332
*/
329-
static inline int pthread_barrierattr_init(pthread_barrierattr_t *b)
330-
{
331-
ARG_UNUSED(b);
332-
333-
return 0;
334-
}
333+
int pthread_barrierattr_init(pthread_barrierattr_t *b);
335334

336335
/**
337336
* @brief POSIX threading compatibility API
338337
*
339338
* See IEEE 1003.1
339+
*/
340+
int pthread_barrierattr_destroy(pthread_barrierattr_t *b);
341+
342+
/**
343+
* @brief POSIX threading compatibility API
340344
*
341-
* Note that pthread attribute structs are currently noops in Zephyr.
345+
* See IEEE 1003.1
342346
*/
343-
static inline int pthread_barrierattr_destroy(pthread_barrierattr_t *b)
344-
{
345-
ARG_UNUSED(b);
347+
int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared);
346348

347-
return 0;
348-
}
349+
/**
350+
* @brief POSIX threading compatibility API
351+
*
352+
* See IEEE 1003.1
353+
*/
354+
int pthread_barrierattr_getpshared(const pthread_barrierattr_t *ZRESTRICT attr,
355+
int *ZRESTRICT pshared);
349356

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

377382
/* Base Pthread related APIs */

lib/posix/barrier.c

+34
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,40 @@ int pthread_barrier_destroy(pthread_barrier_t *b)
161161
return 0;
162162
}
163163

164+
int pthread_barrierattr_init(pthread_barrierattr_t *attr)
165+
{
166+
__ASSERT_NO_MSG(attr != NULL);
167+
168+
attr->pshared = PTHREAD_PROCESS_PRIVATE;
169+
170+
return 0;
171+
}
172+
173+
int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared)
174+
{
175+
if (pshared != PTHREAD_PROCESS_PRIVATE && pshared != PTHREAD_PROCESS_PUBLIC) {
176+
return -EINVAL;
177+
}
178+
179+
attr->pshared = pshared;
180+
return 0;
181+
}
182+
183+
int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict attr,
184+
int *restrict pshared)
185+
{
186+
*pshared = attr->pshared;
187+
188+
return 0;
189+
}
190+
191+
int pthread_barrierattr_destroy(pthread_barrierattr_t *attr)
192+
{
193+
ARG_UNUSED(attr);
194+
195+
return 0;
196+
}
197+
164198
static int pthread_barrier_pool_init(void)
165199
{
166200
int err;

0 commit comments

Comments
 (0)