Skip to content

Commit f972d8e

Browse files
author
Christopher Friedt
committed
posix: pthread: rewrite of create, join, detach, cancel, and exit
Previously, the pthread implementation used a `pthread_mutex_t` to synchronize thread state. This was required because a `pthread_cond_t` was used to notify other pthreads that were attempting to join or exit the same pthread. With the previous removal of the `pthread_cond_t` from `struct posix_thread`, and the addition of the `z_thread_wake_joiners()` utility, there is no longer a need to utilize a `pthread_mutex_t` to synchronize state. Instead, use a `struct k_spinlock` for synchronization and `z_thread_wake_joiners()` for notification. Additionally, use a `bitarray` instead of the the `pthread_pool_lock`, which makes `pthread.c` resource allocation more like that of the other pthread objects. Signed-off-by: Christopher Friedt <[email protected]>
1 parent 02df615 commit f972d8e

File tree

2 files changed

+214
-144
lines changed

2 files changed

+214
-144
lines changed

lib/posix/posix_internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define ZEPHYR_LIB_POSIX_POSIX_INTERNAL_H_
99

1010
#include <zephyr/kernel.h>
11+
#include <zephyr/sys/atomic.h>
1112

1213
/*
1314
* Bit used to mark a pthread object as initialized. Initialization status is
@@ -39,6 +40,7 @@ enum pthread_state {
3940

4041
struct posix_thread {
4142
struct k_thread thread;
43+
struct k_spinlock lock;
4244

4345
/* List of keys that thread has called pthread_setspecific() on */
4446
sys_slist_t key_list;
@@ -49,11 +51,9 @@ struct posix_thread {
4951
/* Pthread cancellation */
5052
int cancel_state;
5153
int cancel_pending;
52-
struct k_spinlock cancel_lock;
5354

5455
/* Pthread State */
5556
enum pthread_state state;
56-
pthread_mutex_t state_lock;
5757
};
5858

5959
typedef struct pthread_key_obj {

0 commit comments

Comments
 (0)