Corrected invalid characters.
[tangerine.git] / rom / exec / attemptsemaphoreshared.c
blob29f7d72540f44df022ee6ae49bdffd3343278357
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Try to lock a semaphore shared.
6 Lang: english
7 */
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 /*****************************************************************************
17 NAME */
19 AROS_LH1(ULONG, AttemptSemaphoreShared,
21 /* SYNOPSIS */
22 AROS_LHA(struct SignalSemaphore *, sigSem, A0),
24 /* LOCATION */
25 struct ExecBase *, SysBase, 120, Exec)
27 /* FUNCTION
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().
33 INPUTS
34 sigSem - pointer to semaphore structure
36 RESULT
37 True if the semaphore could be obtained, false otherwise.
39 NOTES
41 EXAMPLE
43 BUGS
45 SEE ALSO
46 ReleaseSemaphore()
48 INTERNALS
50 *****************************************************************************/
52 AROS_LIBFUNC_INIT
54 struct Task *me = FindTask(NULL);
55 ULONG retval = TRUE;
57 #if CHECK_INITSEM
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);
63 #endif
65 /* Protect the semaphore structure */
66 Forbid();
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++;
82 else
84 /* We can't get ownership, just return it. */
85 sigSem->ss_QueueCount--;
86 retval = FALSE;
89 /* All done. */
90 Permit();
92 return retval;
94 AROS_LIBFUNC_EXIT
95 } /* AttemptSemaphoreShared */