1/*
2Copyright (c) 2012, Broadcom Europe Ltd
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, 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
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON 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
25SOFTWARE, 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
34typedef VCOS_STATUS_T KHR_STATUS_T;
35#define KHR_SUCCESS VCOS_SUCCESS
36#define KHR_EAGAIN VCOS_EAGAIN
37
38/*
39 mutex
40*/
41
42typedef VCOS_REENTRANT_MUTEX_T PLATFORM_MUTEX_T;
43
44/* return !VCOS_SUCCESS on failure */
45VCOS_STATIC_INLINE
46KHR_STATUS_T platform_mutex_create(PLATFORM_MUTEX_T *mutex) {
47 return vcos_reentrant_mutex_create(mutex, NULL);
48}
49
50VCOS_STATIC_INLINE
51void platform_mutex_destroy(PLATFORM_MUTEX_T *mutex) {
52 vcos_reentrant_mutex_delete(mutex);
53}
54
55VCOS_STATIC_INLINE
56void platform_mutex_acquire(PLATFORM_MUTEX_T *mutex) {
57 vcos_reentrant_mutex_lock(mutex);
58}
59
60VCOS_STATIC_INLINE
61void platform_mutex_release(PLATFORM_MUTEX_T *mutex) {
62 vcos_reentrant_mutex_unlock(mutex);
63}
64
65/*
66 named counting semaphore
67*/
68
69typedef VCOS_NAMED_SEMAPHORE_T PLATFORM_SEMAPHORE_T;
70
71/* return !VCOS_SUCCESS on failure */
72
73extern
74KHR_STATUS_T khronos_platform_semaphore_create(PLATFORM_SEMAPHORE_T *sem, int name[3], int count);
75
76VCOS_STATIC_INLINE
77void khronos_platform_semaphore_destroy(PLATFORM_SEMAPHORE_T *sem) {
78 vcos_named_semaphore_delete(sem);
79}
80
81VCOS_STATIC_INLINE
82void khronos_platform_semaphore_acquire(PLATFORM_SEMAPHORE_T *sem) {
83 vcos_named_semaphore_wait(sem);
84}
85
86VCOS_STATIC_INLINE
87KHR_STATUS_T khronos_platform_semaphore_try_acquire(PLATFORM_SEMAPHORE_T *sem) {
88 return vcos_named_semaphore_trywait(sem);
89}
90
91VCOS_STATIC_INLINE
92void khronos_platform_semaphore_release(PLATFORM_SEMAPHORE_T *sem) {
93 vcos_named_semaphore_post(sem);
94}
95
96/*
97 thread-local storage
98*/
99
100typedef VCOS_TLS_KEY_T PLATFORM_TLS_T;
101
102/* return !VCOS_SUCCCESS on failure */
103VCOS_STATIC_INLINE
104KHR_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
110extern 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 */
115extern void *platform_tls_get(PLATFORM_TLS_T tls);
116extern 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