Skip to content

Commit

Permalink
POSIX: Implement pthread_condattr functions
Browse files Browse the repository at this point in the history
Added:
pthread_condattr_init
pthread_condattr_destroy
pthread_condattr_getclock
pthread_condattr_setclock

Signed-off-by: Mateusz Marszalek <matti.marszalek@gmail.com>
  • Loading branch information
Durchbruchswagen authored and mbolivar-ampere committed Aug 30, 2023
1 parent 28ba836 commit 61219da
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 14 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 @@ -75,6 +75,7 @@ BUILD_ASSERT(sizeof(pthread_mutexattr_t) >= sizeof(struct pthread_mutexattr));
typedef uint32_t pthread_cond_t;

struct pthread_condattr {
clockid_t clock;
};

#if defined(CONFIG_MINIMAL_LIBC) || defined(CONFIG_PICOLIBC) || defined(CONFIG_ARMCLANG_STD_LIBC) \
Expand Down
34 changes: 20 additions & 14 deletions include/zephyr/posix/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,34 @@ int pthread_cond_timedwait(pthread_cond_t *cv, pthread_mutex_t *mut,
*
* See IEEE 1003.1.
*
* Note that pthread attribute structs are currently noops in Zephyr.
*/
static inline int pthread_condattr_init(pthread_condattr_t *att)
{
ARG_UNUSED(att);
return 0;
}
int pthread_condattr_init(pthread_condattr_t *att);

/**
* @brief POSIX threading compatibility API
*
* See IEEE 1003.1
*
* Note that pthread attribute structs are currently noops in Zephyr.
*/
static inline int pthread_condattr_destroy(pthread_condattr_t *att)
{
ARG_UNUSED(att);
return 0;
}
int pthread_condattr_destroy(pthread_condattr_t *att);

/**
* @brief POSIX threading comatibility API
*
* See IEEE 1003.1
*
*/
int pthread_condattr_getclock(const pthread_condattr_t *ZRESTRICT att,
clockid_t *ZRESTRICT clock_id);

/**
* @brief POSIX threading compatibility API
*
* See IEEE 1003.1
*
*/

int pthread_condattr_setclock(pthread_condattr_t *att, clockid_t clock_id);

/**
* @brief Declare a mutex as initialized
Expand Down Expand Up @@ -364,9 +372,7 @@ int pthread_barrierattr_getpshared(const pthread_barrierattr_t *ZRESTRICT attr,
* Unix code. Leave the declarations here so they can be easily
* uncommented and implemented as needed.
int pthread_condattr_getclock(const pthread_condattr_t * clockid_t *);
int pthread_condattr_getpshared(const pthread_condattr_t * int *);
int pthread_condattr_setclock(pthread_condattr_t *, clockid_t);
int pthread_condattr_setpshared(pthread_condattr_t *, int);
int pthread_mutex_consistent(pthread_mutex_t *);
int pthread_mutex_getprioceiling(const pthread_mutex_t * int *);
Expand Down
35 changes: 35 additions & 0 deletions lib/posix/cond.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,39 @@ static int pthread_cond_pool_init(void)

return 0;
}

int pthread_condattr_init(pthread_condattr_t *att)
{
__ASSERT_NO_MSG(att != NULL);

att->clock = CLOCK_MONOTONIC;

return 0;
}

int pthread_condattr_destroy(pthread_condattr_t *att)
{
ARG_UNUSED(att);

return 0;
}

int pthread_condattr_getclock(const pthread_condattr_t *ZRESTRICT att,
clockid_t *ZRESTRICT clock_id)
{
*clock_id = att->clock;

return 0;
}

int pthread_condattr_setclock(pthread_condattr_t *att, clockid_t clock_id)
{
if (clock_id != CLOCK_REALTIME && clock_id != CLOCK_MONOTONIC) {
return -EINVAL;
}

att->clock = clock_id;

return 0;
}
SYS_INIT(pthread_cond_pool_init, PRE_KERNEL_1, 0);

0 comments on commit 61219da

Please sign in to comment.