3 * Copyright 2012 Samsung Electronics S.LSI Co. LTD
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 * @file Exynos_OSAL_Semaphore.c
21 * @author SeungBeom Kim (sbcrux.kim@samsung.com)
31 #include <semaphore.h>
33 #include "Exynos_OSAL_Memory.h"
34 #include "Exynos_OSAL_Semaphore.h"
37 #define EXYNOS_LOG_TAG "EXYNOS_LOG_SEMA"
38 #define EXYNOS_LOG_OFF
39 #include "Exynos_OSAL_Log.h"
42 OMX_ERRORTYPE Exynos_OSAL_SemaphoreCreate(OMX_HANDLETYPE *semaphoreHandle)
46 sema = (sem_t *)Exynos_OSAL_Malloc(sizeof(sem_t));
48 return OMX_ErrorInsufficientResources;
50 if (sem_init(sema, 0, 0) != 0) {
51 Exynos_OSAL_Free(sema);
52 return OMX_ErrorUndefined;
55 *semaphoreHandle = (OMX_HANDLETYPE)sema;
59 OMX_ERRORTYPE Exynos_OSAL_SemaphoreTerminate(OMX_HANDLETYPE semaphoreHandle)
61 sem_t *sema = (sem_t *)semaphoreHandle;
64 return OMX_ErrorBadParameter;
66 if (sem_destroy(sema) != 0)
67 return OMX_ErrorUndefined;
69 Exynos_OSAL_Free(sema);
73 OMX_ERRORTYPE Exynos_OSAL_SemaphoreWait(OMX_HANDLETYPE semaphoreHandle)
75 sem_t *sema = (sem_t *)semaphoreHandle;
80 return OMX_ErrorBadParameter;
82 if (sem_wait(sema) != 0)
83 return OMX_ErrorUndefined;
90 OMX_ERRORTYPE Exynos_OSAL_SemaphoreTryWait(OMX_HANDLETYPE semaphoreHandle)
92 sem_t *sema = (sem_t *)semaphoreHandle;
97 return OMX_ErrorBadParameter;
99 if (sem_trywait(sema) != 0)
100 return OMX_ErrorUndefined;
104 return OMX_ErrorNone;
107 OMX_ERRORTYPE Exynos_OSAL_SemaphorePost(OMX_HANDLETYPE semaphoreHandle)
109 sem_t *sema = (sem_t *)semaphoreHandle;
114 return OMX_ErrorBadParameter;
116 if (sem_post(sema) != 0)
117 return OMX_ErrorUndefined;
121 return OMX_ErrorNone;
124 OMX_ERRORTYPE Exynos_OSAL_Set_SemaphoreCount(OMX_HANDLETYPE semaphoreHandle, OMX_S32 val)
126 sem_t *sema = (sem_t *)semaphoreHandle;
129 return OMX_ErrorBadParameter;
131 if (sem_init(sema, 0, val) != 0)
132 return OMX_ErrorUndefined;
134 return OMX_ErrorNone;
137 OMX_ERRORTYPE Exynos_OSAL_Get_SemaphoreCount(OMX_HANDLETYPE semaphoreHandle, OMX_S32 *val)
139 sem_t *sema = (sem_t *)semaphoreHandle;
143 return OMX_ErrorBadParameter;
145 if (sem_getvalue(sema, &semaVal) != 0)
146 return OMX_ErrorUndefined;
148 *val = (OMX_S32)semaVal;
150 return OMX_ErrorNone;