sync with tizen_2.0
[platform/framework/native/appfw.git] / src / base / runtime / FBaseRt_MonitorImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file        FBaseRt_MonitorImpl.cpp
20  * @brief       This is the implementation file for the _MonitorImpl class.
21  *
22  */
23
24 #include <FBaseSysLog.h>
25 #include "FBaseRt_MonitorImpl.h"
26
27 namespace Tizen { namespace Base { namespace Runtime
28 {
29
30 _MonitorImpl::_MonitorImpl(void)
31         : __initialized(false)
32 {
33
34 }
35
36 _MonitorImpl::~_MonitorImpl(void)
37 {
38         if (__initialized)
39         {
40                 pthread_cond_destroy(&__cond);
41                 pthread_mutex_destroy(&__lock);
42         }
43 }
44
45 result
46 _MonitorImpl::Construct(void)
47 {
48         int ret = 0;
49
50         ret = pthread_mutex_init(&__lock, null);
51         SysTryReturnResult(NID_BASE_RT, ret == 0, E_SYSTEM, "[E_SYSTEM] System error has occurred.");
52
53         ret = pthread_cond_init(&__cond, null);
54         SysTryReturnResult(NID_BASE_RT, ret == 0, E_SYSTEM, "[E_SYSTEM] System error has occurred.");
55
56         __initialized = true;
57
58         return E_SUCCESS;
59 }
60
61 result
62 _MonitorImpl::Enter(void)
63 {
64         int ret = 0;
65
66         ret = pthread_mutex_lock(&__lock);
67         SysTryReturnResult(NID_BASE_RT, ret == 0, E_SYSTEM, "[E_SYSTEM] System error has occurred.");
68
69         return E_SUCCESS;
70 }
71
72 result
73 _MonitorImpl::Exit(void)
74 {
75         int ret = 0;
76
77         ret = pthread_mutex_unlock(&__lock);
78         SysTryReturnResult(NID_BASE_RT, ret == 0, E_SYSTEM, "[E_SYSTEM] System error has occurred.");
79
80         return E_SUCCESS;
81 }
82
83 result
84 _MonitorImpl::Wait(void)
85 {
86         int ret = 0;
87
88         ret = pthread_cond_wait(&__cond, &__lock);
89         SysTryReturnResult(NID_BASE_RT, ret == 0, E_SYSTEM, "[E_SYSTEM] System error has occurred.");
90
91         return E_SUCCESS;
92 }
93
94 result
95 _MonitorImpl::Notify(void)
96 {
97         int ret = 0;
98
99         ret = pthread_cond_signal(&__cond);
100         SysTryReturnResult(NID_BASE_RT, ret == 0, E_SYSTEM, "[E_SYSTEM] System error has occured.");
101
102         return E_SUCCESS;
103 }
104
105 result
106 _MonitorImpl::NotifyAll(void)
107 {
108         int ret = 0;
109
110         ret = pthread_cond_broadcast(&__cond);
111         SysTryReturnResult(NID_BASE_RT, ret == 0, E_SYSTEM, "[E_SYSTEM] System error has occurred.");
112
113         return E_SUCCESS;
114 }
115
116 } } } // Tizen::Runtime