123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- #ifndef _BITS_LIBC_LOCK_H
- #define _BITS_LIBC_LOCK_H 1
- #include <pthread.h>
- #ifdef _LIBC
- typedef pthread_mutex_t __libc_lock_t;
- #else
- typedef struct __libc_lock_opaque__ __libc_lock_t;
- #endif
- typedef pthread_key_t __libc_key_t;
- #define __libc_lock_define(CLASS,NAME) \
- CLASS __libc_lock_t NAME;
- #define __libc_lock_define_initialized(CLASS,NAME) \
- CLASS __libc_lock_t NAME;
- #define __libc_lock_define_initialized_recursive(CLASS,NAME) \
- CLASS __libc_lock_t NAME = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
- #define __libc_lock_init(NAME) \
- (__pthread_mutex_init != NULL ? __pthread_mutex_init (&(NAME), NULL) : 0);
- #define __libc_lock_init_recursive(NAME) \
- do { \
- if (__pthread_mutex_init != NULL) \
- { \
- pthread_mutexattr_t __attr; \
- __pthread_mutexattr_init (&__attr); \
- __pthread_mutexattr_settype (&__attr, PTHREAD_MUTEX_RECURSIVE_NP); \
- __pthread_mutex_init (&(NAME), &__attr); \
- __pthread_mutexattr_destroy (&__attr); \
- } \
- } while (0);
- #define __libc_lock_fini(NAME) \
- (__pthread_mutex_destroy != NULL ? __pthread_mutex_destroy (&(NAME)) : 0);
- #define __libc_lock_fini_recursive(NAME) __libc_lock_fini (NAME)
- #define __libc_lock_lock(NAME) \
- (__pthread_mutex_lock != NULL ? __pthread_mutex_lock (&(NAME)) : 0);
- #define __libc_lock_lock_recursive(NAME) __libc_lock_lock (NAME)
- #define __libc_lock_trylock(NAME) \
- (__pthread_mutex_trylock != NULL ? __pthread_mutex_trylock (&(NAME)) : 0)
- #define __libc_lock_trylock_recursive(NAME) __libc_lock_trylock (NAME)
- #define __libc_lock_unlock(NAME) \
- (__pthread_mutex_unlock != NULL ? __pthread_mutex_unlock (&(NAME)) : 0);
- #define __libc_lock_unlock_recursive(NAME) __libc_lock_unlock (NAME)
- #if PTHREAD_ONCE_INIT == 0
- # define __libc_once_define(CLASS, NAME) \
- CLASS pthread_once_t NAME
- #else
- # define __libc_once_define(CLASS, NAME) \
- CLASS pthread_once_t NAME = PTHREAD_ONCE_INIT
- #endif
- #define __libc_once(ONCE_CONTROL, INIT_FUNCTION) \
- do { \
- if (__pthread_once != NULL) \
- __pthread_once (&(ONCE_CONTROL), (INIT_FUNCTION)); \
- else if ((ONCE_CONTROL) == 0) { \
- INIT_FUNCTION (); \
- (ONCE_CONTROL) = 1; \
- } \
- } while (0)
- #define __libc_cleanup_region_start(FCT, ARG) \
- { struct _pthread_cleanup_buffer _buffer; \
- int _avail = _pthread_cleanup_push_defer != NULL; \
- if (_avail) { \
- _pthread_cleanup_push_defer (&_buffer, (FCT), (ARG)); \
- }
- #define __libc_cleanup_region_end(DOIT) \
- if (_avail) { \
- _pthread_cleanup_pop_restore (&_buffer, (DOIT)); \
- } \
- }
- #define __libc_cleanup_end(DOIT) \
- if (_avail) { \
- _pthread_cleanup_pop_restore (&_buffer, (DOIT)); \
- }
- #define __libc_key_create(KEY, DESTRUCTOR) \
- (__pthread_key_create != NULL ? __pthread_key_create (KEY, DESTRUCTOR) : 1)
- #define __libc_getspecific(KEY) \
- (__pthread_getspecific != NULL ? __pthread_getspecific (KEY) : NULL)
- #define __libc_setspecific(KEY, VALUE) \
- (__pthread_setspecific != NULL ? __pthread_setspecific (KEY, VALUE) : 0)
- #define __libc_atfork(PREPARE, PARENT, CHILD) \
- (__pthread_atfork != NULL ? __pthread_atfork (PREPARE, PARENT, CHILD) : 0)
- #ifndef __NO_WEAK_PTHREAD_ALIASES
- # ifdef weak_extern
- weak_extern (__pthread_mutex_init)
- weak_extern (__pthread_mutex_destroy)
- weak_extern (__pthread_mutex_lock)
- weak_extern (__pthread_mutex_trylock)
- weak_extern (__pthread_mutex_unlock)
- weak_extern (__pthread_mutexattr_init)
- weak_extern (__pthread_mutexattr_destroy)
- weak_extern (__pthread_mutexattr_settype)
- weak_extern (__pthread_key_create)
- weak_extern (__pthread_setspecific)
- weak_extern (__pthread_getspecific)
- weak_extern (__pthread_once)
- weak_extern (__pthread_initialize)
- weak_extern (__pthread_atfork)
- weak_extern (_pthread_cleanup_push_defer)
- weak_extern (_pthread_cleanup_pop_restore)
- # else
- # pragma weak __pthread_mutex_init
- # pragma weak __pthread_mutex_destroy
- # pragma weak __pthread_mutex_lock
- # pragma weak __pthread_mutex_trylock
- # pragma weak __pthread_mutex_unlock
- # pragma weak __pthread_mutexattr_init
- # pragma weak __pthread_mutexattr_destroy
- # pragma weak __pthread_mutexattr_settype
- # pragma weak __pthread_key_create
- # pragma weak __pthread_setspecific
- # pragma weak __pthread_getspecific
- # pragma weak __pthread_once
- # pragma weak __pthread_initialize
- # pragma weak __pthread_atfork
- # pragma weak _pthread_cleanup_push_defer
- # pragma weak _pthread_cleanup_pop_restore
- # endif
- #endif
- #define __libc_mutex_unlock __pthread_mutex_unlock
- #endif
|