pthread_private.h revision 10b4fed2
1/*
2 * Copyright 2003-2009, Axel D��rfler, axeld@pinc-software.de.
3 * Copyright 2007, Ryan Leavengood, leavengood@gmail.com.
4 * All rights reserved. Distributed under the terms of the MIT License.
5 */
6#ifndef _PTHREAD_PRIVATE_H_
7#define _PTHREAD_PRIVATE_H_
8
9
10#include <pthread.h>
11
12#include <OS.h>
13
14
15// _pthread_thread::flags values
16#define THREAD_DETACHED				0x01
17#define THREAD_DEAD					0x02
18#define THREAD_CANCELED				0x04
19#define THREAD_CANCEL_ENABLED		0x08
20#define THREAD_CANCEL_ASYNCHRONOUS	0x10
21
22
23struct thread_creation_attributes;
24
25// The public *_t types are only pointers to these structures
26// This way, we are completely free to change them, which might be
27// necessary in the future (not only due to the incomplete implementation
28// at this point).
29
30typedef struct _pthread_condattr {
31	bool		process_shared;
32	clockid_t	clock_id;
33} pthread_condattr;
34
35typedef struct _pthread_mutexattr {
36	int32		type;
37	bool		process_shared;
38} pthread_mutexattr;
39
40typedef struct _pthread_attr {
41	int32		detach_state;
42	int32		sched_priority;
43	size_t		stack_size;
44	size_t		guard_size;
45} pthread_attr;
46
47typedef struct _pthread_rwlockattr {
48	uint32_t	flags;
49} pthread_rwlockattr;
50
51typedef void (*pthread_key_destructor)(void *data);
52
53struct pthread_key {
54	int32		sequence;
55	pthread_key_destructor destructor;
56};
57
58struct pthread_key_data {
59	int32		sequence;
60	void		*value;
61};
62
63#define PTHREAD_UNUSED_SEQUENCE	0
64
65typedef struct _pthread_thread {
66	thread_id	id;
67	int32		flags;
68	void		*(*entry)(void*);
69	void		*entry_argument;
70	void		*exit_value;
71	struct pthread_key_data specific[PTHREAD_KEYS_MAX];
72	struct __pthread_cleanup_handler *cleanup_handlers;
73} pthread_thread;
74
75
76#ifdef __cplusplus
77extern "C" {
78#endif
79
80void __pthread_key_call_destructors(pthread_thread *thread);
81void __pthread_destroy_thread(void);
82pthread_thread *__allocate_pthread(void* (*entry)(void*), void *data);
83void __init_pthread(pthread_thread* thread, void* (*entry)(void*), void* data);
84status_t __pthread_init_creation_attributes(
85	const pthread_attr_t* pthreadAttributes, pthread_t thread,
86	status_t (*entryFunction)(void*, void*), void* argument1,
87	void* argument2, const char* name,
88	struct thread_creation_attributes* attributes);
89
90#ifdef __cplusplus
91}
92#endif
93
94#endif	/* _PTHREAD_PRIVATE_H_ */
95