DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
macro.hpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4// Renamed since fork: yes (from dbe/macro.h to include/dbe/macro.hpp).
5
6/************************************************************
7 * macro.h *
8 * *
9 * Created on: Sep 14, 2014 *
10 * Author: Leonidas Georgopoulos *
11 *
12 * Copyright (C) 2014 Leonidas Georgopoulos
13 * Distributed under the Boost Software License, Version 1.0.
14 * (See accompanying file LICENSE_1_0.txt or
15 * copy at http://www.boost.org/LICENSE_1_0.txt)
16 *
17 ************************************************************/
18
19#ifndef LUTILS_MACRO_H_
20#define LUTILS_MACRO_H_
21
22#include <string>
23#include "dbe/convenience.hpp"
24
25//------------------------------------------------------------------------------
26// Messaging macros
27//------------------------------------------------------------------------------
32#define HERE_TMPL_DEF(T,funname) \
33 typedef typename ::tools::gentraits<T> t_gentraits_T; \
34 static typename t_gentraits_T::t_is const TYPEA = t_gentraits_T::filt(); \
35 static typename t_gentraits_T::t_is const HERE = #funname + "< " + TYPEA +" >"; \
36
37
41#define HERE_AUTO_DEF(funname) \
42 static auto TYPEA = ::tools::filt(this); \
43 static auto HERE = std::string("< ") + TYPEA \
44 + std::string(" >::") + std::string(#funname); \
45
46
49#define HERE_DEF(cn,fn) static char const * const HERE = "< "#cn" >:: "#fn" ";
50
55#define HERE_FUN_DEF(fn) static char const * const HERE = #fn" ";
56
60#ifndef RELEASE
62#define ERROR_NOREL(MSG) ERROR(MSG)
63#define WARN_NOREL(MSG) WARN(MSG)
64#define INFO_NOREL(MSG) INFO(MSG)
65#define DEBUG_NOREL(MSG) DEBUG(MSG)
66
67#else
68#define ERROR_NOREL(MSG)
69#define INFO_NOREL(MSG)
70#define DEBUG_NOREL(MSG)
71#endif
72
73//------------------------------------------------------------------------------
74
75//------------------------------------------------------------------------------
76// Concurrency macros
77//------------------------------------------------------------------------------
78/**
79 * CONDITION_STD_SET provides safe concurrent setting of a shared variable
80 */
81#define CONDITION_STD_SET(cond,lock,var,val) \
82 { \
83 { \
84 std::lock_guard<std::mutex> \
85 __LUTILS_CONDITIONAL_SET_GUARD_##cond_##lock_##var__(lock); \
86 var = val; \
87 } \
88 cond.notify_all(); \
89 } \
90
93 *
94 * Upon any exception thrown it will break an enclosing loop
95 */
96#define CONDITION_BOOL_WAIT(cond,lock,var) \
97 \
98 std::unique_lock<std::mutex> \
99__LUTILS_CONDITIONAL_BOOL_WAIT_GUARD_##cond_##lock_##var__(lock); \
100 try { \
101cond.wait(__LUTILS_CONDITIONAL_BOOL_WAIT_GUARD_##cond_##lock_##var__, [this]() \
102 { return var;}); \
103 } catch (...) {\
104 break;\
105 }\
106
111 * It is advisable that tryfun does not throw exceptions
112 */
113#define CONDITION_BOOL_WAIT_TRYFUN(cond,lock,var,tryfun) \
114 \
115 std::unique_lock<std::mutex> \
116__LUTILS_CONDITIONAL_BOOL_WAIT_TRYFUN_GUARD_##cond_##lock_##var__(lock); \
117 try { \
118cond.wait(__LUTILS_CONDITIONAL_BOOL_WAIT_TRYFUN_GUARD_##cond_##lock_##var__, [this]() \
119 { return var;}); \
120 } catch (...) {\
121 break;\
122 }\
123
128 * Upon any exception thrown it will break an enclosing loop
129 */
130#define CONDITION_BOOL_WAIT_FUN(cond,lock,fun) \
131 \
132 std::unique_lock<std::mutex> \
133 __LUTILS_CONDITIONAL_BOOL_WAIT_FUN_GUARD_##cond_##lock_(lock); \
134 try { \
135cond.wait(__LUTILS_CONDITIONAL_BOOL_WAIT_FUN_GUARD_##cond_##lock_, fun ); \
136 } catch(...) {\
137 break; \
138 }\
139
144 * It is advisable that tryfun does not throw exceptions
145 */
146#define CONDITION_BOOL_WAIT_FUN_TRYFUN(cond,lock,fun,tryfun) \
147 \
148 std::unique_lock<std::mutex> \
149 __LUTILS_CONDITIONAL_BOOL_WAIT_FUN_TRYFUN_GUARD_##cond_##lock_(lock); \
150 try { \
151cond.wait(__LUTILS_CONDITIONAL_BOOL_WAIT_FUN_TRYFUN_GUARD_##cond_##lock_, fun ); \
152 } catch(...) {\
153 tryfun(); \
154 }\
155//------------------------------------------------------------------------------
156
157//------------------------------------------------------------------------------
158// IDE COMPAT MACROS
159//------------------------------------------------------------------------------
160// A workaround for eclipse formatter bug when using decltype
161#define DECLTYPE(x) decltype(x)
162//------------------------------------------------------------------------------
163
164//------------------------------------------------------------------------------
165// VARIABLE ARGUMENTS MACRO COMPAT MACROS
166//------------------------------------------------------------------------------
167#define CAT( A, B ) A ## B
168#define SELECT( NAME, NUM ) CAT( NAME ## _, NUM )
169
170#define GET_COUNT( _1, _2, _3, _4, _5, _6 , _7, _8, _9, COUNT, ... ) COUNT
171#define VA_SIZE( ... ) GET_COUNT( __VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1 )
172
173#define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)
174//------------------------------------------------------------------------------
175
176
177
178#endif /* LUTILS_MACRO_H_ */