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(
49 int androidMutexType
= 0;
55 androidMutexType
= Mutex::PRIVATE
;
58 androidMutexType
= Mutex::SHARED
;
61 ALOGE("%s::unmatched type(%d) fail", __func__
, type
);
65 m_mutex
= new Mutex(androidMutexType
, name
);
66 if (m_mutex
== NULL
) {
67 ALOGE("%s::Mutex create fail", __func__
);
74 ExynosMutex::~ExynosMutex()
77 delete ((Mutex
*)m_mutex
);
81 bool ExynosMutex::lock(
84 #ifdef EXYNOS_MUTEX_DEBUG
85 ALOGD("%s::%s'lock() start", __func__
, m_name
);
88 if (m_mutex
== NULL
) {
89 ALOGE("%s::Mutex create fail", __func__
);
93 if (((Mutex
*)m_mutex
)->lock() != 0) {
94 ALOGE("%s::m_core->lock() fail", __func__
);
98 #ifdef EXYNOS_MUTEX_DEBUG
99 ALOGD("%s::%s'lock() end", __func__
, m_name
);
105 bool ExynosMutex::unLock(
108 #ifdef EXYNOS_MUTEX_DEBUG
109 ALOGD("%s::%s'unlock() start", __func__
, m_name
);
112 if (m_mutex
== NULL
) {
113 ALOGE("%s::Mutex create fail", __func__
);
117 ((Mutex
*)m_mutex
)->unlock();
119 #ifdef EXYNOS_MUTEX_DEBUG
120 ALOGD("%s::%s'unlock() end", __func__
, m_name
);
126 bool ExynosMutex::tryLock(
131 #ifdef EXYNOS_MUTEX_DEBUG
132 ALOGD("%s::%s'trylock() start", __func__
, m_name
);
135 if (m_mutex
== NULL
) {
136 ALOGE("%s::Mutex create fail", __func__
);
140 ret
= ((Mutex
*)m_mutex
)->tryLock();
142 #ifdef EXYNOS_MUTEX_DEBUG
143 ALOGD("%s::%s'trylock() end", __func__
, m_name
);
146 return (ret
== 0) ? true : false;
149 int ExynosMutex::getType(
155 int ExynosMutex::getCreatedStatus(
159 return STATUS_NOT_CREATED
;
161 return STATUS_CREATED
;
164 void *exynos_mutex_create(
168 ExynosMutex
*mutex
= new ExynosMutex(type
, name
);
173 bool exynos_mutex_destroy(
176 if (handle
== NULL
) {
177 ALOGE("%s::handle is null", __func__
);
181 delete (ExynosMutex
*)handle
;
186 bool exynos_mutex_lock(
189 if (handle
== NULL
) {
190 ALOGE("%s::handle is null", __func__
);
194 return ((ExynosMutex
*)handle
)->lock();
198 bool exynos_mutex_unlock(
201 if (handle
== NULL
) {
202 ALOGE("%s::handle is null", __func__
);
206 return ((ExynosMutex
*)handle
)->unLock();
210 bool exynos_mutex_trylock(
213 if (handle
== NULL
) {
214 ALOGE("%s::handle is null", __func__
);
218 return ((ExynosMutex
*)handle
)->tryLock();
222 int exynos_mutex_get_type(
225 if (handle
== NULL
) {
226 ALOGE("%s::handle is null", __func__
);
230 return ((ExynosMutex
*)handle
)->getType();
233 int exynos_mutex_get_created_status(
236 if (handle
== NULL
) {
237 ALOGE("%s::handle is null", __func__
);
241 return ((ExynosMutex
*)handle
)->getCreatedStatus();