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 - named semaphores |
30 | =============================================================================*/ |
31 | |
32 | #ifndef VCOS_GENERIC_NAMED_SEM_H |
33 | #define VCOS_GENERIC_NAMED_SEM_H |
34 | |
35 | #ifdef __cplusplus |
36 | extern "C" { |
37 | #endif |
38 | |
39 | #include "interface/vcos/vcos_types.h" |
40 | |
41 | /** |
42 | * \file |
43 | * |
44 | * Generic support for named semaphores, using regular ones. This is only |
45 | * suitable for emulating them on an embedded MMUless system, since there is |
46 | * no support for opening semaphores across process boundaries. |
47 | * |
48 | */ |
49 | |
50 | #define VCOS_NAMED_SEMAPHORE_NAMELEN 64 |
51 | |
52 | /* In theory we could use the name facility provided within Nucleus. However, this |
53 | * is hard to do as semaphores are constantly being created and destroyed; we |
54 | * would need to stop everything while allocating the memory for the semaphore |
55 | * list and then walking it. So keep our own list. |
56 | */ |
57 | typedef struct VCOS_NAMED_SEMAPHORE_T |
58 | { |
59 | struct VCOS_NAMED_SEMAPHORE_IMPL_T *actual; /**< There are 'n' named semaphores per 1 actual semaphore */ |
60 | VCOS_SEMAPHORE_T *sem; /**< Pointer to actual underlying semaphore */ |
61 | } VCOS_NAMED_SEMAPHORE_T; |
62 | |
63 | VCOSPRE_ VCOS_STATUS_T VCOSPOST_ |
64 | vcos_generic_named_semaphore_create(VCOS_NAMED_SEMAPHORE_T *sem, const char *name, VCOS_UNSIGNED count); |
65 | |
66 | VCOSPRE_ void VCOSPOST_ vcos_named_semaphore_delete(VCOS_NAMED_SEMAPHORE_T *sem); |
67 | |
68 | VCOSPRE_ VCOS_STATUS_T VCOSPOST_ _vcos_named_semaphore_init(void); |
69 | VCOSPRE_ void VCOSPOST_ _vcos_named_semaphore_deinit(void); |
70 | |
71 | #if defined(VCOS_INLINE_BODIES) |
72 | |
73 | VCOS_INLINE_IMPL |
74 | VCOS_STATUS_T vcos_named_semaphore_create(VCOS_NAMED_SEMAPHORE_T *sem, const char *name, VCOS_UNSIGNED count) { |
75 | return vcos_generic_named_semaphore_create(sem, name, count); |
76 | } |
77 | |
78 | VCOS_INLINE_IMPL |
79 | void vcos_named_semaphore_wait(VCOS_NAMED_SEMAPHORE_T *sem) { |
80 | vcos_semaphore_wait(sem->sem); |
81 | } |
82 | |
83 | VCOS_INLINE_IMPL |
84 | VCOS_STATUS_T vcos_named_semaphore_trywait(VCOS_NAMED_SEMAPHORE_T *sem) { |
85 | return vcos_semaphore_trywait(sem->sem); |
86 | } |
87 | |
88 | VCOS_INLINE_IMPL |
89 | void vcos_named_semaphore_post(VCOS_NAMED_SEMAPHORE_T *sem) { |
90 | vcos_semaphore_post(sem->sem); |
91 | } |
92 | |
93 | |
94 | #endif |
95 | |
96 | #ifdef __cplusplus |
97 | } |
98 | #endif |
99 | #endif |
100 | |
101 | |
102 | |