1a635399bSAxel Dörfler/*
2ecf6b86cSAxel Dörfler * Copyright 2003-2009, Axel D��rfler, axeld@pinc-software.de.
3550a30a0SRyan Leavengood * Copyright 2007, Ryan Leavengood, leavengood@gmail.com.
4550a30a0SRyan Leavengood * All rights reserved. Distributed under the terms of the MIT License.
5550a30a0SRyan Leavengood */
6a635399bSAxel Dörfler#ifndef _PTHREAD_PRIVATE_H_
7a635399bSAxel Dörfler#define _PTHREAD_PRIVATE_H_
8a635399bSAxel Dörfler
9a635399bSAxel Dörfler
10a635399bSAxel Dörfler#include <pthread.h>
1174b016ecSAxel Dörfler
1274b016ecSAxel Dörfler#include <OS.h>
1374b016ecSAxel Dörfler
1424df6592SIngo Weinhold
1524df6592SIngo Weinhold// _pthread_thread::flags values
1624df6592SIngo Weinhold#define THREAD_DETACHED				0x01
1724df6592SIngo Weinhold#define THREAD_DEAD					0x02
1824df6592SIngo Weinhold#define THREAD_CANCELED				0x04
1924df6592SIngo Weinhold#define THREAD_CANCEL_ENABLED		0x08
2024df6592SIngo Weinhold#define THREAD_CANCEL_ASYNCHRONOUS	0x10
2124df6592SIngo Weinhold
2224df6592SIngo Weinhold
2324df6592SIngo Weinholdstruct thread_creation_attributes;
2424df6592SIngo Weinhold
2574b016ecSAxel Dörfler// The public *_t types are only pointers to these structures
2674b016ecSAxel Dörfler// This way, we are completely free to change them, which might be
2774b016ecSAxel Dörfler// necessary in the future (not only due to the incomplete implementation
2874b016ecSAxel Dörfler// at this point).
2974b016ecSAxel Dörfler
30550a30a0SRyan Leavengoodtypedef struct _pthread_condattr {
31550a30a0SRyan Leavengood	bool		process_shared;
3210b4fed2SHamish Morrison	clockid_t	clock_id;
33550a30a0SRyan Leavengood} pthread_condattr;
34550a30a0SRyan Leavengood
3574b016ecSAxel Dörflertypedef struct _pthread_mutexattr {
3674b016ecSAxel Dörfler	int32		type;
3774b016ecSAxel Dörfler	bool		process_shared;
3874b016ecSAxel Dörfler} pthread_mutexattr;
3974b016ecSAxel Dörfler
400e0f49e7SDmytro Shynkevychtypedef struct _pthread_barrierattr {
410e0f49e7SDmytro Shynkevych	bool		process_shared;
420e0f49e7SDmytro Shynkevych} pthread_barrierattr;
430e0f49e7SDmytro Shynkevych
44a23efdfaSJérôme Duvaltypedef struct _pthread_attr {
45a23efdfaSJérôme Duval	int32		detach_state;
46a23efdfaSJérôme Duval	int32		sched_priority;
47f7cc12b3SIngo Weinhold	size_t		stack_size;
48d1f280c8SHamish Morrison	size_t		guard_size;
49901c3d44SJérôme Duval	void		*stack_address;
50a23efdfaSJérôme Duval} pthread_attr;
51a23efdfaSJérôme Duval
52a8af2b6dSIngo Weinholdtypedef struct _pthread_rwlockattr {
53a8af2b6dSIngo Weinhold	uint32_t	flags;
54a8af2b6dSIngo Weinhold} pthread_rwlockattr;
55a8af2b6dSIngo Weinhold
56f127ebfdSAxel Dörflertypedef void (*pthread_key_destructor)(void *data);
57f127ebfdSAxel Dörfler
58f127ebfdSAxel Dörflerstruct pthread_key {
59077c84ebSPawel Dziepak	int32		sequence;
60f127ebfdSAxel Dörfler	pthread_key_destructor destructor;
61f127ebfdSAxel Dörfler};
62f127ebfdSAxel Dörfler
63f127ebfdSAxel Dörflerstruct pthread_key_data {
64077c84ebSPawel Dziepak	int32		sequence;
65f127ebfdSAxel Dörfler	void		*value;
66f127ebfdSAxel Dörfler};
67f127ebfdSAxel Dörfler
68f127ebfdSAxel Dörfler#define PTHREAD_UNUSED_SEQUENCE	0
69954f408fSJérôme Duval
70a8af2b6dSIngo Weinholdtypedef struct _pthread_thread {
71a8af2b6dSIngo Weinhold	thread_id	id;
72a8af2b6dSIngo Weinhold	int32		flags;
73a635399bSAxel Dörfler	void		*(*entry)(void*);
74a635399bSAxel Dörfler	void		*entry_argument;
75a8af2b6dSIngo Weinhold	void		*exit_value;
76f127ebfdSAxel Dörfler	struct pthread_key_data specific[PTHREAD_KEYS_MAX];
77a635399bSAxel Dörfler	struct __pthread_cleanup_handler *cleanup_handlers;
78a8af2b6dSIngo Weinhold} pthread_thread;
79a635399bSAxel Dörfler
80a635399bSAxel Dörfler
81a635399bSAxel Dörfler#ifdef __cplusplus
82a635399bSAxel Dörflerextern "C" {
83a635399bSAxel Dörfler#endif
84a635399bSAxel Dörfler
85a8af2b6dSIngo Weinholdvoid __pthread_key_call_destructors(pthread_thread *thread);
86ecf6b86cSAxel Dörflervoid __pthread_destroy_thread(void);
8724df6592SIngo Weinholdpthread_thread *__allocate_pthread(void* (*entry)(void*), void *data);
8824df6592SIngo Weinholdvoid __init_pthread(pthread_thread* thread, void* (*entry)(void*), void* data);
8924df6592SIngo Weinholdstatus_t __pthread_init_creation_attributes(
9024df6592SIngo Weinhold	const pthread_attr_t* pthreadAttributes, pthread_t thread,
9124df6592SIngo Weinhold	status_t (*entryFunction)(void*, void*), void* argument1,
9224df6592SIngo Weinhold	void* argument2, const char* name,
9324df6592SIngo Weinhold	struct thread_creation_attributes* attributes);
948ae2e956STimothy Guvoid __pthread_set_default_priority(int32 priority);
953c2901a9SAugustin Cavalierstatus_t __pthread_mutex_lock(pthread_mutex_t* mutex, bigtime_t timeout);
96a635399bSAxel Dörfler
97a635399bSAxel Dörfler#ifdef __cplusplus
98a635399bSAxel Dörfler}
99a635399bSAxel Dörfler#endif
100954f408fSJérôme Duval
10174b016ecSAxel Dörfler#endif	/* _PTHREAD_PRIVATE_H_ */
102