Skip to content

Commit b0a83a9

Browse files
Christopher Friedtcfriedt
authored andcommitted
posix: rwlock: make pthread_rwlock_t a pooled ipc type
Like mutex, barrier, cond, spinlock, etc, make pthread_rwlock_t a pooled ipc type. Signed-off-by: Christopher Friedt <[email protected]>
1 parent 9948c29 commit b0a83a9

File tree

6 files changed

+199
-64
lines changed

6 files changed

+199
-64
lines changed

include/zephyr/posix/posix_types.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,7 @@ typedef struct pthread_barrierattr {
9090

9191
typedef uint32_t pthread_rwlockattr_t;
9292

93-
typedef struct pthread_rwlock_obj {
94-
struct k_sem rd_sem;
95-
struct k_sem wr_sem;
96-
struct k_sem reader_active;/* blocks WR till reader has acquired lock */
97-
int32_t status;
98-
k_tid_t wr_owner;
99-
} pthread_rwlock_t;
93+
typedef uint32_t pthread_rwlock_t;
10094

10195
struct pthread_once {
10296
bool flag;

include/zephyr/posix/pthread.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ int pthread_condattr_setclock(pthread_condattr_t *att, clockid_t clock_id);
136136
*/
137137
#define PTHREAD_MUTEX_INITIALIZER (-1)
138138

139+
/**
140+
* @brief Declare a rwlock as initialized
141+
*
142+
* Initialize a rwlock with the default rwlock attributes.
143+
*/
144+
#define PTHREAD_RWLOCK_INITIALIZER (-1)
145+
139146
/*
140147
* Mutex attributes - type
141148
*

lib/posix/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ zephyr_library_sources_ifdef(CONFIG_PTHREAD_COND cond.c)
5454
zephyr_library_sources_ifdef(CONFIG_PTHREAD_KEY key.c)
5555
zephyr_library_sources_ifdef(CONFIG_PTHREAD_MUTEX mutex.c)
5656
zephyr_library_sources_ifdef(CONFIG_PTHREAD pthread.c)
57-
zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC rwlock.c)
57+
zephyr_library_sources_ifdef(CONFIG_PTHREAD_RWLOCK rwlock.c)
5858
zephyr_library_sources_ifdef(CONFIG_POSIX_PRIORITY_SCHEDULING sched.c)
5959
zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC semaphore.c)
6060
zephyr_library_sources_ifdef(CONFIG_PTHREAD_SPINLOCK spinlock.c)

lib/posix/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ source "lib/posix/Kconfig.limits"
4949
source "lib/posix/Kconfig.mqueue"
5050
source "lib/posix/Kconfig.mutex"
5151
source "lib/posix/Kconfig.pthread"
52+
source "lib/posix/Kconfig.rwlock"
5253
source "lib/posix/Kconfig.sched"
5354
source "lib/posix/Kconfig.semaphore"
5455
source "lib/posix/Kconfig.signal"

lib/posix/Kconfig.rwlock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2024 Meta
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
TYPE = PTHREAD_RWLOCK
6+
type = pthread_rwlock_t
7+
type-function = pthread_rwlock_timedrdlock
8+
source "lib/posix/Kconfig.template.pooled_ipc_type"

0 commit comments

Comments
 (0)