Remove build warnings and fixed svace issues
[platform/adaptation/ap_samsung/libomxil-e3250-v4l2.git] / openmax / osal / Exynos_OSAL_Mutex.c
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@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
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 Exynos_OSAL_MutexUnlock(OMX_HANDLETYPE mutexHandle)
80 {
81     pthread_mutex_t *mutex = (pthread_mutex_t *)mutexHandle;
82
83     if (mutex == NULL)
84         return OMX_ErrorBadParameter;
85
86     if (pthread_mutex_unlock(mutex) != 0)
87         return OMX_ErrorUndefined;
88
89     return OMX_ErrorNone;
90 }