client-cpp  0.6.1
KaaThread.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014 CyberVision, Inc.
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 #ifndef KAA_KAATHREAD_HPP_
18 #define KAA_KAATHREAD_HPP_
19 
20 #include "kaa/KaaDefaults.hpp"
21 
22 #ifdef KAA_THREADSAFE
23 
24 #include <mutex>
25 #include <atomic>
26 #include <condition_variable>
27 
28 #define KAA_MUTEX std::mutex
29 #define KAA_R_MUTEX std::recursive_mutex
30 
31 #define KAA_MUTEX_UNIQUE std::unique_lock<KAA_MUTEX>
32 #define KAA_R_MUTEX_UNIQUE std::unique_lock<KAA_R_MUTEX>
33 
34 #define KAA_LOCK(mtx) mtx.lock()
35 #define KAA_UNLOCK(mtx) mtx.unlock()
36 
37 #define KAA_CONDITION_VARIABLE std::condition_variable
38 #define KAA_CONDITION_WAIT(cond, lck) cond.wait(lck)
39 #define KAA_CONDITION_WAIT_PRED(cond, lck, pred) cond.wait(lck, pred)
40 #define KAA_CONDITION_NOTIFY(cond) cond.notify_one()
41 #define KAA_CONDITION_NOTIFY_ALL(cond) cond.notify_all()
42 
43 #define KAA_CONDITION_VARIABLE_DECLARE(name) KAA_CONDITION_VARIABLE name
44 #define KAA_MUTEX_DECLARE(name) KAA_MUTEX name
45 #define KAA_MUTEX_MUTABLE_DECLARE(name) mutable KAA_MUTEX_DECLARE(name)
46 #define KAA_R_MUTEX_DECLARE(name) KAA_R_MUTEX name
47 #define KAA_R_MUTEX_MUTABLE_DECLARE(name) mutable KAA_R_MUTEX_DECLARE(name)
48 #define KAA_MUTEX_UNIQUE_DECLARE(name, mtx) KAA_MUTEX_UNIQUE name(mtx)
49 #define KAA_R_MUTEX_UNIQUE_DECLARE(name, mtx) KAA_R_MUTEX_UNIQUE name(mtx)
50 
51 typedef std::atomic_bool bool_type;
52 
53 #else
54 
55 #define KAA_MUTEX
56 #define KAA_R_MUTEX
57 
58 #define KAA_MUTEX_UNIQUE
59 #define KAA_R_MUTEX_UNIQUE
60 
61 #define KAA_LOCK(mtx)
62 #define KAA_UNLOCK(mtx)
63 
64 #define KAA_CONDITION_VARIABLE
65 #define KAA_CONDITION_WAIT(cond, lck)
66 #define KAA_CONDITION_WAIT_PRED(cond, lck, pred)
67 #define KAA_CONDITION_NOTIFY(cond)
68 #define KAA_CONDITION_NOTIFY_ALL(cond)
69 
70 #define KAA_CONDITION_VARIABLE_DECLARE(name)
71 #define KAA_MUTEX_DECLARE(name)
72 #define KAA_MUTEX_MUTABLE_DECLARE(name)
73 #define KAA_R_MUTEX_DECLARE(name)
74 #define KAA_R_MUTEX_MUTABLE_DECLARE(name)
75 #define KAA_MUTEX_UNIQUE_DECLARE(name, mtx)
76 #define KAA_R_MUTEX_UNIQUE_DECLARE(name, mtx)
77 
78 typedef bool bool_type;
79 
80 #endif
81 
82 
83 #endif /* KAA_KAATHREAD_HPP_ */
bool bool_type
Definition: KaaThread.hpp:78