client-cpp  0.10.0
KaaThread.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2016 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 #ifdef _WIN32
52 typedef std::atomic<bool> bool_type;
53 #else
54 typedef std::atomic_bool bool_type;
55 #endif
56 typedef std::atomic_int_fast32_t RequestId;
57 
58 #define kaa_thread_local thread_local
59 
60 #if 0
61 
62 #define KAA_MUTEX
63 #define KAA_R_MUTEX
64 
65 #define KAA_MUTEX_UNIQUE
66 #define KAA_R_MUTEX_UNIQUE
67 
68 #define KAA_LOCK(mtx)
69 #define KAA_UNLOCK(mtx)
70 
71 #define KAA_CONDITION_VARIABLE
72 #define KAA_CONDITION_WAIT(cond, lck)
73 #define KAA_CONDITION_WAIT_PRED(cond, lck, pred)
74 #define KAA_CONDITION_NOTIFY(cond)
75 #define KAA_CONDITION_NOTIFY_ALL(cond)
76 
77 #define KAA_CONDITION_VARIABLE_DECLARE(name)
78 #define KAA_MUTEX_DECLARE(name)
79 #define KAA_MUTEX_MUTABLE_DECLARE(name)
80 #define KAA_R_MUTEX_DECLARE(name)
81 #define KAA_R_MUTEX_MUTABLE_DECLARE(name)
82 #define KAA_MUTEX_UNIQUE_DECLARE(name, mtx)
83 #define KAA_R_MUTEX_UNIQUE_DECLARE(name, mtx)
84 
85 typedef bool bool_type;
86 typedef std::int32_t RequestId;
87 
88 #define kaa_thread_local
89 
90 #endif
91 
92 
93 #endif /* KAA_KAATHREAD_HPP_ */
std::atomic_bool bool_type
Definition: KaaThread.hpp:54
std::atomic_int_fast32_t RequestId
Definition: KaaThread.hpp:56