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