Support rastport clipping rectangle for layerless rastports
[tangerine.git] / rom / exec / attemptsemaphoreshared.c
blobc4c2bfd66cb4906c7e5f8a70d31e552d94e762a5
1 /*
2 Copyright © 1995-2001, 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
53 AROS_LIBBASE_EXT_DECL(struct ExecBase *,SysBase)
55 struct Task *me = FindTask(NULL);
56 ULONG retval = TRUE;
58 #if CHECK_INITSEM
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);
64 #endif
66 /* Protect the semaphore structure */
67 Forbid();
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++;
83 else
85 /* We can't get ownership, just return it. */
86 sigSem->ss_QueueCount--;
87 retval = FALSE;
90 /* All done. */
91 Permit();
93 return retval;
95 AROS_LIBFUNC_EXIT
96 } /* AttemptSemaphoreShared */