Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / thread / trylockmutex.c
bloba826841b1a86b657e58a55127eb08e910ef7328a
1 /*
2 * thread.library - threading and synchronisation primitives
4 * Copyright © 2007 Robert Norris
6 * This program is free software; you can redistribute it and/or modify it
7 * under the same terms as AROS itself.
8 */
10 #include "thread_intern.h"
12 #include <exec/semaphores.h>
13 #include <proto/exec.h>
14 #include <assert.h>
16 /*****************************************************************************
18 NAME */
19 AROS_LH1(BOOL, TryLockMutex,
21 /* SYNOPSIS */
22 AROS_LHA(void *, mutex, A0),
24 /* LOCATION */
25 struct ThreadBase *, ThreadBase, 13, Thread)
27 /* FUNCTION
28 Tries to lock a mutex. If the lock is already held, this function
29 fails.
31 INPUTS
32 mutex - mutex to lock.
34 RESULT
35 TRUE if the lock was acquired, FALSE if the lock is already held.
37 NOTES
39 EXAMPLE
40 TryLockMutex(mutex);
42 BUGS
44 SEE ALSO
45 CreateMutex(), DestroyMutex(), LockMutex(), UnlockMutex()
47 INTERNALS
48 Mutexes are implemented as thin wrappers around Exec semaphores.
49 *****************************************************************************/
51 AROS_LIBFUNC_INIT
53 assert(mutex != NULL);
55 return (BOOL) AttemptSemaphore((struct SignalSemaphore *) mutex);
57 AROS_LIBFUNC_EXIT
58 } /* TryLockMutex */