diff --git a/lib/posix/options/cond.c b/lib/posix/options/cond.c index 4799224b014..7f64385ba33 100644 --- a/lib/posix/options/cond.c +++ b/lib/posix/options/cond.c @@ -225,11 +225,18 @@ static int pthread_cond_pool_init(void) int pthread_condattr_init(pthread_condattr_t *att) { - __ASSERT_NO_MSG(att != NULL); - struct posix_condattr *const attr = (struct posix_condattr *)att; + if (att == NULL) { + return EINVAL; + } + if (attr->initialized) { + LOG_DBG("%s %s initialized", "attribute", "already"); + return EINVAL; + } + attr->clock = CLOCK_MONOTONIC; + attr->initialized = true; return 0; } @@ -238,7 +245,8 @@ int pthread_condattr_destroy(pthread_condattr_t *att) { struct posix_condattr *const attr = (struct posix_condattr *)att; - if (attr == NULL) { + if ((attr == NULL) || !attr->initialized) { + LOG_DBG("%s %s initialized", "attribute", "not"); return EINVAL; } @@ -252,6 +260,11 @@ int pthread_condattr_getclock(const pthread_condattr_t *ZRESTRICT att, { struct posix_condattr *const attr = (struct posix_condattr *)att; + if ((attr == NULL) || !attr->initialized) { + LOG_DBG("%s %s initialized", "attribute", "not"); + return EINVAL; + } + *clock_id = attr->clock; return 0; @@ -265,6 +278,11 @@ int pthread_condattr_setclock(pthread_condattr_t *att, clockid_t clock_id) return -EINVAL; } + if ((attr == NULL) || !attr->initialized) { + LOG_DBG("%s %s initialized", "attribute", "not"); + return EINVAL; + } + attr->clock = clock_id; return 0;