1 /* Copyright (c) 2002 Jeff Johnston  <jjohnstn@redhat.com> */
2 #ifndef __SYS_LOCK_H__
3 #define __SYS_LOCK_H__
4 
5 /* dummy lock routines for single-threaded aps */
6 
7 #include <newlib.h>
8 #include <_ansi.h>
9 
10 #if !defined(_RETARGETABLE_LOCKING)
11 
12 typedef int _LOCK_T;
13 typedef int _LOCK_RECURSIVE_T;
14 
15 #define __LOCK_INIT(lock)
16 #define __LOCK_INIT_RECURSIVE(lock)
17 #define __lock_init(lock) ((void) 0)
18 #define __lock_init_recursive(lock) ((void) 0)
19 #define __lock_close(lock) ((void) 0)
20 #define __lock_close_recursive(lock) ((void) 0)
21 #define __lock_acquire(lock) ((void) 0)
22 #define __lock_acquire_recursive(lock) ((void) 0)
23 #define __lock_try_acquire(lock) ((void) 0)
24 #define __lock_try_acquire_recursive(lock) ((void) 0)
25 #define __lock_release(lock) ((void) 0)
26 #define __lock_release_recursive(lock) ((void) 0)
27 
28 #else
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 struct __lock;
35 typedef struct __lock * _LOCK_T;
36 #define _LOCK_RECURSIVE_T _LOCK_T
37 
38 #define __LOCK_INIT(lock) extern struct __lock __lock_ ## lock;
39 #define __LOCK_INIT_RECURSIVE(lock) __LOCK_INIT(lock)
40 
41 extern void __retarget_lock_init(_LOCK_T *lock);
42 #define __lock_init(lock) __retarget_lock_init(&lock)
43 extern void __retarget_lock_init_recursive(_LOCK_T *lock);
44 #define __lock_init_recursive(lock) __retarget_lock_init_recursive(&lock)
45 extern void __retarget_lock_close(_LOCK_T lock);
46 #define __lock_close(lock) __retarget_lock_close(lock)
47 extern void __retarget_lock_close_recursive(_LOCK_T lock);
48 #define __lock_close_recursive(lock) __retarget_lock_close_recursive(lock)
49 extern void __retarget_lock_acquire(_LOCK_T lock);
50 #define __lock_acquire(lock) __retarget_lock_acquire(lock)
51 extern void __retarget_lock_acquire_recursive(_LOCK_T lock);
52 #define __lock_acquire_recursive(lock) __retarget_lock_acquire_recursive(lock)
53 extern int __retarget_lock_try_acquire(_LOCK_T lock);
54 #define __lock_try_acquire(lock) __retarget_lock_try_acquire(lock)
55 extern int __retarget_lock_try_acquire_recursive(_LOCK_T lock);
56 #define __lock_try_acquire_recursive(lock) \
57   __retarget_lock_try_acquire_recursive(lock)
58 extern void __retarget_lock_release(_LOCK_T lock);
59 #define __lock_release(lock) __retarget_lock_release(lock)
60 extern void __retarget_lock_release_recursive(_LOCK_T lock);
61 #define __lock_release_recursive(lock) __retarget_lock_release_recursive(lock)
62 
63 #ifdef __cplusplus
64 }
65 #endif
66 
67 #endif /* !defined(_RETARGETABLE_LOCKING) */
68 
69 #define __LIBC_LOCK()	__lock_acquire_recursive(&__lock___libc_recursive_mutex)
70 #define __LIBC_UNLOCK()	__lock_release_recursive(&__lock___libc_recursive_mutex)
71 __LOCK_INIT_RECURSIVE(__libc_recursive_mutex)
72 
73 #endif /* __SYS_LOCK_H__ */
74