Skip to content

Commit fcb28da

Browse files
author
deadwood
committed
[NP] Use Exec's semaphore functions
See comment in code on why this is required.
1 parent a60a2a8 commit fcb28da

File tree

1 file changed

+10
-100
lines changed
  • workbench/devs/AHI/Device

1 file changed

+10
-100
lines changed

workbench/devs/AHI/Device/misc.c

Lines changed: 10 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -149,22 +149,20 @@ SprintfA( char *dst, const char *fmt, IPTR* args )
149149
** mode, thus the implementation below which is "almost" the same as Exec's
150150
******************************************************************************/
151151

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+
152158
/******************************************************************************
153159
** AHIInitSemaphore ***********************************************************
154160
******************************************************************************/
155161

156162
void
157163
AHIInitSemaphore( struct SignalSemaphore* sigSem )
158164
{
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 );
168166
}
169167

170168

@@ -175,31 +173,7 @@ AHIInitSemaphore( struct SignalSemaphore* sigSem )
175173
void
176174
AHIObtainSemaphore( struct SignalSemaphore* sigSem )
177175
{
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 );
203177
}
204178

205179

@@ -210,51 +184,7 @@ AHIObtainSemaphore( struct SignalSemaphore* sigSem )
210184
void
211185
AHIReleaseSemaphore( struct SignalSemaphore* sigSem )
212186
{
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 );
258188
}
259189

260190

@@ -265,27 +195,7 @@ AHIReleaseSemaphore( struct SignalSemaphore* sigSem )
265195
LONG
266196
AHIAttemptSemaphore( struct SignalSemaphore* sigSem )
267197
{
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 );
289199
}
290200

291201

0 commit comments

Comments
 (0)