posix: rwlock: pthread_rwlockattr_init / destroy in lib

Move the implementation of the following functions into
the posix library rather than having themn as static
inline functions.

* pthread_rwlockattr_init()
* pthread_rwlockattr_destroy()

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
This commit is contained in:
Christopher Friedt 2024-03-19 06:03:16 -04:00 committed by Chris Friedt
parent 457e44073b
commit 61c4139925
2 changed files with 34 additions and 10 deletions

View file

@ -390,22 +390,14 @@ int pthread_equal(pthread_t pt1, pthread_t pt2);
*
* See IEEE 1003.1
*/
static inline int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr)
{
ARG_UNUSED(attr);
return 0;
}
int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr);
/**
* @brief initialize the read-write lock attributes object.
*
* See IEEE 1003.1
*/
static inline int pthread_rwlockattr_init(pthread_rwlockattr_t *attr)
{
ARG_UNUSED(attr);
return 0;
}
int pthread_rwlockattr_init(pthread_rwlockattr_t *attr);
int pthread_attr_getguardsize(const pthread_attr_t *ZRESTRICT attr, size_t *ZRESTRICT guardsize);
int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize);

View file

@ -21,6 +21,10 @@ struct posix_rwlock {
k_tid_t wr_owner;
};
struct posix_rwlockattr {
bool initialized: 1;
};
int64_t timespec_to_timeoutms(const struct timespec *abstime);
static uint32_t read_lock_acquire(struct posix_rwlock *rwl, int32_t timeout);
static uint32_t write_lock_acquire(struct posix_rwlock *rwl, int32_t timeout);
@ -384,3 +388,31 @@ static uint32_t write_lock_acquire(struct posix_rwlock *rwl, int32_t timeout)
}
return ret;
}
int pthread_rwlockattr_init(pthread_rwlockattr_t *attr)
{
struct posix_rwlockattr *const a = (struct posix_rwlockattr *)attr;
if (a == NULL) {
return EINVAL;
}
*a = (struct posix_rwlockattr){
.initialized = true,
};
return 0;
}
int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr)
{
struct posix_rwlockattr *const a = (struct posix_rwlockattr *)attr;
if (a == NULL || !a->initialized) {
return EINVAL;
}
*a = (struct posix_rwlockattr){0};
return 0;
}