Fix the boiler plate codes
[platform/framework/native/appfw.git] / src / base / runtime / FBaseRt_MonitorImpl.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file        FBaseRt_MonitorImpl.h
19  * @brief       This is the header file for the %_Monitor class.
20  *
21  * This file contains the declarations of the %_Monitor class.
22  */
23
24 #ifndef _FBASE_RT_INTERNAL_MONITOR_IMPL_H_
25 #define _FBASE_RT_INTERNAL_MONITOR_IMPL_H_
26
27 #include <pthread.h>
28
29 #include <FBaseResult.h>
30 #include <FBaseObject.h>
31
32
33 namespace Tizen { namespace Base { namespace Runtime
34 {
35
36 /**
37  * @class   _MonitorImpl
38  * @brief       This is one of the synchronization mechanisms. It not only provides acquire/release semantics
39  *  (by Enter/Exit), but also wait/notify semantics (by Wait/Notify/NotifyAll).
40  * @since 2.0
41  *
42  */
43
44 class _MonitorImpl
45         : public Tizen::Base::Object
46 {
47 public:
48         /**
49          * This is the default constructor for this class.
50          *
51          * @since 2.0
52          * @remarks     After creating an instance of this class, you must explicitly call one of the
53          *          Construct() methods to initialize the instance.
54          */
55         _MonitorImpl(void);
56
57
58         /**
59          * This is the destructor for this class.
60          *
61          * @since 2.0
62          */
63         ~_MonitorImpl(void);
64
65
66         /**
67          * Creates the monitor instance.
68          *
69          * @since 2.0
70          * @return              An error code
71          * @exception   E_SUCCESS       The method was successful.
72          * @exception   E_SYSTEM                An unknown operating system error occurred.
73          */
74         result Construct(void);
75
76 public:
77         /**
78          * Acquires a lock for a monitor. @n
79          * Semantically, this method declares the beginning of the critical region for a monitor. This region is
80          * ended with the Exit() method.
81          *
82          * @since 2.0
83          * @return              An error code
84          * @exception   E_SUCCESS       The method was successful. @n
85          *                                                      It was successful in acquiring the lock.
86          * @see                 Exit()
87          */
88         result Enter(void);
89
90
91         /**
92          * Releases a lock for a monitor. @n
93          * Semantically, it declares the ending of the critical region for the monitor which begins by
94          * the Enter() method.
95          *
96          * @since 2.0
97          * @return              An error code
98          * @exception   E_SUCCESS       The method was successful. @n
99          *                                                      It was successful in releasing the lock.
100          * @exception   E_INVALID_STATE The current thread has not entered the monitor.
101          * @see                 Enter()
102          */
103         result Exit(void);
104
105         /**
106          * Releases the lock for the monitor and waits for the other thread's notification. @n
107          * After receiving the notification, it tries to acquire the lock. @n
108          * Semantically, it waits until the other thread notifies it.
109          *
110          * @since 2.0
111          * @return              An error code
112          * @exception   E_SUCCESS       The method was successful.
113          * @see                 Notify(), NotifyAll()
114          */
115         result Wait(void);
116
117         /**
118          * Notifies one of the waiting threads. @n
119          * The selection of the notified thread is dependent on the underlying OS.
120          *
121          * @since 2.0
122          * @return              An error code
123          * @exception   E_SUCCESS       The method was successful.
124          * @see                 NotifyAll(), Wait()
125          */
126         result Notify(void);
127
128
129         /**
130          * Notifies all waiting threads.
131          *
132          * @since 2.0
133          * @return              An error code
134          * @exception   E_SUCCESS       The method was successful.
135          * @see                 Notify(), Wait()
136          */
137         result NotifyAll(void);
138
139 private:
140         bool __initialized;
141         pthread_mutex_t __lock;
142         pthread_cond_t __cond;
143
144 }; // _MonitorImpl
145
146 } } } // Tizen::Base::Runtime
147
148 #endif // _FBASE_RT_INTERNAL_MONITOR_IMPL_H_