2 * Copyright@ Samsung Electronics Co. LTD
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * \file ExynosMutex.cpp
19 * \brief source file for ExynosMutex
20 * \author Sangwoo, Park(sw5771.park@samsung.com)
23 * <b>Revision History: </b>
24 * - 2010/06/15 : Sangwoo, Park(sw5771.park@samsung.com) \n
29 //#define LOG_NDEBUG 0
30 #define LOG_TAG "ExynosMutex"
31 #include <utils/Log.h>
33 #include <utils/threads.h>
34 using namespace android
;
41 #include "ExynosMutex.h"
43 //#define EXYNOS_MUTEX_DEBUG
45 ExynosMutex::ExynosMutex()
52 ExynosMutex::~ExynosMutex()
54 if (m_flagCreate
== true)
58 bool ExynosMutex::create(int type
, char* name
)
60 if (m_flagCreate
== true) {
61 ALOGE("%s::Already created", __func__
);
65 int androidMutexType
= 0;
71 androidMutexType
= Mutex::PRIVATE
;
74 androidMutexType
= Mutex::SHARED
;
77 ALOGE("%s::unmatched type(%d) fail", __func__
, type
);
81 m_mutex
= new Mutex(androidMutexType
, name
);
82 if (m_mutex
== NULL
) {
83 ALOGE("%s::Mutex create fail", __func__
);
95 void ExynosMutex::destroy(void)
97 if (m_flagCreate
== false) {
98 ALOGE("%s::Not yet created", __func__
);
103 delete ((Mutex
*)m_mutex
);
106 m_flagCreate
= false;
109 bool ExynosMutex::getCreatedStatus(void)
114 bool ExynosMutex::lock(void)
116 if (m_flagCreate
== false) {
117 ALOGE("%s::Not yet created", __func__
);
121 #ifdef EXYNOS_MUTEX_DEBUG
122 ALOGD("%s::%s'lock() start", __func__
, m_name
);
125 if (((Mutex
*)m_mutex
)->lock() != 0) {
126 ALOGE("%s::m_core->lock() fail", __func__
);
130 #ifdef EXYNOS_MUTEX_DEBUG
131 ALOGD("%s::%s'lock() end", __func__
, m_name
);
137 bool ExynosMutex::unLock(void)
139 if (m_flagCreate
== false) {
140 ALOGE("%s::Not yet created", __func__
);
144 #ifdef EXYNOS_MUTEX_DEBUG
145 ALOGD("%s::%s'unlock() start", __func__
, m_name
);
148 ((Mutex
*)m_mutex
)->unlock();
150 #ifdef EXYNOS_MUTEX_DEBUG
151 ALOGD("%s::%s'unlock() end", __func__
, m_name
);
157 bool ExynosMutex::tryLock(void)
159 if (m_flagCreate
== false) {
160 ALOGE("%s::Not yet created", __func__
);
166 #ifdef EXYNOS_MUTEX_DEBUG
167 ALOGD("%s::%s'trylock() start", __func__
, m_name
);
170 ret
= ((Mutex
*)m_mutex
)->tryLock();
172 #ifdef EXYNOS_MUTEX_DEBUG
173 ALOGD("%s::%s'trylock() end", __func__
, m_name
);
176 return (ret
== 0) ? true : false;
179 int ExynosMutex::getType(void)
184 void *exynos_mutex_create(
188 ExynosMutex
*mutex
= new ExynosMutex();
190 if (mutex
->create(type
, name
) == false) {
191 ALOGE("%s::mutex->create() fail", __func__
);
199 bool exynos_mutex_destroy(
202 if (handle
== NULL
) {
203 ALOGE("%s::handle is null", __func__
);
207 if (((ExynosMutex
*)handle
)->getCreatedStatus() == true)
208 ((ExynosMutex
*)handle
)->destroy();
210 delete (ExynosMutex
*)handle
;
215 bool exynos_mutex_lock(
218 if (handle
== NULL
) {
219 ALOGE("%s::handle is null", __func__
);
223 return ((ExynosMutex
*)handle
)->lock();
227 bool exynos_mutex_unlock(
230 if (handle
== NULL
) {
231 ALOGE("%s::handle is null", __func__
);
235 return ((ExynosMutex
*)handle
)->unLock();
239 bool exynos_mutex_trylock(
242 if (handle
== NULL
) {
243 ALOGE("%s::handle is null", __func__
);
247 return ((ExynosMutex
*)handle
)->tryLock();
251 int exynos_mutex_get_type(
254 if (handle
== NULL
) {
255 ALOGE("%s::handle is null", __func__
);
259 return ((ExynosMutex
*)handle
)->getType();
262 bool exynos_mutex_get_created_status(
265 if (handle
== NULL
) {
266 ALOGE("%s::handle is null", __func__
);
270 return ((ExynosMutex
*)handle
)->getCreatedStatus();