1 /* 2 * 3 * Copyright 2012 Samsung Electronics S.LSI Co. LTD 4 * 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 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 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. 16 */ 17 18 /* 19 * @file Exynos_OSAL_Mutex.c 20 * @brief 21 * @author SeungBeom Kim (sbcrux.kim (at) samsung.com) 22 * @version 2.0.0 23 * @history 24 * 2012.02.20 : Create 25 */ 26 27 #include <stdio.h> 28 #include <stdlib.h> 29 #include <string.h> 30 #include <pthread.h> 31 32 #include "Exynos_OSAL_Memory.h" 33 #include "Exynos_OSAL_Mutex.h" 34 35 OMX_ERRORTYPE Exynos_OSAL_MutexCreate(OMX_HANDLETYPE *mutexHandle) 36 { 37 pthread_mutex_t *mutex; 38 39 mutex = (pthread_mutex_t *)Exynos_OSAL_Malloc(sizeof(pthread_mutex_t)); 40 if (!mutex) 41 return OMX_ErrorInsufficientResources; 42 43 if (pthread_mutex_init(mutex, NULL) != 0) { 44 Exynos_OSAL_Free(mutex); 45 return OMX_ErrorUndefined; 46 } 47 48 *mutexHandle = (OMX_HANDLETYPE)mutex; 49 return OMX_ErrorNone; 50 } 51 52 OMX_ERRORTYPE Exynos_OSAL_MutexTerminate(OMX_HANDLETYPE mutexHandle) 53 { 54 pthread_mutex_t *mutex = (pthread_mutex_t *)mutexHandle; 55 56 if (mutex == NULL) 57 return OMX_ErrorBadParameter; 58 59 if (pthread_mutex_destroy(mutex) != 0) 60 return OMX_ErrorUndefined; 61 62 Exynos_OSAL_Free(mutex); 63 return OMX_ErrorNone; 64 } 65 66 OMX_ERRORTYPE Exynos_OSAL_MutexLock(OMX_HANDLETYPE mutexHandle) 67 { 68 pthread_mutex_t *mutex = (pthread_mutex_t *)mutexHandle; 69 int result; 70 71 if (mutex == NULL) 72 return OMX_ErrorBadParameter; 73 74 if (pthread_mutex_lock(mutex) != 0) 75 return OMX_ErrorUndefined; 76 77 return OMX_ErrorNone; 78 } 79 80 OMX_ERRORTYPE Exynos_OSAL_MutexUnlock(OMX_HANDLETYPE mutexHandle) 81 { 82 pthread_mutex_t *mutex = (pthread_mutex_t *)mutexHandle; 83 int result; 84 85 if (mutex == NULL) 86 return OMX_ErrorBadParameter; 87 88 if (pthread_mutex_unlock(mutex) != 0) 89 return OMX_ErrorUndefined; 90 91 return OMX_ErrorNone; 92 } 93