2 * Copyright (C) 2001-2003 by NBMK Encryption Technologies.
5 * NBMK Encryption Technologies provides no support of any kind for
6 * this software. Questions or concerns about it may be addressed to
7 * the members of the relevant open-source community at
8 * <tech-crypto@netbsd.org>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer in the documentation and/or other materials provided
20 * with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 /*****************************************************************************
36 * @(#) n8_semaphore_bsd.c 1.2@(#)
37 *****************************************************************************/
39 /*****************************************************************************/
40 /** @file n8_semaphore_bsd.c
41 * @brief This file implements the n8 semaphore operations for BSD kernel
44 *****************************************************************************/
46 /*****************************************************************************
48 * 12/02/02 brr Added n8_delete_process_init_sem function.
49 * 06/12/02 hml Implemented the processSem ops. They are all empty for BSD.
50 * 03/18/02 brr Original version.
51 ****************************************************************************/
52 /** @defgroup n8_semaphore NetOctave Semaphore Operations
56 #include "n8_pub_errors.h"
57 #include "n8_semaphore.h"
59 static int initComplete
= FALSE
;
60 static ATOMICLOCK_t initProcessMutex_g
= SIMPLELOCK_INITIALIZER
;
62 /*****************************************************************************
63 * n8_acquire_process_init_sem
64 *****************************************************************************/
65 /** @ingroup n8_semaphore
66 * @brief Acquire the statically defined initilization semaphore.
68 * This function is the POSIX implementation of a function that grabs
69 * the statically allocated initialization semaphore. It turns out this
70 * is needed in order to prevent any race conditions on initialization.
73 * initProcessMutex_g RW: The global process initialization mutex.
82 *****************************************************************************/
84 n8_acquire_process_init_sem()
86 N8_AtomicLock(initProcessMutex_g
);
89 /*****************************************************************************
90 * n8_release_process_init_sem
91 *****************************************************************************/
92 /** @ingroup n8_semaphore
93 * @brief Release the statically defined initilization semaphore.
95 * This function is the POSIX implementation of a function that releases
96 * the statically allocated initialization semaphore. It turns out this
97 * is needed in order to prevent any race conditions on initialization.
100 * initProcessMutex_g RW: The global process initialization mutex.
109 *****************************************************************************/
111 n8_release_process_init_sem()
113 N8_AtomicUnlock(initProcessMutex_g
);
116 /*****************************************************************************
117 * n8_create_process_init_sem
118 *****************************************************************************/
119 /** @ingroup n8_semaphore
120 * @brief Creates the process initialization semaphore
122 * This function allocates a kernel semaphore,
130 * A text description of locks required by this routine and
131 * locks aquired by this routine. Optional if there are no locks.
134 * initVal is a sane number
135 *****************************************************************************/
138 n8_create_process_init_sem(void)
140 if (initComplete
== FALSE
)
142 N8_AtomicLockInit(initProcessMutex_g
);
147 /*****************************************************************************
148 * n8_delete_process_init_sem
149 *****************************************************************************/
150 /** @ingroup n8_semaphore
151 * @brief Deletes the process initialization semaphore
153 * This function deletes a kernel semaphore,
161 * A text description of locks required by this routine and
162 * locks aquired by this routine. Optional if there are no locks.
165 * initVal is a sane number
166 *****************************************************************************/
169 n8_delete_process_init_sem(void)
171 N8_AtomicLockDel(initProcessMutex_g
);
172 initComplete
= FALSE
;
175 /*****************************************************************************
176 * N8_acquireProcessSem
177 *****************************************************************************/
178 /** @ingroup n8_semaphore
179 * @brief Acquire a lock of type N8_Lock_t.
181 * This function is the kernel space implementation of a function that grabs
182 * a lock of type N8_Lock_t. Does nothing in BSD.
195 *****************************************************************************/
197 N8_acquireProcessSem(n8_Lock_t
*lock_p
)
201 /*****************************************************************************
202 * N8_releaseProcessSem
203 *****************************************************************************/
204 /** @ingroup n8_semaphore
205 * @brief Release a lock of type N8_Lock_t.
207 * This function is the kernel space implementation of a function that releases
208 * a lock of type N8_Lock_t. Does nothing in BSD.
221 *****************************************************************************/
223 N8_releaseProcessSem(n8_Lock_t
*lock_p
)
227 /*****************************************************************************
229 *****************************************************************************/
230 /** @ingroup n8_semaphore
231 * @brief Initialize a lock of type N8_Lock_t.
233 * This function is the kernel space implementation of a function that
234 * initializes a lock of type N8_Lock_t. Does nothing in BSD.
247 *****************************************************************************/
249 N8_initProcessSem(n8_Lock_t
*lock_p
)
253 /*****************************************************************************
254 * N8_deleteProcessSem
255 *****************************************************************************/
256 /** @ingroup n8_semaphore
257 * @brief Initialize a lock of type N8_Lock_t.
259 * This function is the kernel space implementation of a function that
260 * deletes a lock of type N8_Lock_t. Does nothing in BSD.
273 *****************************************************************************/
275 N8_deleteProcessSem(n8_Lock_t
*lock_p
)