source: trunk/src/emx/include/sys/fmutex.h@ 880

Last change on this file since 880 was 880, checked in by bird, 22 years ago

Inlined _fmutex_checked_release & _fmutex_checked_request.

  • Property cvs2svn:cvs-rev set to 1.3
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 2.3 KB
Line 
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#include <stdlib.h> /* need abort */
11
12#if defined (__cplusplus)
13extern "C" {
14#endif
15
16/* Constants for _fmutex.fs. See _fmutex_available() for ordering. */
17
18#define _FMS_UNINIT 0
19#define _FMS_AVAILABLE 1
20#define _FMS_OWNED_SIMPLE 2
21#define _FMS_OWNED_HARD 3
22
23/* Constants for _fmutex_create() */
24
25#define _FMC_SHARED 0x01
26
27/* Constants for _fmutex_request() */
28
29#define _FMR_IGNINT 0x01
30#define _FMR_NOWAIT 0x02
31
32/* We cannot use __attribute__ ((__packed__)) because G++ does not
33 support this. */
34
35#pragma pack(1)
36typedef struct
37{
38 /** Handle to event semaphore. */
39 unsigned long hev;
40 /** Semaphore status. */
41 __volatile__ signed char fs;
42 /** Semaphore create flags. (_FMC_SHARED) */
43 unsigned char flags;
44 /** padding the struct to 8 bytes. */
45 unsigned char padding[2];
46} _fmutex;
47#pragma pack()
48
49
50unsigned __fmutex_request_internal (_fmutex *, unsigned, signed char);
51unsigned __fmutex_create_internal (_fmutex *, unsigned);
52unsigned __fmutex_release_internal (_fmutex *);
53
54
55static __inline__ unsigned _fmutex_request (_fmutex *sem, unsigned flags)
56{
57 signed char fs;
58
59 fs = __cxchg (&sem->fs, _FMS_OWNED_SIMPLE);
60 if (fs == _FMS_AVAILABLE)
61 return 0;
62 else
63 return __fmutex_request_internal (sem, flags, fs);
64}
65
66
67static __inline__ unsigned _fmutex_release (_fmutex *sem)
68{
69 signed char fs;
70
71 fs = __cxchg (&sem->fs, _FMS_AVAILABLE);
72 if (fs == _FMS_OWNED_HARD)
73 return __fmutex_release_internal (sem);
74 else
75 return 0;
76}
77
78
79static __inline__ int _fmutex_available (_fmutex *sem)
80{
81 return sem->fs <= _FMS_AVAILABLE;
82}
83
84
85unsigned _fmutex_create (_fmutex *, unsigned);
86unsigned _fmutex_open (_fmutex *);
87unsigned _fmutex_close (_fmutex *);
88void _fmutex_dummy (_fmutex *);
89
90void _fmutex_checked_close (_fmutex *);
91void _fmutex_checked_create (_fmutex *, unsigned);
92void _fmutex_checked_open (_fmutex *);
93
94static __inline__ void _fmutex_checked_release (_fmutex * sem)
95{
96 if (_fmutex_release (sem) != 0)
97 abort ();
98}
99
100static __inline__ void _fmutex_checked_request (_fmutex * sem, unsigned flags)
101{
102 if (_fmutex_request (sem, flags) != 0)
103 abort ();
104}
105
106#if defined (__cplusplus)
107}
108#endif
109
110#endif /* not _SYS_FMUTEX_H */
Note: See TracBrowser for help on using the repository browser.