pthread_private.h revision 077c84eb
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} pthread_condattr;
33
34typedef struct _pthread_mutexattr {
35	int32		type;
36	bool		process_shared;
37} pthread_mutexattr;
38
39typedef struct _pthread_attr {
40	int32		detach_state;
41	int32		sched_priority;
42	size_t		stack_size;
43	size_t		guard_size;
44} pthread_attr;
45
46typedef struct _pthread_rwlockattr {
47	uint32_t	flags;
48} pthread_rwlockattr;
49
50typedef void (*pthread_key_destructor)(void *data);
51
52struct pthread_key {
53	int32		sequence;
54	pthread_key_destructor destructor;
55};
56
57struct pthread_key_data {
58	int32		sequence;
59	void		*value;
60};
61
62#define PTHREAD_UNUSED_SEQUENCE	0
63
64typedef struct _pthread_thread {
65	thread_id	id;
66	int32		flags;
67	void		*(*entry)(void*);
68	void		*entry_argument;
69	void		*exit_value;
70	struct pthread_key_data specific[PTHREAD_KEYS_MAX];
71	struct __pthread_cleanup_handler *cleanup_handlers;
72} pthread_thread;
73
74
75#ifdef __cplusplus
76extern "C" {
77#endif
78
79void __pthread_key_call_destructors(pthread_thread *thread);
80void __pthread_destroy_thread(void);
81pthread_thread *__allocate_pthread(void* (*entry)(void*), void *data);
82void __init_pthread(pthread_thread* thread, void* (*entry)(void*), void* data);
83status_t __pthread_init_creation_attributes(
84	const pthread_attr_t* pthreadAttributes, pthread_t thread,
85	status_t (*entryFunction)(void*, void*), void* argument1,
86	void* argument2, const char* name,
87	struct thread_creation_attributes* attributes);
88
89#ifdef __cplusplus
90}
91#endif
92
93#endif	/* _PTHREAD_PRIVATE_H_ */
94