1 /* Copyright (C) 2012-2020 IBM Corp.
2  * This program is Licensed under the Apache License, Version 2.0
3  * (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  *   http://www.apache.org/licenses/LICENSE-2.0
6  * Unless required by applicable law or agreed to in writing, software
7  * distributed under the License is distributed on an "AS IS" BASIS,
8  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9  * See the License for the specific language governing permissions and
10  * limitations under the License. See accompanying LICENSE file.
11  */
12 /**
13  * @file multicore.h
14  * @brief Support for multi-threaded implementations
15  **/
16 
17 #ifndef HELIB_MULTICORE_H
18 #define HELIB_MULTICORE_H
19 
20 #ifdef HELIB_THREADS
21 
22 #include <atomic>
23 #include <mutex>
24 
25 namespace helib {
26 
27 #define HELIB_atomic_long std::atomic_long
28 #define HELIB_atomic_ulong std::atomic_ulong
29 
30 #define HELIB_MUTEX_TYPE std::mutex
31 #define HELIB_MUTEX_GUARD(mx) std::lock_guard<std::mutex> _lock##__LINE__(mx)
32 
33 } // namespace helib
34 
35 #else
36 
37 namespace helib {
38 
39 #define HELIB_atomic_long long
40 #define HELIB_atomic_ulong unsigned long
41 
42 #define HELIB_MUTEX_TYPE int
43 #define HELIB_MUTEX_GUARD(mx) ((void)mx)
44 
45 } // namespace helib
46 
47 #endif // ifdef HELIB_THREADS
48 
49 #endif // ifndef HELIB_MULTICORE_H
50