comparison packages/kernel/current/include/mutex.hxx @ 115:6ed91473a1cd ecos-sw-2000-08-21

Merge from eCos master repository on 2000-08-21-22:40:54-BST
author jlarmour
date Fri, 25 Aug 2000 17:32:38 +0000
parents bf00f99aec69
children 4c750ce71ae3
comparison
equal deleted inserted replaced
114:5ad2b71d525e 115:6ed91473a1cd
57 57
58 class Cyg_Mutex 58 class Cyg_Mutex
59 { 59 {
60 friend class Cyg_Condition_Variable; 60 friend class Cyg_Condition_Variable;
61 61
62 cyg_atomic locked; // true if locked 62 cyg_atomic locked; // true if locked. This may seem
63 // redundant due to "owner" below,
64 // but is intentionally present for
65 // future SMP support.
63 66
64 Cyg_Thread *owner; // Current locking thread 67 Cyg_Thread *owner; // Current locking thread
65 68
66 Cyg_ThreadQueue queue; // Queue of waiting threads 69 Cyg_ThreadQueue queue; // Queue of waiting threads
70
71 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_DYNAMIC
72
73 public:
74 enum cyg_protcol
75 {
76 NONE = 0, // no inversion protocol
77 INHERIT, // priority inheritance protocol
78 CEILING // priority ceiling protocol
79 };
80
81 private:
82 cyg_protcol protocol; // this mutex's protocol
83
84 #endif
85
86 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_CEILING
87
88 private:
89 cyg_priority ceiling; // mutex priority ceiling
90
91 #endif
67 92
68 public: 93 public:
69 94
70 CYGDBG_DEFINE_CHECK_THIS 95 CYGDBG_DEFINE_CHECK_THIS
71 96
72 Cyg_Mutex(); // Create in unlocked state 97 Cyg_Mutex(); // Create in unlocked state
73 98
99 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_DYNAMIC
100
101 Cyg_Mutex( cyg_protcol protocol ); // Create with defined protocol
102
103 #endif
104
74 ~Cyg_Mutex(); // Destructor 105 ~Cyg_Mutex(); // Destructor
75 106
76 cyg_bool lock(); // lock and/or wait 107 cyg_bool lock(); // lock and/or wait
77 108
78 cyg_bool trylock(); // try to lock and return success 109 cyg_bool trylock(); // try to lock and return success
79 110
80 void unlock(); // unlock 111 void unlock(); // unlock
81 112
82 void release(); // release all waiting threads 113 void release(); // release all waiting threads
114
115 // Get the current owning thread
116 inline Cyg_Thread *get_owner() { return owner; }
117
118 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_CEILING
119
120 // set ceiling priority for priority ceiling protocol
121 void set_ceiling( cyg_priority priority );
122
123 cyg_priority get_ceiling(void) { return ceiling; };
124
125 #endif
83 126
84 }; 127 };
85 128
86 // ------------------------------------------------------------------------- 129 // -------------------------------------------------------------------------
87 // Condition variable. 130 // Condition variable.
89 class Cyg_Condition_Variable 132 class Cyg_Condition_Variable
90 { 133 {
91 Cyg_Mutex *mutex; // Associated mutex 134 Cyg_Mutex *mutex; // Associated mutex
92 135
93 Cyg_ThreadQueue queue; // Queue of waiting threads 136 Cyg_ThreadQueue queue; // Queue of waiting threads
137
138 // Private internal implementation function for wait operations
139 cyg_bool wait_inner( Cyg_Mutex *mutex );
140
141 #ifdef CYGMFN_KERNEL_SYNCH_CONDVAR_TIMED_WAIT
142
143 // Private internal implementation function for timed wait operations
144 cyg_bool wait_inner( Cyg_Mutex *mutex, cyg_tick_count timeout );
145
146 #endif
94 147
95 public: 148 public:
96 149
97 CYGDBG_DEFINE_CHECK_THIS 150 CYGDBG_DEFINE_CHECK_THIS
151
152 Cyg_Condition_Variable(); // simple constructor
98 153
99 Cyg_Condition_Variable( 154 Cyg_Condition_Variable(
100 Cyg_Mutex &mutex // linked mutex 155 Cyg_Mutex &mutex // linked mutex
101 ); 156 );
102 157
103 ~Cyg_Condition_Variable(); // Destructor 158 ~Cyg_Condition_Variable(); // Destructor
104 159
105 void wait(); // Wait for condition to be true
106 160
107 void signal(); // Set cond true, wake one thread 161 void signal(); // Set cond true, wake one thread
108 162
109 void broadcast(); // Set cond true, wake all threads 163 void broadcast(); // Set cond true, wake all threads
110 164
165 // Wait for condition to be true
166 inline cyg_bool wait() { return wait_inner( mutex ); }
167
111 #ifdef CYGMFN_KERNEL_SYNCH_CONDVAR_TIMED_WAIT 168 #ifdef CYGMFN_KERNEL_SYNCH_CONDVAR_TIMED_WAIT
112 169
113 // Wait until a signal or timeout expiry 170 // Wait until a signal or timeout expiry
114 cyg_bool wait( cyg_tick_count timeout ); 171 inline cyg_bool wait( cyg_tick_count timeout )
115 172 { return wait_inner( mutex, timeout ); }
116 #endif 173
174 #endif
175
176 #ifdef CYGMFN_KERNEL_SYNCH_CONDVAR_WAIT_MUTEX
177
178 // Wait for condition to be true using the supplied mutex
179 inline cyg_bool wait( Cyg_Mutex &mx ) { return wait_inner( &mx ); }
180
181
182 #ifdef CYGMFN_KERNEL_SYNCH_CONDVAR_TIMED_WAIT
183
184 // Wait until a signal or timeout expiry, using the supplied mutex
185 inline cyg_bool wait( Cyg_Mutex &mx, cyg_tick_count timeout )
186 { return wait_inner( &mx, timeout ); }
187
188 #endif
189 #endif
190
191 // Return a pointer to this variables thread queue. Used mainly
192 // for testing whether a thread is on the queue for a particular
193 // cv.
194 inline Cyg_ThreadQueue *get_queue() { return &queue; };
117 195
118 }; 196 };
119 197
120 198
121 // ------------------------------------------------------------------------- 199 // -------------------------------------------------------------------------