sensor-framework : Initial commit
[platform/core/system/sensord.git] / src / shared / crw_lock.cpp
1 /*
2  * libsensord-share
3  *
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include "crw_lock.h"
21 #include "common.h"
22
23 crw_lock::crw_lock()
24 {
25         m_rw_lock = PTHREAD_RWLOCK_INITIALIZER;
26 }
27
28 crw_lock::~crw_lock()
29 {
30         pthread_rwlock_destroy(&m_rw_lock);
31 }
32
33 void crw_lock::read_lock()
34 {
35         cbase_lock::lock(LOCK_TYPE_READ, "read lock", __MODULE__, __func__, __LINE__);
36 }
37
38 void crw_lock::write_lock()
39 {
40         cbase_lock::lock(LOCK_TYPE_WRITE, "write lock", __MODULE__, __func__, __LINE__);
41 }
42
43 int crw_lock::read_lock_impl(void)
44 {
45         return pthread_rwlock_rdlock(&m_rw_lock);
46 }
47 int crw_lock::write_lock_impl(void)
48 {
49         return pthread_rwlock_wrlock(&m_rw_lock);
50 }
51
52 int crw_lock::try_read_lock_impl(void)
53 {
54         return pthread_rwlock_tryrdlock(&m_rw_lock);
55 }
56
57 int crw_lock::try_write_lock_impl(void)
58 {
59         return pthread_rwlock_trywrlock(&m_rw_lock);
60 }
61
62 int crw_lock::unlock_impl()
63 {
64         return pthread_rwlock_unlock(&m_rw_lock);
65 }