89 lines
1.9 KiB
C
89 lines
1.9 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;
|
|
|
|
/* Dynamic stack */
|
|
k_thread_stack_t *dynamic_stack;
|
|
|
|
/* 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
|