| 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 | #ifndef KHRN_CLIENT_PLATFORM_FILLER_VCOS_H |
| 29 | #define KHRN_CLIENT_PLATFORM_FILLER_VCOS_H |
| 30 | |
| 31 | #include "interface/vcos/vcos.h" |
| 32 | #include "interface/vcos/vcos_reentrant_mutex.h" |
| 33 | |
| 34 | typedef VCOS_STATUS_T KHR_STATUS_T; |
| 35 | #define KHR_SUCCESS VCOS_SUCCESS |
| 36 | #define KHR_EAGAIN VCOS_EAGAIN |
| 37 | |
| 38 | /* |
| 39 | mutex |
| 40 | */ |
| 41 | |
| 42 | typedef VCOS_REENTRANT_MUTEX_T PLATFORM_MUTEX_T; |
| 43 | |
| 44 | /* return !VCOS_SUCCESS on failure */ |
| 45 | VCOS_STATIC_INLINE |
| 46 | KHR_STATUS_T platform_mutex_create(PLATFORM_MUTEX_T *mutex) { |
| 47 | return vcos_reentrant_mutex_create(mutex, NULL); |
| 48 | } |
| 49 | |
| 50 | VCOS_STATIC_INLINE |
| 51 | void platform_mutex_destroy(PLATFORM_MUTEX_T *mutex) { |
| 52 | vcos_reentrant_mutex_delete(mutex); |
| 53 | } |
| 54 | |
| 55 | VCOS_STATIC_INLINE |
| 56 | void platform_mutex_acquire(PLATFORM_MUTEX_T *mutex) { |
| 57 | vcos_reentrant_mutex_lock(mutex); |
| 58 | } |
| 59 | |
| 60 | VCOS_STATIC_INLINE |
| 61 | void platform_mutex_release(PLATFORM_MUTEX_T *mutex) { |
| 62 | vcos_reentrant_mutex_unlock(mutex); |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | named counting semaphore |
| 67 | */ |
| 68 | |
| 69 | typedef VCOS_NAMED_SEMAPHORE_T PLATFORM_SEMAPHORE_T; |
| 70 | |
| 71 | /* return !VCOS_SUCCESS on failure */ |
| 72 | |
| 73 | extern |
| 74 | KHR_STATUS_T khronos_platform_semaphore_create(PLATFORM_SEMAPHORE_T *sem, int name[3], int count); |
| 75 | |
| 76 | VCOS_STATIC_INLINE |
| 77 | void khronos_platform_semaphore_destroy(PLATFORM_SEMAPHORE_T *sem) { |
| 78 | vcos_named_semaphore_delete(sem); |
| 79 | } |
| 80 | |
| 81 | VCOS_STATIC_INLINE |
| 82 | void khronos_platform_semaphore_acquire(PLATFORM_SEMAPHORE_T *sem) { |
| 83 | vcos_named_semaphore_wait(sem); |
| 84 | } |
| 85 | |
| 86 | VCOS_STATIC_INLINE |
| 87 | KHR_STATUS_T khronos_platform_semaphore_try_acquire(PLATFORM_SEMAPHORE_T *sem) { |
| 88 | return vcos_named_semaphore_trywait(sem); |
| 89 | } |
| 90 | |
| 91 | VCOS_STATIC_INLINE |
| 92 | void khronos_platform_semaphore_release(PLATFORM_SEMAPHORE_T *sem) { |
| 93 | vcos_named_semaphore_post(sem); |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | thread-local storage |
| 98 | */ |
| 99 | |
| 100 | typedef VCOS_TLS_KEY_T PLATFORM_TLS_T; |
| 101 | |
| 102 | /* return !VCOS_SUCCCESS on failure */ |
| 103 | VCOS_STATIC_INLINE |
| 104 | KHR_STATUS_T platform_tls_create(VCOS_TLS_KEY_T *key) { |
| 105 | return vcos_tls_create(key); |
| 106 | } |
| 107 | |
| 108 | #define platform_tls_destroy(tls) vcos_tls_delete(tls) |
| 109 | |
| 110 | extern void platform_tls_remove(PLATFORM_TLS_T tls); |
| 111 | |
| 112 | /* This has to be per-platform because different platforms do |
| 113 | * thread attachment differently. |
| 114 | */ |
| 115 | extern void *platform_tls_get(PLATFORM_TLS_T tls); |
| 116 | extern void* platform_tls_get_check(PLATFORM_TLS_T tls); |
| 117 | |
| 118 | #define platform_tls_set(tls, v) vcos_tls_set(tls, v) |
| 119 | #define platform_tls_remove(tls) vcos_tls_set(tls,NULL) |
| 120 | |
| 121 | #endif |
| 122 | |
| 123 | |