2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FBaseRtThreadSemaphore.cpp
20 * @brief This is the implementation file for the Semaphore class.
26 #include <FBaseRtSemaphore.h>
28 #include "FBase_NativeError.h"
29 #include <FBaseSysLog.h>
30 #include "FBaseRt_SemaphoreImpl.h"
33 namespace Tizen { namespace Base { namespace Runtime
36 Semaphore::Semaphore(void)
37 : __pSemaphoreImpl(null)
42 Semaphore::~Semaphore(void)
44 delete __pSemaphoreImpl;
45 __pSemaphoreImpl = null;
49 Semaphore::Create(int count)
51 return Create(L"", count);
55 Semaphore::Create(const String& name, int count)
57 // Object is not allowed to construct twice
58 SysAssertf(__pSemaphoreImpl == null,
59 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
61 SysTryReturnResult(NID_BASE_RT, count >= 0, E_INVALID_ARG, "The count(%d) MUST be greater than or equal to 0.", count);
63 __pSemaphoreImpl = new (std::nothrow) _SemaphoreImpl;
64 SysTryReturnResult(NID_BASE_RT, __pSemaphoreImpl != null, E_OUT_OF_MEMORY, "Not enough memory.");
66 result r = __pSemaphoreImpl->Create(name, count);
69 delete __pSemaphoreImpl;
70 __pSemaphoreImpl = null;
77 Semaphore::Acquire(long timeout)
79 SysAssertf(__pSemaphoreImpl != null, "Not yet constructed! Construct() should be called before use.");
80 return __pSemaphoreImpl->Acquire(timeout);
84 Semaphore::TryToAcquire(void)
86 SysAssertf(__pSemaphoreImpl != null, "Not yet constructed! Construct() should be called before use.");
87 return __pSemaphoreImpl->TryToAcquire();
91 Semaphore::Release(void)
93 SysAssertf(__pSemaphoreImpl != null, "Not yet constructed! Construct() should be called before use.");
94 return __pSemaphoreImpl->Release();
97 } } } // Tizen::Runtime