2 Copyright © 1995-2007, 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 *****************************************************************************/
54 struct Task
*me
= FindTask(NULL
);
58 if (sigSem
->ss_Link
.ln_Type
!= NT_SIGNALSEM
)
60 kprintf("\n\nAttemptSemaphoreShared called on an unintialized semaphore!!! "
61 "sem = %x task = %x (%s)\n\n", sigSem
, me
, me
->tc_Node
.ln_Name
);
65 /* Protect the semaphore structure */
68 /* Increment the queue count. This will need SMP protection */
69 sigSem
->ss_QueueCount
++;
71 if( sigSem
->ss_QueueCount
== 0 )
73 /* The semaphore wasn't owned. We can now own it */
74 sigSem
->ss_Owner
= NULL
;
75 sigSem
->ss_NestCount
++;
77 else if( ( sigSem
->ss_Owner
== me
) || ( sigSem
->ss_Owner
== NULL
) )
79 /* The semaphore was owned by me or is shared, just increase the nest count */
80 sigSem
->ss_NestCount
++;
84 /* We can't get ownership, just return it. */
85 sigSem
->ss_QueueCount
--;
95 } /* AttemptSemaphoreShared */