4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #ifndef _CBASE_LOCK_H_
21 #define _CBASE_LOCK_H_
32 #define AUTOLOCK(x) Autolock x##_autolock((x),LOCK_TYPE_MUTEX, #x, __MODULE__, __func__, __LINE__)
33 #define AUTOLOCK_R(x) Autolock x##_autolock_r((x),LOCK_TYPE_READ, #x, __MODULE__, __func__, __LINE__)
34 #define AUTOLOCK_W(x) Autolock x##_autolock_w((x),LOCK_TYPE_WRITE, #x, __MODULE__, __func__, __LINE__)
35 #define LOCK(x) (x).lock(#x, __MODULE__, __func__, __LINE__)
36 #define LOCK_R(x) (x).lock(LOCK_TYPE_READ, #x, __MODULE__, __func__, __LINE__)
37 #define LOCK_W(x) (x).lock(LOCK_TYPE_WRITE, #x, __MODULE__, __func__, __LINE__)
38 #define UNLOCK(x) (x).unlock()
40 #define AUTOLOCK(x) Autolock x##_autolock((x),LOCK_TYPE_MUTEX)
41 #define AUTOLOCK_R(x) Autolock x##_autolock_r((x),LOCK_TYPE_READ)
42 #define AUTOLOCK_W(x) Autolock x##_autolock_w((x),LOCK_TYPE_WRITE)
43 #define LOCK(x) (x).lock()
44 #define LOCK_R(x) (x).lock(LOCK_TYPE_READ)
45 #define LOCK_W(x) (x).lock(LOCK_TYPE_WRITE)
46 #define UNLOCK(x) (x).unlock()
53 virtual ~cbase_lock();
55 void lock(lock_type type, const char* expr, const char *module, const char *func, int line);
56 void lock(lock_type type);
60 virtual int lock_impl(void);
61 virtual int read_lock_impl(void);
62 virtual int write_lock_impl(void);
64 virtual int try_lock_impl(void);
65 virtual int try_read_lock_impl(void);
66 virtual int try_write_lock_impl(void);
68 virtual int unlock_impl(void);
70 pthread_mutex_t m_history_mutex;
71 static const int OWNER_INFO_LEN = 256;
72 char m_owner_info[OWNER_INFO_LEN];
79 Autolock(cbase_lock &m, lock_type type, const char* expr, const char *module, const char *func, int line);
80 Autolock(cbase_lock &m, lock_type type);
84 #endif /* _CBASE_LOCK_H_ */