SPH
CheckFunction.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "common/Globals.h"
10 #include <atomic>
11 
13 
14 enum class CheckFunction {
15  NON_REENRANT = 1 << 0,
16  MAIN_THREAD = 1 << 1,
17  NOT_MAIN_THREAD = 1 << 2,
18  ONCE = 1 << 3,
19  NO_THROW = 1 << 4,
20 };
21 
23  std::atomic<Size>& reentrantCnt;
25 
26 public:
27  FunctionChecker(std::atomic<Size>& reentrantCnt,
28  std::atomic<Size>& totalCnt,
29  const Flags<CheckFunction> flags);
30 
32 };
33 
34 #ifdef SPH_DEBUG
35 #define CHECK_FUNCTION(flags) \
36  static std::atomic<Size> __reentrantCnt; \
37  static std::atomic<Size> __totalCnt; \
38  FunctionChecker __checker(__reentrantCnt, __totalCnt, flags);
39 #else
40 #define CHECK_FUNCTION(flags)
41 #endif
42 
43 
45 bool isMainThread();
46 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
CheckFunction
Definition: CheckFunction.h:14
@ NOT_MAIN_THREAD
Function cannot be called from main thread.
@ NO_THROW
Function cannot throw exceptions.
@ MAIN_THREAD
Function can only be executed from main thread.
@ ONCE
Function can be executed only once in the application.
@ NON_REENRANT
Function can be executed by any thread, but only once at a time.
bool isMainThread()
Checks if the calling thread is the main thred.
Wrapper over enum allowing setting (and querying) individual bits of the stored value.
Global parameters of the code.
#define NAMESPACE_SPH_END
Definition: Object.h:12
FunctionChecker(std::atomic< Size > &reentrantCnt, std::atomic< Size > &totalCnt, const Flags< CheckFunction > flags)