| 1 |
2 |
drasko |
/* Copyright (C) 2006 Manuel Novoa III <mjn3@codepoet.org>
|
| 2 |
|
|
*
|
| 3 |
|
|
* GNU Library General Public License (LGPL) version 2 or later.
|
| 4 |
|
|
*
|
| 5 |
|
|
* Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
|
| 6 |
|
|
*/
|
| 7 |
|
|
|
| 8 |
|
|
#ifndef _UCLIBC_MUTEX_H
|
| 9 |
|
|
#define _UCLIBC_MUTEX_H
|
| 10 |
|
|
|
| 11 |
|
|
#include <features.h>
|
| 12 |
|
|
|
| 13 |
|
|
#ifdef __UCLIBC_HAS_THREADS__
|
| 14 |
|
|
|
| 15 |
|
|
#include <pthread.h>
|
| 16 |
|
|
#include <bits/uClibc_pthread.h>
|
| 17 |
|
|
|
| 18 |
|
|
#define __UCLIBC_MUTEX_TYPE pthread_mutex_t
|
| 19 |
|
|
|
| 20 |
|
|
#define __UCLIBC_MUTEX(M) pthread_mutex_t M
|
| 21 |
|
|
#define __UCLIBC_MUTEX_INIT(M,I) pthread_mutex_t M = I
|
| 22 |
|
|
#define __UCLIBC_MUTEX_STATIC(M,I) static pthread_mutex_t M = I
|
| 23 |
|
|
#define __UCLIBC_MUTEX_EXTERN(M) extern pthread_mutex_t M
|
| 24 |
|
|
|
| 25 |
|
|
#define __UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE(M) \
|
| 26 |
|
|
__pthread_mutex_lock(&(M))
|
| 27 |
|
|
|
| 28 |
|
|
#define __UCLIBC_MUTEX_UNLOCK_CANCEL_UNSAFE(M) \
|
| 29 |
|
|
__pthread_mutex_unlock(&(M))
|
| 30 |
|
|
|
| 31 |
|
|
#define __UCLIBC_MUTEX_TRYLOCK_CANCEL_UNSAFE(M) \
|
| 32 |
|
|
__pthread_mutex_trylock(&(M))
|
| 33 |
|
|
|
| 34 |
|
|
#define __UCLIBC_MUTEX_CONDITIONAL_LOCK(M,C) \
|
| 35 |
|
|
do { \
|
| 36 |
|
|
struct _pthread_cleanup_buffer __infunc_pthread_cleanup_buffer; \
|
| 37 |
|
|
if (C) { \
|
| 38 |
|
|
_pthread_cleanup_push_defer(&__infunc_pthread_cleanup_buffer, \
|
| 39 |
|
|
(void (*) (void *))__pthread_mutex_unlock, \
|
| 40 |
|
|
&(M)); \
|
| 41 |
|
|
__pthread_mutex_lock(&(M)); \
|
| 42 |
|
|
} \
|
| 43 |
|
|
((void)0)
|
| 44 |
|
|
|
| 45 |
|
|
#define __UCLIBC_MUTEX_CONDITIONAL_UNLOCK(M,C) \
|
| 46 |
|
|
if (C) { \
|
| 47 |
|
|
_pthread_cleanup_pop_restore(&__infunc_pthread_cleanup_buffer,1); \
|
| 48 |
|
|
} \
|
| 49 |
|
|
} while (0)
|
| 50 |
|
|
|
| 51 |
|
|
#define __UCLIBC_MUTEX_AUTO_LOCK_VAR(A) int A
|
| 52 |
|
|
|
| 53 |
|
|
#define __UCLIBC_MUTEX_AUTO_LOCK(M,A,V) \
|
| 54 |
|
|
__UCLIBC_MUTEX_CONDITIONAL_LOCK(M,((A=(V)) == 0))
|
| 55 |
|
|
|
| 56 |
|
|
#define __UCLIBC_MUTEX_AUTO_UNLOCK(M,A) \
|
| 57 |
|
|
__UCLIBC_MUTEX_CONDITIONAL_UNLOCK(M,(A == 0))
|
| 58 |
|
|
|
| 59 |
|
|
#define __UCLIBC_MUTEX_LOCK(M) \
|
| 60 |
|
|
__UCLIBC_MUTEX_CONDITIONAL_LOCK(M, 1)
|
| 61 |
|
|
|
| 62 |
|
|
#define __UCLIBC_MUTEX_UNLOCK(M) \
|
| 63 |
|
|
__UCLIBC_MUTEX_CONDITIONAL_UNLOCK(M, 1)
|
| 64 |
|
|
|
| 65 |
|
|
#else
|
| 66 |
|
|
|
| 67 |
|
|
#define __UCLIBC_MUTEX(M) void *__UCLIBC_MUTEX_DUMMY_ ## M
|
| 68 |
|
|
#define __UCLIBC_MUTEX_INIT(M,I) extern void *__UCLIBC_MUTEX_DUMMY_ ## M
|
| 69 |
|
|
#define __UCLIBC_MUTEX_STATIC(M,I) extern void *__UCLIBC_MUTEX_DUMMY_ ## M
|
| 70 |
|
|
#define __UCLIBC_MUTEX_EXTERN(M) extern void *__UCLIBC_MUTEX_DUMMY_ ## M
|
| 71 |
|
|
|
| 72 |
|
|
#define __UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE(M) ((void)0)
|
| 73 |
|
|
#define __UCLIBC_MUTEX_UNLOCK_CANCEL_UNSAFE(M) ((void)0)
|
| 74 |
|
|
#define __UCLIBC_MUTEX_TRYLOCK_CANCEL_UNSAFE(M) (0) /* Always succeed? */
|
| 75 |
|
|
|
| 76 |
|
|
#define __UCLIBC_MUTEX_CONDITIONAL_LOCK(M,C) ((void)0)
|
| 77 |
|
|
#define __UCLIBC_MUTEX_CONDITIONAL_UNLOCK(M,C) ((void)0)
|
| 78 |
|
|
|
| 79 |
|
|
#define __UCLIBC_MUTEX_AUTO_LOCK_VAR(A) ((void)0)
|
| 80 |
|
|
#define __UCLIBC_MUTEX_AUTO_LOCK(M,A,V) ((void)0)
|
| 81 |
|
|
#define __UCLIBC_MUTEX_AUTO_UNLOCK(M,A) ((void)0)
|
| 82 |
|
|
|
| 83 |
|
|
#define __UCLIBC_MUTEX_LOCK(M) ((void)0)
|
| 84 |
|
|
#define __UCLIBC_MUTEX_UNLOCK(M) ((void)0)
|
| 85 |
|
|
|
| 86 |
|
|
#endif
|
| 87 |
|
|
|
| 88 |
|
|
#endif /* _UCLIBC_MUTEX_H */
|