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