zephyr/lib/posix/posix_internal.h
Christopher Friedt 89cf4cea56 posix: pthread: mitigate include order sensitivity
Previously, the `posix_internal.h` header needed to be exposed
to the application because we had non-trivial details for
most posix types (pthread, mutex, cond, ...). Since most of
those have been simplified to a typedef'ed integer, we
no longer need to expose that header to the applicaiton.

Additionally, it means that we can adopt normalized
header order in posix.

Additionally, keep more implementation details hidden
and prefer the static keyword on internal symbols where
possible.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-06-09 12:27:04 -04:00

85 lines
1.8 KiB
C

/*
* Copyright (c) 2022 Meta
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_LIB_POSIX_POSIX_INTERNAL_H_
#define ZEPHYR_LIB_POSIX_POSIX_INTERNAL_H_
#include <stdbool.h>
#include <stdint.h>
#include <zephyr/kernel.h>
#include <zephyr/posix/pthread.h>
#include <zephyr/sys/dlist.h>
#include <zephyr/sys/slist.h>
/*
* Bit used to mark a pthread object as initialized. Initialization status is
* verified (against internal status) in lock / unlock / destroy functions.
*/
#define PTHREAD_OBJ_MASK_INIT 0x80000000
struct posix_thread {
struct k_thread thread;
/* List node for ready_q, run_q, or done_q */
sys_dnode_t q_node;
/* List of keys that thread has called pthread_setspecific() on */
sys_slist_t key_list;
/* Exit status */
void *retval;
/* Pthread cancellation */
uint8_t cancel_state;
bool cancel_pending;
/* Detach state */
uint8_t detachstate;
/* Queue ID (internal-only) */
uint8_t qid;
};
typedef struct pthread_key_obj {
/* List of pthread_key_data objects that contain thread
* specific data for the key
*/
sys_slist_t key_data_l;
/* Optional destructor that is passed to pthread_key_create() */
void (*destructor)(void *value);
} pthread_key_obj;
typedef struct pthread_thread_data {
sys_snode_t node;
/* Key and thread specific data passed to pthread_setspecific() */
pthread_key_obj *key;
void *spec_data;
} pthread_thread_data;
static inline bool is_pthread_obj_initialized(uint32_t obj)
{
return (obj & PTHREAD_OBJ_MASK_INIT) != 0;
}
static inline uint32_t mark_pthread_obj_initialized(uint32_t obj)
{
return obj | PTHREAD_OBJ_MASK_INIT;
}
static inline uint32_t mark_pthread_obj_uninitialized(uint32_t obj)
{
return obj & ~PTHREAD_OBJ_MASK_INIT;
}
struct posix_thread *to_posix_thread(pthread_t pth);
/* get and possibly initialize a posix_mutex */
struct k_mutex *to_posix_mutex(pthread_mutex_t *mu);
#endif