Changeset 1661 for trunk/src/emx/include/sys/fmutex.h
- Timestamp:
- Nov 22, 2004, 2:46:26 AM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/include/sys/fmutex.h
-
Property cvs2svn:cvs-rev
changed from
1.3
to1.4
r1660 r1661 6 6 7 7 #ifndef _SYS_FMUTEX_H 8 #define _SYS_FMUTEX_H8 #define _SYS_FMUTEX_H 9 9 10 #include <stdlib.h> /* need abort */ 10 #include <sys/cdefs.h> 11 #include <stdlib.h> /* need abort */ 12 #include <InnoTekLIBC/FastInfoBlocks.h> 11 13 12 #if defined (__cplusplus) 13 extern "C" { 14 #endif 14 __BEGIN_DECLS 15 15 16 16 /* Constants for _fmutex.fs. See _fmutex_available() for ordering. */ 17 17 18 #define _FMS_UNINIT 019 #define _FMS_AVAILABLE 120 #define _FMS_OWNED_SIMPLE 221 #define _FMS_OWNED_HARD 318 #define _FMS_UNINIT 0 19 #define _FMS_AVAILABLE 1 20 #define _FMS_OWNED_SIMPLE 2 21 #define _FMS_OWNED_HARD 3 22 22 23 23 /* Constants for _fmutex_create() */ 24 24 25 #define _FMC_SHARED 0x01 25 #define _FMC_SHARED 0x01 26 #define _FMC_MUST_COMPLETE 0x02 27 #define _FMC_DUMMY 0x04 /* internal */ 26 28 27 29 /* Constants for _fmutex_request() */ 28 30 29 #define _FMR_IGNINT 0x0130 #define _FMR_NOWAIT 0x0231 #define _FMR_IGNINT 0x01 32 #define _FMR_NOWAIT 0x02 31 33 32 34 /* We cannot use __attribute__ ((__packed__)) because G++ does not 33 35 support this. */ 34 36 35 #pragma pack(1)37 #pragma pack(1) 36 38 typedef struct 37 39 { 38 40 /** Handle to event semaphore. */ 39 unsigned long hev;41 unsigned long hev; 40 42 /** Semaphore status. */ 41 __volatile__ signed charfs;43 volatile signed char fs; 42 44 /** Semaphore create flags. (_FMC_SHARED) */ 43 unsigned char flags; 44 /** padding the struct to 8 bytes. */ 45 unsigned char padding[2]; 45 unsigned char flags; 46 /** padding the struct to 16 bytes. */ 47 unsigned char padding[2]; 48 /** The (pid << 16) | tid of the owner. */ 49 volatile unsigned Owner; 50 /** Descriptive name of the mutex. */ 51 const char *pszDesc; 46 52 } _fmutex; 47 #pragma pack() 53 #pragma pack() 54 48 55 49 56 50 57 unsigned __fmutex_request_internal (_fmutex *, unsigned, signed char); 51 unsigned __fmutex_ create_internal(_fmutex *, unsigned);58 unsigned __fmutex_request_internal_must_complete (_fmutex *, unsigned); 52 59 unsigned __fmutex_release_internal (_fmutex *); 60 unsigned __fmutex_release_internal_must_complete (_fmutex *); 53 61 54 62 55 63 static __inline__ unsigned _fmutex_request (_fmutex *sem, unsigned flags) 56 64 { 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); 65 if (!(sem->flags & _FMC_MUST_COMPLETE)) 66 { 67 signed char fs = __cxchg (&sem->fs, _FMS_OWNED_SIMPLE); 68 if (fs == _FMS_AVAILABLE) 69 { 70 __atomic_xchg(&sem->Owner, fibGetTidPid()); 71 return 0; 72 } 73 else 74 return __fmutex_request_internal (sem, flags, fs); 75 } 76 else 77 return __fmutex_request_internal_must_complete (sem, flags); 64 78 } 65 79 … … 67 81 static __inline__ unsigned _fmutex_release (_fmutex *sem) 68 82 { 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; 83 if (!(sem->flags & _FMC_MUST_COMPLETE)) 84 { 85 signed char fs; 86 __atomic_xchg(&sem->Owner, 0); 87 fs = __cxchg(&sem->fs, _FMS_AVAILABLE); 88 if (fs != _FMS_OWNED_HARD) 89 return 0; 90 else 91 return __fmutex_release_internal (sem); 92 } 93 else 94 return __fmutex_release_internal_must_complete (sem); 76 95 } 77 78 96 79 97 static __inline__ int _fmutex_available (_fmutex *sem) 80 98 { 81 return sem->fs <= _FMS_AVAILABLE;99 return sem->fs <= _FMS_AVAILABLE; 82 100 } 83 101 84 102 85 103 unsigned _fmutex_create (_fmutex *, unsigned); 104 unsigned _fmutex_create2 (_fmutex *sem, unsigned, const char *); 86 105 unsigned _fmutex_open (_fmutex *); 87 106 unsigned _fmutex_close (_fmutex *); 88 107 void _fmutex_dummy (_fmutex *); 89 108 90 void _fmutex_checked_close (_fmutex *); 91 void _fmutex_checked_create (_fmutex *, unsigned); 92 void _fmutex_checked_open (_fmutex *); 109 void _fmutex_checked_close(_fmutex *); 110 void _fmutex_checked_create(_fmutex *, unsigned); 111 void _fmutex_checked_create2(_fmutex *, unsigned, const char *); 112 void _fmutex_checked_open(_fmutex *); 113 void _fmutex_abort(_fmutex *, const char *); 93 114 94 115 static __inline__ void _fmutex_checked_release (_fmutex * sem) 95 116 { 96 if (_fmutex_release (sem) != 0) 97 abort (); 117 if (sem->Owner != fibGetTidPid()) 118 _fmutex_abort(sem, "release not owner"); 119 if (_fmutex_release (sem) != 0) 120 _fmutex_abort(sem, "release"); 98 121 } 99 122 100 123 static __inline__ void _fmutex_checked_request (_fmutex * sem, unsigned flags) 101 124 { 102 if (_fmutex_request (sem, flags) != 0)103 abort ();125 if (_fmutex_request (sem, flags) != 0) 126 _fmutex_abort(sem, "request"); 104 127 } 105 128 106 #if defined (__cplusplus) 107 } 108 #endif 129 __END_DECLS 109 130 110 131 #endif /* not _SYS_FMUTEX_H */ 132 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.