pthread_internal.h 1.6 KB
Newer Older
Y
yiyue.fang 已提交
1
/*
2
 * Copyright (c) 2006-2018, RT-Thread Development Team
Y
yiyue.fang 已提交
3
 *
4
 * SPDX-License-Identifier: Apache-2.0
Y
yiyue.fang 已提交
5 6 7 8 9 10
 *
 * Change Logs:
 * Date           Author       Notes
 * 2010-10-26     Bernard      the first version
 */

M
Ming, Bai 已提交
11 12 13 14 15 16 17 18
#ifndef __PTHREAD_INTERNAL_H__
#define __PTHREAD_INTERNAL_H__

#include <rtthread.h>
#include <pthread.h>

struct _pthread_cleanup
{
Y
yiyue.fang 已提交
19 20
    void (*cleanup_func)(void *parameter);
    void *parameter;
M
Ming, Bai 已提交
21

Y
yiyue.fang 已提交
22
    struct _pthread_cleanup *next;
M
Ming, Bai 已提交
23 24 25 26 27
};
typedef struct _pthread_cleanup _pthread_cleanup_t;

struct _pthread_key_data
{
Y
yiyue.fang 已提交
28 29
    int is_used;
    void (*destructor)(void *parameter);
M
Ming, Bai 已提交
30 31 32
};
typedef struct _pthread_key_data _pthread_key_data_t;

Y
yiyue.fang 已提交
33
#define PTHREAD_MAGIC   0x70746873
M
Ming, Bai 已提交
34 35
struct _pthread_data
{
Y
yiyue.fang 已提交
36 37 38
    rt_uint32_t magic;
    pthread_attr_t attr;
    rt_thread_t tid;
M
Ming, Bai 已提交
39

Y
yiyue.fang 已提交
40 41
    void* (*thread_entry)(void *parameter);
    void *thread_parameter;
M
Ming, Bai 已提交
42

Y
yiyue.fang 已提交
43 44
    /* return value */
    void *return_value;
M
Ming, Bai 已提交
45

Y
yiyue.fang 已提交
46 47
    /* semaphore for joinable thread */
    rt_sem_t joinable_sem;
M
Ming, Bai 已提交
48

Y
yiyue.fang 已提交
49 50 51 52
    /* cancel state and type */
    rt_uint8_t cancelstate;
    volatile rt_uint8_t canceltype;
    volatile rt_uint8_t canceled;
M
Ming, Bai 已提交
53

Y
yiyue.fang 已提交
54 55
    _pthread_cleanup_t *cleanup;
    void** tls; /* thread-local storage area */
M
Ming, Bai 已提交
56 57 58
};
typedef struct _pthread_data _pthread_data_t;

Y
yiyue.fang 已提交
59
rt_inline _pthread_data_t *_pthread_get_data(pthread_t thread)
M
Ming, Bai 已提交
60
{
Y
yiyue.fang 已提交
61 62
    _pthread_data_t *ptd;
    RT_ASSERT(thread != RT_NULL);
M
Ming, Bai 已提交
63

Y
yiyue.fang 已提交
64 65 66
    ptd = (_pthread_data_t *)thread->user_data;
    RT_ASSERT(ptd != RT_NULL);
    RT_ASSERT(ptd->magic == PTHREAD_MAGIC);
M
Ming, Bai 已提交
67

Y
yiyue.fang 已提交
68
    return ptd;
M
Ming, Bai 已提交
69 70 71
}

int clock_time_to_tick(const struct timespec *time);
B
BernardXiong 已提交
72

M
Ming, Bai 已提交
73 74 75 76 77
void posix_mq_system_init(void);
void posix_sem_system_init(void);
void pthread_key_system_init(void);

#endif