2 // Copyright (c) 2012 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 FBaseRtThreadMutex.cpp
19 * @brief This is the implementation file for the Mutex class.
25 #include <FBaseRtMutex.h>
27 #include "FBase_NativeError.h"
28 #include <FBaseSysLog.h>
29 #include "FBaseRt_MutexImpl.h"
32 namespace Tizen { namespace Base { namespace Runtime
54 Mutex::Create(NonRecursiveMutexTag)
56 // Object is not allowed to construct twice
57 SysAssertf(__pMutexImpl == null,
58 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
62 __pMutexImpl = new (std::nothrow) _MutexImpl;
63 SysTryReturnResult(NID_BASE_RT, __pMutexImpl != null, E_OUT_OF_MEMORY, "Not enough memory.");
65 r = __pMutexImpl->CreateNonRecursiveMutex();
66 SysTryCatch(NID_BASE_RT, !IsFailed(r), , r, "[%s] Mutex initialization failed.", GetErrorMessage(r));
80 Mutex::Create(const String& name)
82 // Object is not allowed to construct twice
83 SysAssertf(__pMutexImpl == null,
84 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
88 __pMutexImpl = new (std::nothrow) _MutexImpl;
89 SysTryReturnResult(NID_BASE_RT, __pMutexImpl != null, E_OUT_OF_MEMORY, "Not enough memory.");
91 r = __pMutexImpl->Create(name);
92 SysTryCatch(NID_BASE_RT, !IsFailed(r), , r, "[%s] Mutex initialization failed.", GetErrorMessage(r));
106 SysAssertf(__pMutexImpl != null, "Not yet constructed! Construct() should be called before use.");
107 return __pMutexImpl->Acquire();
111 Mutex::TryToAcquire(void)
113 SysAssertf(__pMutexImpl != null, "Not yet constructed! Construct() should be called before use.");
114 return __pMutexImpl->TryToAcquire();
120 SysAssertf(__pMutexImpl != null, "Not yet constructed! Construct() should be called before use.");
121 return __pMutexImpl->Release();
124 } } } // Tizen::Runtime