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 FBaseRt_MutexImpl.h
19 * @brief This is the implementation file for the _MutexImpl class.
23 #ifndef _FTHREAD_INTERNAL_MUTEX_IMPL_H_
24 #define _FTHREAD_INTERNAL_MUTEX_IMPL_H_
27 #include <FBaseResult.h>
28 #include <FBaseString.h>
31 namespace Tizen { namespace Base { namespace Runtime
36 * @brief This class represents a mutex; one type of synchronization mechanism.
38 * It is a binary semaphore. Only one thread can acquire the Mutex.
43 * using namespace Tizen::Base;
44 * using namespace Tizen::Base::Runtime;
53 * __pMutex->Release();
59 * @see Semaphore, Thread
63 : public Tizen::Base::Object
67 * This is the default constructor for this class.
70 * @remarks After creating an instance of this class, you must explicitly call one of
71 * the Create() methods to initialize the instance.
76 * This is the destructor for this class.
80 virtual ~_MutexImpl(void);
83 * Creates an unnamed Mutex.
86 * @return An error code
87 * @exception E_SUCCESS The method was successful.
88 * @exception E_SYSTEM An unknown operating system error occurred.
93 * Creates a non-recursive mutex.
96 * @return An error code
97 * @exception E_SUCCESS The method was successful.
98 * @exception E_SYSTEM An unknown operating system error occurred.
100 result CreateNonRecursiveMutex(void);
103 * Creates a named Mutex. @n
104 * If there is already a Mutex with the specified name, this creates a Mutex which references that particular Mutex.
107 * @return An error code
108 * @param[in] name The name of the Mutex
109 * @exception E_SUCCESS The method was successful.
110 * @exception E_SYSTEM An unknown operating system error occurred.
112 result Create(const Tizen::Base::String& name);
115 * Acquires the Mutex if it is not acquired. @n
116 * If the Mutex is already acquired by another thread,
117 * the current thread is blocked until the Mutex is released.
120 * @return An error code
121 * @param[in] timeout The period during which the thread tries to acquire the mutex
122 * @exception E_SUCCESS The method was successful.
123 * @exception E_TIMEOUT The operation could not be completed within the specified time period. @n
124 * @exception E_SYSTEM An unknown operating system error occurred. @n
125 * Failed to acquire the Mutex because an OS failure occurred.
127 result Acquire(long timeout);
130 * Releases the Mutex.
133 * @return An error code
134 * @exception E_SUCCESS The method was successful.
135 * @exception E_SYSTEM An unknown operating system error occurred. @n
136 * Failed to acquire the Mutex because an OS failure occurred.
138 result Release(void);
141 * Acquires the Mutex if it is not acquired. @n
142 * If the Mutex is already acquired by another thread,
143 * the current thread is blocked until the Mutex is released.
146 * @return An error code
147 * @exception E_SUCCESS The method was successful.
148 * @exception E_SYSTEM An unknown operating system error occurred. @n
149 * Failed to acquire the Mutex because an OS failure occurred.
151 result Acquire(void);
154 * Acquires the mutex if it is not acquired. @n
155 * If the mutex is already acquired by another thread, E_OBJECT_LOCKED is returned.
159 * @return An error code
160 * @exception E_SUCCESS The method is successful.
161 * @exception E_OBJECT_LOCKED The mutex is already locked.
162 * @exception E_INVALID_STATE The mutex has not been initialized as yet.
163 * @exception E_SYSTEM A system error has occurred.
165 result TryToAcquire(void);
168 pthread_mutex_t* __pMutex;
169 Tizen::Base::String __name;
175 } } } // Tizen::Runtime