@@ -149,22 +149,20 @@ SprintfA( char *dst, const char *fmt, IPTR* args )
149
149
** mode, thus the implementation below which is "almost" the same as Exec's
150
150
******************************************************************************/
151
151
152
+ /******************************************************************************
153
+ ** AxRT has SMP support enable which requires an extended implementation of
154
+ ** #?Semaphore functions, meaning AHI-specific semaphore code does not
155
+ ** guarantee serialization.
156
+ ******************************************************************************/
157
+
152
158
/******************************************************************************
153
159
** AHIInitSemaphore ***********************************************************
154
160
******************************************************************************/
155
161
156
162
void
157
163
AHIInitSemaphore ( struct SignalSemaphore * sigSem )
158
164
{
159
- // TODO: Verify license compatibility (Code mostly stolen from AROS).
160
-
161
- sigSem -> ss_WaitQueue .mlh_Head = (struct MinNode * )& sigSem -> ss_WaitQueue .mlh_Tail ;
162
- sigSem -> ss_WaitQueue .mlh_Tail = NULL ;
163
- sigSem -> ss_WaitQueue .mlh_TailPred = (struct MinNode * )& sigSem -> ss_WaitQueue .mlh_Head ;
164
- sigSem -> ss_Link .ln_Type = NT_SIGNALSEM ;
165
- sigSem -> ss_NestCount = 0 ;
166
- sigSem -> ss_Owner = 0 ;
167
- sigSem -> ss_QueueCount = -1 ;
165
+ InitSemaphore ( sigSem );
168
166
}
169
167
170
168
@@ -175,31 +173,7 @@ AHIInitSemaphore( struct SignalSemaphore* sigSem )
175
173
void
176
174
AHIObtainSemaphore ( struct SignalSemaphore * sigSem )
177
175
{
178
- // TODO: Verify license compatibility (Code mostly stolen from AROS).
179
-
180
- struct Task * me ;
181
-
182
- Disable (); // Not Forbid()!
183
- me = FindTask (NULL );
184
- sigSem -> ss_QueueCount ++ ;
185
- if ( sigSem -> ss_QueueCount == 0 )
186
- {
187
- sigSem -> ss_Owner = me ;
188
- sigSem -> ss_NestCount ++ ;
189
- }
190
- else if ( sigSem -> ss_Owner == me )
191
- {
192
- sigSem -> ss_NestCount ++ ;
193
- }
194
- else
195
- {
196
- struct SemaphoreRequest sr ;
197
- sr .sr_Waiter = me ;
198
- me -> tc_SigRecvd &= ~SIGF_SINGLE ;
199
- AddTail ((struct List * )& sigSem -> ss_WaitQueue , (struct Node * )& sr );
200
- Wait (SIGF_SINGLE );
201
- }
202
- Enable ();
176
+ ObtainSemaphore ( sigSem );
203
177
}
204
178
205
179
@@ -210,51 +184,7 @@ AHIObtainSemaphore( struct SignalSemaphore* sigSem )
210
184
void
211
185
AHIReleaseSemaphore ( struct SignalSemaphore * sigSem )
212
186
{
213
- // TODO: Verify license compatibility (Code mostly stolen from AROS).
214
-
215
- Disable (); // Not Forbid()!
216
-
217
- sigSem -> ss_NestCount -- ;
218
- sigSem -> ss_QueueCount -- ;
219
- if (sigSem -> ss_NestCount == 0 )
220
- {
221
- if ( sigSem -> ss_QueueCount >= 0
222
- && sigSem -> ss_WaitQueue .mlh_Head -> mln_Succ != NULL )
223
- {
224
- struct SemaphoreRequest * sr ;
225
- struct SemaphoreMessage * sm ;
226
- sr = (struct SemaphoreRequest * )sigSem -> ss_WaitQueue .mlh_Head ;
227
-
228
- // Note that shared semaphores are not supported!
229
-
230
- sm = (struct SemaphoreMessage * )sr ;
231
-
232
- Remove ((struct Node * )sr );
233
- sigSem -> ss_NestCount ++ ;
234
- if (sr -> sr_Waiter != NULL )
235
- {
236
- sigSem -> ss_Owner = sr -> sr_Waiter ;
237
- Signal (sr -> sr_Waiter , SIGF_SINGLE );
238
- }
239
- else
240
- {
241
- sigSem -> ss_Owner = (struct Task * )sm -> ssm_Semaphore ;
242
- sm -> ssm_Semaphore = sigSem ;
243
- ReplyMsg ((struct Message * )sr );
244
- }
245
- }
246
- else
247
- {
248
- sigSem -> ss_Owner = NULL ;
249
- sigSem -> ss_QueueCount = -1 ;
250
- }
251
- }
252
- else if (sigSem -> ss_NestCount < 0 )
253
- {
254
- Alert ( AN_SemCorrupt );
255
- }
256
-
257
- Enable ();
187
+ ReleaseSemaphore ( sigSem );
258
188
}
259
189
260
190
@@ -265,27 +195,7 @@ AHIReleaseSemaphore( struct SignalSemaphore* sigSem )
265
195
LONG
266
196
AHIAttemptSemaphore ( struct SignalSemaphore * sigSem )
267
197
{
268
- // TODO: Verify license compatibility (Code mostly stolen from AROS).
269
-
270
- LONG rc = FALSE;
271
-
272
- Disable (); // Not Forbid()!
273
-
274
- sigSem -> ss_QueueCount ++ ;
275
- if ( sigSem -> ss_QueueCount == 0 )
276
- {
277
- sigSem -> ss_Owner = (APTR ) ~0 ;
278
- sigSem -> ss_NestCount ++ ;
279
- rc = TRUE;
280
- }
281
- else
282
- {
283
- sigSem -> ss_QueueCount -- ;
284
- }
285
-
286
- Enable ();
287
-
288
- return rc ;
198
+ return AttemptSemaphore ( sigSem );
289
199
}
290
200
291
201
0 commit comments