Skip to content

Commit

Permalink
posix: rwlock: make pthread_rwlock_t a pooled ipc type
Browse files Browse the repository at this point in the history
Like mutex, barrier, cond, spinlock, etc, make
pthread_rwlock_t a pooled ipc type.

Signed-off-by: Christopher Friedt <[email protected]>
  • Loading branch information
cfriedt committed Jan 18, 2024
1 parent 9948c29 commit b0a83a9
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 64 deletions.
8 changes: 1 addition & 7 deletions include/zephyr/posix/posix_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,7 @@ typedef struct pthread_barrierattr {

typedef uint32_t pthread_rwlockattr_t;

typedef struct pthread_rwlock_obj {
struct k_sem rd_sem;
struct k_sem wr_sem;
struct k_sem reader_active;/* blocks WR till reader has acquired lock */
int32_t status;
k_tid_t wr_owner;
} pthread_rwlock_t;
typedef uint32_t pthread_rwlock_t;

struct pthread_once {
bool flag;
Expand Down
7 changes: 7 additions & 0 deletions include/zephyr/posix/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ int pthread_condattr_setclock(pthread_condattr_t *att, clockid_t clock_id);
*/
#define PTHREAD_MUTEX_INITIALIZER (-1)

/**
* @brief Declare a rwlock as initialized
*
* Initialize a rwlock with the default rwlock attributes.
*/
#define PTHREAD_RWLOCK_INITIALIZER (-1)

/*
* Mutex attributes - type
*
Expand Down
2 changes: 1 addition & 1 deletion lib/posix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ zephyr_library_sources_ifdef(CONFIG_PTHREAD_COND cond.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_KEY key.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_MUTEX mutex.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD pthread.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC rwlock.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_RWLOCK rwlock.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_PRIORITY_SCHEDULING sched.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC semaphore.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_SPINLOCK spinlock.c)
Expand Down
1 change: 1 addition & 0 deletions lib/posix/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ source "lib/posix/Kconfig.limits"
source "lib/posix/Kconfig.mqueue"
source "lib/posix/Kconfig.mutex"
source "lib/posix/Kconfig.pthread"
source "lib/posix/Kconfig.rwlock"
source "lib/posix/Kconfig.sched"
source "lib/posix/Kconfig.semaphore"
source "lib/posix/Kconfig.signal"
Expand Down
8 changes: 8 additions & 0 deletions lib/posix/Kconfig.rwlock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2024 Meta
#
# SPDX-License-Identifier: Apache-2.0

TYPE = PTHREAD_RWLOCK
type = pthread_rwlock_t
type-function = pthread_rwlock_timedrdlock
source "lib/posix/Kconfig.template.pooled_ipc_type"
Loading

0 comments on commit b0a83a9

Please sign in to comment.