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 FBaseRtThreadSemaphore.cpp
19 * @brief This is the implementation file for the Semaphore class.
25 #include <FBaseRtSemaphore.h>
27 #include "FBase_NativeError.h"
28 #include <FBaseSysLog.h>
29 #include "FBaseRt_SemaphoreImpl.h"
32 namespace Tizen { namespace Base { namespace Runtime
35 Semaphore::Semaphore(void)
36 : __pSemaphoreImpl(null)
41 Semaphore::~Semaphore(void)
43 delete __pSemaphoreImpl;
44 __pSemaphoreImpl = null;
48 Semaphore::Create(int count)
50 return Create(L"", count);
54 Semaphore::Create(const String& name, int count)
56 // Object is not allowed to construct twice
57 SysAssertf(__pSemaphoreImpl == null,
58 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
60 SysTryReturnResult(NID_BASE_RT, count >= 0, E_INVALID_ARG, "The count(%d) MUST be greater than or equal to 0.", count);
62 __pSemaphoreImpl = new (std::nothrow) _SemaphoreImpl;
63 SysTryReturnResult(NID_BASE_RT, __pSemaphoreImpl != null, E_OUT_OF_MEMORY, "Not enough memory.");
65 result r = __pSemaphoreImpl->Create(name, count);
68 delete __pSemaphoreImpl;
69 __pSemaphoreImpl = null;
76 Semaphore::Acquire(long timeout)
78 SysAssertf(__pSemaphoreImpl != null, "Not yet constructed! Construct() should be called before use.");
79 return __pSemaphoreImpl->Acquire(timeout);
83 Semaphore::TryToAcquire(void)
85 SysAssertf(__pSemaphoreImpl != null, "Not yet constructed! Construct() should be called before use.");
86 return __pSemaphoreImpl->TryToAcquire();
90 Semaphore::Release(void)
92 SysAssertf(__pSemaphoreImpl != null, "Not yet constructed! Construct() should be called before use.");
93 return __pSemaphoreImpl->Release();
96 } } } // Tizen::Runtime