xref: /haiku/headers/private/libroot/pthread_private.h (revision 3386b8b7858f5659c205b8f088eb568692699591)
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 // _pthread_mutex::flags values
23 #define MUTEX_FLAG_SHARED	0x80000000
24 
25 
26 struct thread_creation_attributes;
27 
28 // The public *_t types are only pointers to these structures
29 // This way, we are completely free to change them, which might be
30 // necessary in the future (not only due to the incomplete implementation
31 // at this point).
32 
33 typedef struct _pthread_condattr {
34 	bool		process_shared;
35 	clockid_t	clock_id;
36 } pthread_condattr;
37 
38 typedef struct _pthread_mutexattr {
39 	int32		type;
40 	bool		process_shared;
41 } pthread_mutexattr;
42 
43 typedef struct _pthread_barrierattr {
44 	bool		process_shared;
45 } pthread_barrierattr;
46 
47 typedef struct _pthread_attr {
48 	int32		detach_state;
49 	int32		sched_priority;
50 	size_t		stack_size;
51 	size_t		guard_size;
52 	void		*stack_address;
53 } pthread_attr;
54 
55 typedef struct _pthread_rwlockattr {
56 	uint32_t	flags;
57 } pthread_rwlockattr;
58 
59 typedef void (*pthread_key_destructor)(void *data);
60 
61 struct pthread_key {
62 	int32		sequence;
63 	pthread_key_destructor destructor;
64 };
65 
66 struct pthread_key_data {
67 	int32		sequence;
68 	void		*value;
69 };
70 
71 #define PTHREAD_UNUSED_SEQUENCE	0
72 
73 typedef struct _pthread_thread {
74 	thread_id	id;
75 	int32		flags;
76 	void		*(*entry)(void*);
77 	void		*entry_argument;
78 	void		*exit_value;
79 	struct pthread_key_data specific[PTHREAD_KEYS_MAX];
80 	struct __pthread_cleanup_handler *cleanup_handlers;
81 } pthread_thread;
82 
83 
84 #ifdef __cplusplus
85 extern "C" {
86 #endif
87 
88 void __pthread_key_call_destructors(pthread_thread *thread);
89 void __pthread_destroy_thread(void);
90 pthread_thread *__allocate_pthread(void* (*entry)(void*), void *data);
91 void __init_pthread(pthread_thread* thread, void* (*entry)(void*), void* data);
92 status_t __pthread_init_creation_attributes(
93 	const pthread_attr_t* pthreadAttributes, pthread_t thread,
94 	status_t (*entryFunction)(void*, void*), void* argument1,
95 	void* argument2, const char* name,
96 	struct thread_creation_attributes* attributes);
97 void __pthread_set_default_priority(int32 priority);
98 status_t __pthread_mutex_lock(pthread_mutex_t* mutex, bigtime_t timeout);
99 
100 int __pthread_getname_np(pthread_t thread, char* buffer, size_t length);
101 int __pthread_setname_np(pthread_t thread, const char* name);
102 
103 #ifdef __cplusplus
104 }
105 #endif
106 
107 #endif	/* _PTHREAD_PRIVATE_H_ */
108