diff --git a/doc/services/portability/posix/conformance/index.rst b/doc/services/portability/posix/conformance/index.rst index b4baa41262d..ef0522107d0 100644 --- a/doc/services/portability/posix/conformance/index.rst +++ b/doc/services/portability/posix/conformance/index.rst @@ -66,7 +66,7 @@ POSIX System Interfaces :ref:`_POSIX_CLOCK_SELECTION`, 200809L, :kconfig:option:`CONFIG_POSIX_CLOCK_SELECTION` _POSIX_MAPPED_FILES, -1, :ref:`†` _POSIX_MEMORY_PROTECTION, -1, :ref:`†` - :ref:`_POSIX_READER_WRITER_LOCKS`, 200809L, :kconfig:option:`CONFIG_PTHREAD_IPC` + :ref:`_POSIX_READER_WRITER_LOCKS`, 200809L, :kconfig:option:`CONFIG_POSIX_READER_WRITER_LOCKS` :ref:`_POSIX_REALTIME_SIGNALS`, -1, :ref:`_POSIX_SEMAPHORES`, 200809L, :kconfig:option:`CONFIG_PTHREAD_IPC` :ref:`_POSIX_SPIN_LOCKS`, 200809L, :kconfig:option:`CONFIG_POSIX_SPIN_LOCKS` diff --git a/include/zephyr/posix/posix_features.h b/include/zephyr/posix/posix_features.h index 9b53a4ba646..710c7c8f148 100644 --- a/include/zephyr/posix/posix_features.h +++ b/include/zephyr/posix/posix_features.h @@ -71,7 +71,7 @@ #define _POSIX_RAW_SOCKETS _POSIX_VERSION #endif -#ifdef CONFIG_PTHREAD_IPC +#ifdef CONFIG_POSIX_READER_WRITER_LOCKS #define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION #endif diff --git a/include/zephyr/posix/pthread.h b/include/zephyr/posix/pthread.h index 7cd0f7e1160..0a721f58be2 100644 --- a/include/zephyr/posix/pthread.h +++ b/include/zephyr/posix/pthread.h @@ -153,7 +153,7 @@ int pthread_condattr_setclock(pthread_condattr_t *att, clockid_t clock_id); * * Initialize a rwlock with the default rwlock attributes. */ -#define PTHREAD_RWLOCK_INITIALIZER (-1) +#define POSIX_RWLOCK_INITIALIZER (-1) /* * Mutex attributes - type diff --git a/include/zephyr/posix/sys/sysconf.h b/include/zephyr/posix/sys/sysconf.h index dfcebd28cc2..d90f13580e5 100644 --- a/include/zephyr/posix/sys/sysconf.h +++ b/include/zephyr/posix/sys/sysconf.h @@ -168,7 +168,7 @@ enum { COND_CODE_1(CONFIG_NET_SOCKETS_PACKET, (_POSIX_RAW_SOCKETS), (-1L)) #define __z_posix_sysconf_SC_RE_DUP_MAX _POSIX_RE_DUP_MAX #define __z_posix_sysconf_SC_READER_WRITER_LOCKS \ - COND_CODE_1(CONFIG_PTHREAD_IPC, (_POSIX_READER_WRITER_LOCKS), (-1L)) + COND_CODE_1(CONFIG_POSIX_READER_WRITER_LOCKS, (_POSIX_READER_WRITER_LOCKS), (-1L)) #define __z_posix_sysconf_SC_REALTIME_SIGNALS (-1L) #define __z_posix_sysconf_SC_REGEXP (-1L) #define __z_posix_sysconf_SC_SAVED_IDS (-1L) diff --git a/lib/posix/options/CMakeLists.txt b/lib/posix/options/CMakeLists.txt index a6ce721b4ce..e4431df859b 100644 --- a/lib/posix/options/CMakeLists.txt +++ b/lib/posix/options/CMakeLists.txt @@ -73,8 +73,8 @@ 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_RWLOCK rwlock.c) zephyr_library_sources_ifdef(CONFIG_POSIX_PRIORITY_SCHEDULING sched.c) +zephyr_library_sources_ifdef(CONFIG_POSIX_READER_WRITER_LOCKS rwlock.c) zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC semaphore.c) zephyr_library_include_directories( diff --git a/lib/posix/options/Kconfig.deprecated b/lib/posix/options/Kconfig.deprecated index b2ed5e60028..5b16209fad0 100644 --- a/lib/posix/options/Kconfig.deprecated +++ b/lib/posix/options/Kconfig.deprecated @@ -120,6 +120,15 @@ config PTHREAD_BARRIER Please use CONFIG_POSIX_BARRIERS instead. +config PTHREAD_RWLOCK + bool "pthread_spinlock_t support [DEPRECATED]" + select DEPRECATED + select POSIX_READER_WRITER_LOCKS + help + This option is deprecated. + + Please use CONFIG_POSIX_READER_WRITER_LOCKS instead. + config PTHREAD_SPINLOCK bool "pthread_spinlock_t support [DEPRECATED]" select DEPRECATED diff --git a/lib/posix/options/Kconfig.rwlock b/lib/posix/options/Kconfig.rwlock index fea61551ec3..ed19520725a 100644 --- a/lib/posix/options/Kconfig.rwlock +++ b/lib/posix/options/Kconfig.rwlock @@ -2,7 +2,27 @@ # # SPDX-License-Identifier: Apache-2.0 -TYPE = PTHREAD_RWLOCK -type = pthread_rwlock_t -type-function = pthread_rwlock_timedrdlock -rsource "Kconfig.template.pooled_ipc_type" +menuconfig POSIX_READER_WRITER_LOCKS + bool "POSIX reader-writer locks" + default y if POSIX_API + help + Select 'y' here to enable POSIX reader-writer locks. + + For more information please see + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html + +if POSIX_READER_WRITER_LOCKS + +config MAX_PTHREAD_RWLOCK_COUNT + int "Maximum number of POSIX reader-writer locks" + default 5 + help + Maximum simultaneously active reader-writer locks in a POSIX application. + + Note: this is a non-standard option. + +module = PTHREAD_RWLOCK +module-str = POSIX Reader-Writer Locks +source "subsys/logging/Kconfig.template.log_config" + +endif # POSIX_READER_WRITER_LOCKS diff --git a/lib/posix/options/rwlock.c b/lib/posix/options/rwlock.c index b8a91a03232..c4143a79acb 100644 --- a/lib/posix/options/rwlock.c +++ b/lib/posix/options/rwlock.c @@ -86,7 +86,7 @@ struct posix_rwlock *to_posix_rwlock(pthread_rwlock_t *rwlock) size_t bit; struct posix_rwlock *rwl; - if (*rwlock != PTHREAD_RWLOCK_INITIALIZER) { + if (*rwlock != POSIX_RWLOCK_INITIALIZER) { return get_posix_rwlock(*rwlock); } @@ -116,7 +116,7 @@ int pthread_rwlock_init(pthread_rwlock_t *rwlock, struct posix_rwlock *rwl; ARG_UNUSED(attr); - *rwlock = PTHREAD_RWLOCK_INITIALIZER; + *rwlock = POSIX_RWLOCK_INITIALIZER; rwl = to_posix_rwlock(rwlock); if (rwl == NULL) { diff --git a/tests/posix/headers/src/pthread_h.c b/tests/posix/headers/src/pthread_h.c index 4363d3b4764..8f1286222d5 100644 --- a/tests/posix/headers/src/pthread_h.c +++ b/tests/posix/headers/src/pthread_h.c @@ -59,7 +59,7 @@ ZTEST(posix_headers, test_pthread_h) pthread_cond_t cond = PTHREAD_COND_INITIALIZER; pthread_mutex_t mu = PTHREAD_MUTEX_INITIALIZER; - /* pthread_rwlock_t lock = PTHREAD_RWLOCK_INITIALIZER; */ /* not implemented */ + /* pthread_rwlock_t lock = POSIX_READER_WRITER_LOCKS_INITIALIZER; */ /* not implemented */ zassert_not_null(pthread_atfork); zassert_not_null(pthread_attr_destroy);