2 * @file IxOsalOsSemaphore.c (eCos)
4 * @brief Implementation for semaphore and mutex.
8 * IXP400 SW Release version 1.5
10 * -- Copyright Notice --
13 * Copyright 2001-2005, Intel Corporation.
14 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 * 3. Neither the name of the Intel Corporation nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
31 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 * -- End of Copyright Notice --
47 #include "IxNpeMhReceive_p.h"
49 /* Define a large number */
50 #define IX_OSAL_MAX_LONG (0x7FFFFFFF)
52 /* Max timeout in MS, used to guard against possible overflow */
53 #define IX_OSAL_MAX_TIMEOUT_MS (IX_OSAL_MAX_LONG/HZ)
57 ixOsalSemaphoreInit (IxOsalSemaphore * sid, UINT32 start_value)
59 diag_printf("%s called\n", __FUNCTION__);
64 * DESCRIPTION: If the semaphore is 'empty', the calling thread is blocked.
65 * If the semaphore is 'full', it is taken and control is returned
66 * to the caller. If the time indicated in 'timeout' is reached,
67 * the thread will unblock and return an error indication. If the
68 * timeout is set to 'IX_OSAL_WAIT_NONE', the thread will never block;
69 * if it is set to 'IX_OSAL_WAIT_FOREVER', the thread will block until
70 * the semaphore is available.
77 ixOsalSemaphoreWait (IxOsalOsSemaphore * sid, INT32 timeout)
79 diag_printf("%s called\n", __FUNCTION__);
84 * Attempt to get semaphore, return immediately,
85 * no error info because users expect some failures
86 * when using this API.
89 ixOsalSemaphoreTryWait (IxOsalSemaphore * sid)
91 diag_printf("%s called\n", __FUNCTION__);
97 * DESCRIPTION: This function causes the next available thread in the pend queue
98 * to be unblocked. If no thread is pending on this semaphore, the
99 * semaphore becomes 'full'.
102 ixOsalSemaphorePost (IxOsalSemaphore * sid)
104 diag_printf("%s called\n", __FUNCTION__);
109 ixOsalSemaphoreGetValue (IxOsalSemaphore * sid, UINT32 * value)
111 diag_printf("%s called\n", __FUNCTION__);
116 ixOsalSemaphoreDestroy (IxOsalSemaphore * sid)
118 diag_printf("%s called\n", __FUNCTION__);
122 /****************************
124 ****************************/
126 static void drv_mutex_init(IxOsalMutex *mutex)
131 static void drv_mutex_destroy(IxOsalMutex *mutex)
136 static int drv_mutex_trylock(IxOsalMutex *mutex)
146 static void drv_mutex_unlock(IxOsalMutex *mutex)
149 printf("Trying to unlock unlocked mutex!");
155 ixOsalMutexInit (IxOsalMutex * mutex)
157 drv_mutex_init(mutex);
162 ixOsalMutexLock (IxOsalMutex * mutex, INT32 timeout)
166 if (timeout == IX_OSAL_WAIT_NONE) {
167 if (drv_mutex_trylock(mutex))
173 tries = (timeout * 1000) / 50;
175 if (drv_mutex_trylock(mutex))
177 if (timeout != IX_OSAL_WAIT_FOREVER && tries-- <= 0)
185 ixOsalMutexUnlock (IxOsalMutex * mutex)
187 drv_mutex_unlock(mutex);
192 * Attempt to get mutex, return immediately,
193 * no error info because users expect some failures
194 * when using this API.
197 ixOsalMutexTryLock (IxOsalMutex * mutex)
199 if (drv_mutex_trylock(mutex))
205 ixOsalMutexDestroy (IxOsalMutex * mutex)
207 drv_mutex_destroy(mutex);
212 ixOsalFastMutexInit (IxOsalFastMutex * mutex)
214 return ixOsalMutexInit(mutex);
217 PUBLIC IX_STATUS ixOsalFastMutexTryLock(IxOsalFastMutex *mutex)
219 return ixOsalMutexTryLock(mutex);
224 ixOsalFastMutexUnlock (IxOsalFastMutex * mutex)
226 return ixOsalMutexUnlock(mutex);
230 ixOsalFastMutexDestroy (IxOsalFastMutex * mutex)
232 return ixOsalMutexDestroy(mutex);