1 /* 2 * 3 * Copyright 2010 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 SEC_OSAL_Mutex.c 20 * @brief 21 * @author SeungBeom Kim (sbcrux.kim (at) samsung.com) 22 * @version 1.0 23 * @history 24 * 2010.7.15 : Create 25 */ 26 27 #include <stdio.h> 28 #include <stdlib.h> 29 #include <string.h> 30 #include <pthread.h> 31 32 #include "SEC_OSAL_Memory.h" 33 #include "SEC_OSAL_Mutex.h" 34 35 36 OMX_ERRORTYPE SEC_OSAL_MutexCreate(OMX_HANDLETYPE *mutexHandle) 37 { 38 pthread_mutex_t *mutex; 39 40 mutex = (pthread_mutex_t *)SEC_OSAL_Malloc(sizeof(pthread_mutex_t)); 41 if (!mutex) 42 return OMX_ErrorInsufficientResources; 43 44 if (pthread_mutex_init(mutex, NULL) != 0) 45 return OMX_ErrorUndefined; 46 47 *mutexHandle = (OMX_HANDLETYPE)mutex; 48 return OMX_ErrorNone; 49 } 50 51 OMX_ERRORTYPE SEC_OSAL_MutexTerminate(OMX_HANDLETYPE mutexHandle) 52 { 53 pthread_mutex_t *mutex = (pthread_mutex_t *)mutexHandle; 54 55 if (mutex == NULL) 56 return OMX_ErrorBadParameter; 57 58 if (pthread_mutex_destroy(mutex) != 0) 59 return OMX_ErrorUndefined; 60 61 SEC_OSAL_Free(mutex); 62 return OMX_ErrorNone; 63 } 64 65 OMX_ERRORTYPE SEC_OSAL_MutexLock(OMX_HANDLETYPE mutexHandle) 66 { 67 pthread_mutex_t *mutex = (pthread_mutex_t *)mutexHandle; 68 int result; 69 70 if (mutex == NULL) 71 return OMX_ErrorBadParameter; 72 73 if (pthread_mutex_lock(mutex) != 0) 74 return OMX_ErrorUndefined; 75 76 return OMX_ErrorNone; 77 } 78 79 OMX_ERRORTYPE SEC_OSAL_MutexUnlock(OMX_HANDLETYPE mutexHandle) 80 { 81 pthread_mutex_t *mutex = (pthread_mutex_t *)mutexHandle; 82 int result; 83 84 if (mutex == NULL) 85 return OMX_ErrorBadParameter; 86 87 if (pthread_mutex_unlock(mutex) != 0) 88 return OMX_ErrorUndefined; 89 90 return OMX_ErrorNone; 91 } 92