| 1 | /* sys/fmutex.h (emx+gcc) */
|
|---|
| 2 |
|
|---|
| 3 | /* Fast mutex semaphores. */
|
|---|
| 4 |
|
|---|
| 5 | /* This header requires <sys/builtin.h>. */
|
|---|
| 6 |
|
|---|
| 7 | #ifndef _SYS_FMUTEX_H
|
|---|
| 8 | #define _SYS_FMUTEX_H
|
|---|
| 9 |
|
|---|
| 10 | #if defined (__cplusplus)
|
|---|
| 11 | extern "C" {
|
|---|
| 12 | #endif
|
|---|
| 13 |
|
|---|
| 14 | /* Constants for _fmutex.fs. See _fmutex_available() for ordering. */
|
|---|
| 15 |
|
|---|
| 16 | #define _FMS_UNINIT 0
|
|---|
| 17 | #define _FMS_AVAILABLE 1
|
|---|
| 18 | #define _FMS_OWNED_SIMPLE 2
|
|---|
| 19 | #define _FMS_OWNED_HARD 3
|
|---|
| 20 |
|
|---|
| 21 | /* Constants for _fmutex_create() */
|
|---|
| 22 |
|
|---|
| 23 | #define _FMC_SHARED 0x01
|
|---|
| 24 |
|
|---|
| 25 | /* Constants for _fmutex_request() */
|
|---|
| 26 |
|
|---|
| 27 | #define _FMR_IGNINT 0x01
|
|---|
| 28 | #define _FMR_NOWAIT 0x02
|
|---|
| 29 |
|
|---|
| 30 | /* We cannot use __attribute__ ((__packed__)) because G++ does not
|
|---|
| 31 | support this. */
|
|---|
| 32 |
|
|---|
| 33 | #pragma pack(1)
|
|---|
| 34 | typedef struct
|
|---|
| 35 | {
|
|---|
| 36 | unsigned long hev; /* HEV */
|
|---|
| 37 | __volatile__ signed char fs; /* Status */
|
|---|
| 38 | } _fmutex;
|
|---|
| 39 | #pragma pack()
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 | unsigned __fmutex_request_internal (_fmutex *, unsigned, signed char);
|
|---|
| 43 | unsigned __fmutex_create_internal (_fmutex *, unsigned);
|
|---|
| 44 | unsigned __fmutex_release_internal (_fmutex *);
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 | static __inline__ unsigned _fmutex_request (_fmutex *sem, unsigned flags)
|
|---|
| 48 | {
|
|---|
| 49 | signed char fs;
|
|---|
| 50 |
|
|---|
| 51 | fs = __cxchg (&sem->fs, _FMS_OWNED_SIMPLE);
|
|---|
| 52 | if (fs == _FMS_AVAILABLE)
|
|---|
| 53 | return 0;
|
|---|
| 54 | else
|
|---|
| 55 | return __fmutex_request_internal (sem, flags, fs);
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 | static __inline__ unsigned _fmutex_release (_fmutex *sem)
|
|---|
| 60 | {
|
|---|
| 61 | signed char fs;
|
|---|
| 62 |
|
|---|
| 63 | fs = __cxchg (&sem->fs, _FMS_AVAILABLE);
|
|---|
| 64 | if (fs == _FMS_OWNED_HARD)
|
|---|
| 65 | return __fmutex_release_internal (sem);
|
|---|
| 66 | else
|
|---|
| 67 | return 0;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 | static __inline__ int _fmutex_available (_fmutex *sem)
|
|---|
| 72 | {
|
|---|
| 73 | return sem->fs <= _FMS_AVAILABLE;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 | unsigned _fmutex_create (_fmutex *, unsigned);
|
|---|
| 78 | unsigned _fmutex_open (_fmutex *);
|
|---|
| 79 | unsigned _fmutex_close (_fmutex *);
|
|---|
| 80 | void _fmutex_dummy (_fmutex *);
|
|---|
| 81 |
|
|---|
| 82 | void _fmutex_checked_close (_fmutex *);
|
|---|
| 83 | void _fmutex_checked_create (_fmutex *, unsigned);
|
|---|
| 84 | void _fmutex_checked_open (_fmutex *);
|
|---|
| 85 | void _fmutex_checked_release (_fmutex *);
|
|---|
| 86 | void _fmutex_checked_request (_fmutex *, unsigned);
|
|---|
| 87 |
|
|---|
| 88 | #if defined (__cplusplus)
|
|---|
| 89 | }
|
|---|
| 90 | #endif
|
|---|
| 91 |
|
|---|
| 92 | #endif /* not _SYS_FMUTEX_H */
|
|---|