xref: /haiku/headers/private/libroot/pthread_private.h (revision 4a55cc230cf7566cadcbb23b1928eefff8aea9a2)
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 	void		*stack_address;
50 } pthread_attr;
51 
52 typedef struct _pthread_rwlockattr {
53 	uint32_t	flags;
54 } pthread_rwlockattr;
55 
56 typedef void (*pthread_key_destructor)(void *data);
57 
58 struct pthread_key {
59 	int32		sequence;
60 	pthread_key_destructor destructor;
61 };
62 
63 struct pthread_key_data {
64 	int32		sequence;
65 	void		*value;
66 };
67 
68 #define PTHREAD_UNUSED_SEQUENCE	0
69 
70 typedef struct _pthread_thread {
71 	thread_id	id;
72 	int32		flags;
73 	void		*(*entry)(void*);
74 	void		*entry_argument;
75 	void		*exit_value;
76 	struct pthread_key_data specific[PTHREAD_KEYS_MAX];
77 	struct __pthread_cleanup_handler *cleanup_handlers;
78 } pthread_thread;
79 
80 
81 #ifdef __cplusplus
82 extern "C" {
83 #endif
84 
85 void __pthread_key_call_destructors(pthread_thread *thread);
86 void __pthread_destroy_thread(void);
87 pthread_thread *__allocate_pthread(void* (*entry)(void*), void *data);
88 void __init_pthread(pthread_thread* thread, void* (*entry)(void*), void* data);
89 status_t __pthread_init_creation_attributes(
90 	const pthread_attr_t* pthreadAttributes, pthread_t thread,
91 	status_t (*entryFunction)(void*, void*), void* argument1,
92 	void* argument2, const char* name,
93 	struct thread_creation_attributes* attributes);
94 void __pthread_set_default_priority(int32 priority);
95 status_t __pthread_mutex_lock(pthread_mutex_t* mutex, bigtime_t timeout);
96 
97 int __pthread_getname_np(pthread_t thread, char* buffer, size_t length);
98 int __pthread_setname_np(pthread_t thread, const char* name);
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 #endif	/* _PTHREAD_PRIVATE_H_ */
105