revert between 56095 -> 55830 in arch
[AROS.git] / rom / exec / vacate.c
blob017ff9a749abcbbe3f80425437e5772ffb95358c
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Release a lock obtained with Procure().
6 Lang: english
7 */
8 #include <exec/lists.h>
9 #include <exec/semaphores.h>
10 #include <proto/exec.h>
11 #include "semaphores.h"
12 #include "exec_intern.h"
14 /*****************************************************************************
16 NAME */
18 AROS_LH2(void, Vacate,
20 /* SYNOPSIS */
21 AROS_LHA(struct SignalSemaphore *, sigSem, A0),
22 AROS_LHA(struct SemaphoreMessage *, bidMsg, A1),
24 /* LOCATION */
25 struct ExecBase *, SysBase, 91, Exec)
27 /* FUNCTION
28 Release a lock obtained with Procure. This will even work if the
29 message is not yet replied - the request will be cancelled and the
30 message replied. In any case the ssm_Semaphore field will be set to
31 NULL.
33 INPUTS
34 sigSem - Pointer to semaphore structure.
35 bidMsg - Pointer to struct SemaphoreMessage.
37 RESULT
39 NOTES
41 EXAMPLE
43 BUGS
45 SEE ALSO
46 Procure()
48 INTERNALS
50 *****************************************************************************/
52 AROS_LIBFUNC_INIT
54 struct SemaphoreRequest *sr = NULL;
56 /* Arbitrate for the semaphore structure */
57 Forbid();
58 bidMsg->ssm_Semaphore = NULL;
61 * Two cases, the request is in the list, which means it hasn't been
62 * granted, or the request is not in the list, in which case it has
63 * been granted. We need to check if the request is in the list.
65 ForeachNode(&sigSem->ss_WaitQueue, sr)
67 if (sr == (struct SemaphoreRequest *)bidMsg)
69 /* Found it. Remove it from the semaphore's waiting queue. */
70 Remove(&bidMsg->ssm_Message.mn_Node);
71 sigSem->ss_QueueCount--;
73 /* And reply the message. */
74 ReplyMsg(&bidMsg->ssm_Message);
76 /* All done */
77 Permit();
78 return;
82 /* No, it must have been fulfilled. Release the semaphore and done. */
83 ReleaseSemaphore(sigSem);
85 /* All done. */
86 Permit();
87 AROS_LIBFUNC_EXIT
88 } /* Vacate */