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 * SPDX-License-Identifier: BSD-3-Clause
19 * -- End of Copyright Notice --
23 #include "IxNpeMhReceive_p.h"
25 /* Define a large number */
26 #define IX_OSAL_MAX_LONG (0x7FFFFFFF)
28 /* Max timeout in MS, used to guard against possible overflow */
29 #define IX_OSAL_MAX_TIMEOUT_MS (IX_OSAL_MAX_LONG/HZ)
33 ixOsalSemaphoreInit (IxOsalSemaphore * sid, UINT32 start_value)
35 diag_printf("%s called\n", __FUNCTION__);
40 * DESCRIPTION: If the semaphore is 'empty', the calling thread is blocked.
41 * If the semaphore is 'full', it is taken and control is returned
42 * to the caller. If the time indicated in 'timeout' is reached,
43 * the thread will unblock and return an error indication. If the
44 * timeout is set to 'IX_OSAL_WAIT_NONE', the thread will never block;
45 * if it is set to 'IX_OSAL_WAIT_FOREVER', the thread will block until
46 * the semaphore is available.
53 ixOsalSemaphoreWait (IxOsalOsSemaphore * sid, INT32 timeout)
55 diag_printf("%s called\n", __FUNCTION__);
60 * Attempt to get semaphore, return immediately,
61 * no error info because users expect some failures
62 * when using this API.
65 ixOsalSemaphoreTryWait (IxOsalSemaphore * sid)
67 diag_printf("%s called\n", __FUNCTION__);
73 * DESCRIPTION: This function causes the next available thread in the pend queue
74 * to be unblocked. If no thread is pending on this semaphore, the
75 * semaphore becomes 'full'.
78 ixOsalSemaphorePost (IxOsalSemaphore * sid)
80 diag_printf("%s called\n", __FUNCTION__);
85 ixOsalSemaphoreGetValue (IxOsalSemaphore * sid, UINT32 * value)
87 diag_printf("%s called\n", __FUNCTION__);
92 ixOsalSemaphoreDestroy (IxOsalSemaphore * sid)
94 diag_printf("%s called\n", __FUNCTION__);
98 /****************************
100 ****************************/
102 static void drv_mutex_init(IxOsalMutex *mutex)
107 static void drv_mutex_destroy(IxOsalMutex *mutex)
112 static int drv_mutex_trylock(IxOsalMutex *mutex)
122 static void drv_mutex_unlock(IxOsalMutex *mutex)
125 printf("Trying to unlock unlocked mutex!");
131 ixOsalMutexInit (IxOsalMutex * mutex)
133 drv_mutex_init(mutex);
138 ixOsalMutexLock (IxOsalMutex * mutex, INT32 timeout)
142 if (timeout == IX_OSAL_WAIT_NONE) {
143 if (drv_mutex_trylock(mutex))
149 tries = (timeout * 1000) / 50;
151 if (drv_mutex_trylock(mutex))
153 if (timeout != IX_OSAL_WAIT_FOREVER && tries-- <= 0)
161 ixOsalMutexUnlock (IxOsalMutex * mutex)
163 drv_mutex_unlock(mutex);
168 * Attempt to get mutex, return immediately,
169 * no error info because users expect some failures
170 * when using this API.
173 ixOsalMutexTryLock (IxOsalMutex * mutex)
175 if (drv_mutex_trylock(mutex))
181 ixOsalMutexDestroy (IxOsalMutex * mutex)
183 drv_mutex_destroy(mutex);
188 ixOsalFastMutexInit (IxOsalFastMutex * mutex)
190 return ixOsalMutexInit(mutex);
193 PUBLIC IX_STATUS ixOsalFastMutexTryLock(IxOsalFastMutex *mutex)
195 return ixOsalMutexTryLock(mutex);
200 ixOsalFastMutexUnlock (IxOsalFastMutex * mutex)
202 return ixOsalMutexUnlock(mutex);
206 ixOsalFastMutexDestroy (IxOsalFastMutex * mutex)
208 return ixOsalMutexDestroy(mutex);