Skip to content

Commit 87635dd

Browse files
committed
posix: do not define _PTHREAD_CANCEL_POS
_PTHREAD_CANCEL_POS is an implementation detail and should not be defined in the global scope. Furthermore, _PTHREAD_CANCEL_POS uses a reserved identifier (underscore followed by capital letter). Adjust definitions so that the implementation detail is only used in the implementation and not in the interface. Additionally, modify naming so that the non-standard macro does not use a reserved identifier. Signed-off-by: Christopher Friedt <[email protected]>
1 parent d2e7292 commit 87635dd

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

include/zephyr/posix/pthread.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ extern "C" {
3030
#define PTHREAD_PROCESS_SHARED 1
3131

3232
/* Pthread cancellation */
33-
#define PTHREAD_CANCELED ((void *)-1)
34-
#define _PTHREAD_CANCEL_POS 0
35-
#define PTHREAD_CANCEL_ENABLE (0U << _PTHREAD_CANCEL_POS)
36-
#define PTHREAD_CANCEL_DISABLE BIT(_PTHREAD_CANCEL_POS)
33+
#define PTHREAD_CANCELED ((void *)-1)
34+
#define PTHREAD_CANCEL_ENABLE 0
35+
#define PTHREAD_CANCEL_DISABLE 1
3736

3837
/* Passed to pthread_once */
3938
#define PTHREAD_ONCE_INIT \

lib/posix/pthread.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <zephyr/sys/atomic.h>
1717
#include <zephyr/posix/pthread.h>
1818
#include <zephyr/sys/slist.h>
19+
#include <zephyr/sys/util.h>
1920

2021
LOG_MODULE_REGISTER(pthread, CONFIG_PTHREAD_LOG_LEVEL);
2122

@@ -25,6 +26,8 @@ LOG_MODULE_REGISTER(pthread, CONFIG_PTHREAD_LOG_LEVEL);
2526
#define DYNAMIC_STACK_SIZE 0
2627
#endif
2728

29+
#define _pthread_cancel_pos LOG2(PTHREAD_CANCEL_DISABLE)
30+
2831
#define PTHREAD_INIT_FLAGS PTHREAD_CANCEL_ENABLE
2932

3033
enum posix_thread_qid {
@@ -406,7 +409,7 @@ int pthread_create(pthread_t *th, const pthread_attr_t *_attr, void *(*threadrou
406409
sys_dlist_append(&run_q, &t->q_node);
407410
t->qid = POSIX_THREAD_RUN_Q;
408411
t->detachstate = attr->detachstate;
409-
if ((BIT(_PTHREAD_CANCEL_POS) & attr->flags) != 0) {
412+
if ((BIT(_pthread_cancel_pos) & attr->flags) != 0) {
410413
t->cancel_state = PTHREAD_CANCEL_ENABLE;
411414
}
412415
t->cancel_pending = false;

0 commit comments

Comments
 (0)