2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Try to lock a semaphore shared.
8 #include "exec_intern.h"
9 #include "semaphores.h"
10 #include <exec/semaphores.h>
11 #include <proto/exec.h>
13 #define CHECK_INITSEM 1
15 /*****************************************************************************
19 AROS_LH1(ULONG
, AttemptSemaphoreShared
,
22 AROS_LHA(struct SignalSemaphore
*, sigSem
, A0
),
25 struct ExecBase
*, SysBase
, 120, Exec
)
28 Tries to get a shared lock on a signal semaphore. If the lock cannot
29 be obtained false is returned. There may be more than one shared lock
30 at a time but an exclusive lock prevents all other locks. The lock
31 must be released with ReleaseSemaphore().
34 sigSem - pointer to semaphore structure
37 True if the semaphore could be obtained, false otherwise.
50 *****************************************************************************/
53 AROS_LIBBASE_EXT_DECL(struct ExecBase
*,SysBase
)
55 struct Task
*me
= FindTask(NULL
);
59 if (sigSem
->ss_Link
.ln_Type
!= NT_SIGNALSEM
)
61 kprintf("\n\nAttemptSemaphoreShared called on an unintialized semaphore!!! "
62 "sem = %x task = %x (%s)\n\n", sigSem
, me
, me
->tc_Node
.ln_Name
);
66 /* Protect the semaphore structure */
69 /* Increment the queue count. This will need SMP protection */
70 sigSem
->ss_QueueCount
++;
72 if( sigSem
->ss_QueueCount
== 0 )
74 /* The semaphore wasn't owned. We can now own it */
75 sigSem
->ss_Owner
= NULL
;
76 sigSem
->ss_NestCount
++;
78 else if( ( sigSem
->ss_Owner
== me
) || ( sigSem
->ss_Owner
== NULL
) )
80 /* The semaphore was owned by me or is shared, just increase the nest count */
81 sigSem
->ss_NestCount
++;
85 /* We can't get ownership, just return it. */
86 sigSem
->ss_QueueCount
--;
96 } /* AttemptSemaphoreShared */