blob: 2e3ac3d971a723053dd85069cbb6d84a1f771c97 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/* $OpenBSD: thread_private.h,v 1.18 2006/02/22 07:16:31 otto Exp $ */
2
3/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
4
5#ifndef _THREAD_PRIVATE_H_
6#define _THREAD_PRIVATE_H_
7
8#include <pthread.h>
9
Elliott Hughes0468feb2014-06-20 22:49:20 -070010__BEGIN_DECLS
11
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080012/*
13 * This file defines the thread library interface to libc. Thread
14 * libraries must implement the functions described here for proper
15 * inter-operation with libc. libc contains weak versions of the
16 * described functions for operation in a non-threaded environment.
17 */
18
19/*
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080020 * helper macro to make unique names in the thread namespace
21 */
22#define __THREAD_NAME(name) __CONCAT(_thread_tagname_,name)
23
24struct __thread_private_tag_t {
25 pthread_mutex_t _private_lock;
26 pthread_key_t _private_key;
27};
28
29#define _THREAD_PRIVATE_MUTEX(name) \
30 static struct __thread_private_tag_t __THREAD_NAME(name) = { PTHREAD_MUTEX_INITIALIZER, -1 }
31#define _THREAD_PRIVATE_MUTEX_LOCK(name) \
32 pthread_mutex_lock( &__THREAD_NAME(name)._private_lock )
33#define _THREAD_PRIVATE_MUTEX_UNLOCK(name) \
34 pthread_mutex_unlock( &__THREAD_NAME(name)._private_lock )
35
Dmitriy Ivanov53c3c272014-07-11 12:59:16 -070036/* Note that these aren't compatible with the usual OpenBSD ones which lazy-initialize! */
37#define _MUTEX_LOCK(l) pthread_mutex_lock((pthread_mutex_t*) l)
38#define _MUTEX_UNLOCK(l) pthread_mutex_unlock((pthread_mutex_t*) l)
39
40__LIBC_HIDDEN__ void _thread_atexit_lock(void);
41__LIBC_HIDDEN__ void _thread_atexit_unlock(void);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080042
Elliott Hughesf2cea022014-03-13 14:54:53 -070043#define _ATEXIT_LOCK() _thread_atexit_lock()
44#define _ATEXIT_UNLOCK() _thread_atexit_unlock()
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080045
Elliott Hughes0468feb2014-06-20 22:49:20 -070046__LIBC_HIDDEN__ void _thread_arc4_lock(void);
47__LIBC_HIDDEN__ void _thread_arc4_unlock(void);
48
Elliott Hughes2b67d7d2014-07-18 15:57:41 -070049#define _ARC4_LOCK() _thread_arc4_lock()
50#define _ARC4_UNLOCK() _thread_arc4_unlock()
51#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
Elliott Hughes0468feb2014-06-20 22:49:20 -070052
53__END_DECLS
54
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080055#endif /* _THREAD_PRIVATE_H_ */