| 1 | /* |
| 2 | Copyright (c) 2012, Broadcom Europe Ltd |
| 3 | All rights reserved. |
| 4 | |
| 5 | Redistribution and use in source and binary forms, with or without |
| 6 | modification, are permitted provided that the following conditions are met: |
| 7 | * Redistributions of source code must retain the above copyright |
| 8 | notice, this list of conditions and the following disclaimer. |
| 9 | * Redistributions in binary form must reproduce the above copyright |
| 10 | notice, this list of conditions and the following disclaimer in the |
| 11 | documentation and/or other materials provided with the distribution. |
| 12 | * Neither the name of the copyright holder nor the |
| 13 | names of its contributors may be used to endorse or promote products |
| 14 | derived from this software without specific prior written permission. |
| 15 | |
| 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
| 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | /*============================================================================= |
| 29 | VideoCore OS Abstraction Layer - mutex public header file |
| 30 | =============================================================================*/ |
| 31 | |
| 32 | #ifndef VCOS_MUTEX_H |
| 33 | #define VCOS_MUTEX_H |
| 34 | |
| 35 | #ifdef __cplusplus |
| 36 | extern "C" { |
| 37 | #endif |
| 38 | |
| 39 | #include "interface/vcos/vcos_types.h" |
| 40 | #include "vcos.h" |
| 41 | |
| 42 | /** |
| 43 | * \file vcos_mutex.h |
| 44 | * |
| 45 | * Mutex API. Mutexes are not re-entrant, as supporting this adds extra code |
| 46 | * that slows down clients which have been written sensibly. |
| 47 | * |
| 48 | * \sa vcos_reentrant_mutex.h |
| 49 | * |
| 50 | */ |
| 51 | |
| 52 | /** Create a mutex. |
| 53 | * |
| 54 | * @param m Filled in with mutex on return |
| 55 | * @param name A non-null name for the mutex, used for diagnostics. |
| 56 | * |
| 57 | * @return VCOS_SUCCESS if mutex was created, or error code. |
| 58 | */ |
| 59 | VCOS_INLINE_DECL |
| 60 | VCOS_STATUS_T vcos_mutex_create(VCOS_MUTEX_T *m, const char *name); |
| 61 | |
| 62 | /** Delete the mutex. |
| 63 | */ |
| 64 | VCOS_INLINE_DECL |
| 65 | void vcos_mutex_delete(VCOS_MUTEX_T *m); |
| 66 | |
| 67 | /** |
| 68 | * \brief Wait to claim the mutex. |
| 69 | * |
| 70 | * On most platforms this always returns VCOS_SUCCESS, and so would ideally be |
| 71 | * a void function, however some platforms allow a wait to be interrupted so |
| 72 | * it remains non-void. |
| 73 | * |
| 74 | * Try to obtain the mutex. |
| 75 | * @param m Mutex to wait on |
| 76 | * @return VCOS_SUCCESS - mutex was taken. |
| 77 | * VCOS_EAGAIN - could not take mutex. |
| 78 | */ |
| 79 | #ifndef vcos_mutex_lock |
| 80 | VCOS_INLINE_DECL |
| 81 | VCOS_STATUS_T vcos_mutex_lock(VCOS_MUTEX_T *m); |
| 82 | |
| 83 | /** Release the mutex. |
| 84 | */ |
| 85 | VCOS_INLINE_DECL |
| 86 | void vcos_mutex_unlock(VCOS_MUTEX_T *m); |
| 87 | #endif |
| 88 | |
| 89 | /** Test if the mutex is already locked. |
| 90 | * |
| 91 | * @return 1 if mutex is locked, 0 if it is unlocked. |
| 92 | */ |
| 93 | VCOS_INLINE_DECL |
| 94 | int vcos_mutex_is_locked(VCOS_MUTEX_T *m); |
| 95 | |
| 96 | /** Obtain the mutex if possible. |
| 97 | * |
| 98 | * @param m the mutex to try to obtain |
| 99 | * |
| 100 | * @return VCOS_SUCCESS if mutex is successfully obtained, or VCOS_EAGAIN |
| 101 | * if it is already in use by another thread. |
| 102 | */ |
| 103 | #ifndef vcos_mutex_trylock |
| 104 | VCOS_INLINE_DECL |
| 105 | VCOS_STATUS_T vcos_mutex_trylock(VCOS_MUTEX_T *m); |
| 106 | #endif |
| 107 | |
| 108 | |
| 109 | #ifdef __cplusplus |
| 110 | } |
| 111 | #endif |
| 112 | #endif |
| 113 | |