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 "dbe/convenience.hpp"
23#include <string>
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
41#define HERE_AUTO_DEF(funname) \
42 static auto TYPEA = ::tools::filt(this); \
43 static auto HERE = std::string("< ") + TYPEA + std::string(" >::") + std::string(#funname); \
44
45
48#define HERE_DEF(cn, fn) static char const* const HERE = "< " #cn " >:: " #fn " ";
49
54#define HERE_FUN_DEF(fn) static char const* const HERE = #fn " ";
55
59#ifndef RELEASE
61#define ERROR_NOREL(MSG) ERROR(MSG)
62#define WARN_NOREL(MSG) WARN(MSG)
63#define INFO_NOREL(MSG) INFO(MSG)
64#define DEBUG_NOREL(MSG) DEBUG(MSG)
65
66#else
67#define ERROR_NOREL(MSG)
68#define INFO_NOREL(MSG)
69#define DEBUG_NOREL(MSG)
70#endif
71
72//------------------------------------------------------------------------------
73
74//------------------------------------------------------------------------------
75// Concurrency macros
76//------------------------------------------------------------------------------
77/**
78 * CONDITION_STD_SET provides safe concurrent setting of a shared variable
79 */
80#define CONDITION_STD_SET(cond, lock, var, val) \
81 { \
82 { \
83 std::lock_guard<std::mutex> __LUTILS_CONDITIONAL_SET_GUARD_##cond_##lock_##var__(lock); \
84 var = val; \
85 } \
86 cond.notify_all(); \
87 }
88
91 *
92 * Upon any exception thrown it will break an enclosing loop
93 */
94#define CONDITION_BOOL_WAIT(cond, lock, var) \
95 \
96 std::unique_lock<std::mutex> __LUTILS_CONDITIONAL_BOOL_WAIT_GUARD_##cond_##lock_##var__(lock); \
97 try { \
98 cond.wait(__LUTILS_CONDITIONAL_BOOL_WAIT_GUARD_##cond_##lock_##var__, [this]() { return var; }); \
99 } catch (...) { \
100 break; \
101 }
102
107 * It is advisable that tryfun does not throw exceptions
108 */
109#define CONDITION_BOOL_WAIT_TRYFUN(cond, lock, var, tryfun) \
110 \
111 std::unique_lock<std::mutex> __LUTILS_CONDITIONAL_BOOL_WAIT_TRYFUN_GUARD_##cond_##lock_##var__(lock); \
112 try { \
113 cond.wait(__LUTILS_CONDITIONAL_BOOL_WAIT_TRYFUN_GUARD_##cond_##lock_##var__, [this]() { return var; }); \
114 } catch (...) { \
115 break; \
116 }
117
122 * Upon any exception thrown it will break an enclosing loop
123 */
124#define CONDITION_BOOL_WAIT_FUN(cond, lock, fun) \
125 \
126 std::unique_lock<std::mutex> __LUTILS_CONDITIONAL_BOOL_WAIT_FUN_GUARD_##cond_##lock_(lock); \
127 try { \
128 cond.wait(__LUTILS_CONDITIONAL_BOOL_WAIT_FUN_GUARD_##cond_##lock_, fun); \
129 } catch (...) { \
130 break; \
131 }
132
137 * It is advisable that tryfun does not throw exceptions
138 */
139#define CONDITION_BOOL_WAIT_FUN_TRYFUN(cond, lock, fun, tryfun) \
140 \
141 std::unique_lock<std::mutex> __LUTILS_CONDITIONAL_BOOL_WAIT_FUN_TRYFUN_GUARD_##cond_##lock_(lock); \
142 try { \
143 cond.wait(__LUTILS_CONDITIONAL_BOOL_WAIT_FUN_TRYFUN_GUARD_##cond_##lock_, fun); \
144 } catch (...) { \
145 tryfun(); \
146 } \
147//------------------------------------------------------------------------------
148
149//------------------------------------------------------------------------------
150// IDE COMPAT MACROS
151//------------------------------------------------------------------------------
152// A workaround for eclipse formatter bug when using decltype
153#define DECLTYPE(x) decltype(x)
154//------------------------------------------------------------------------------
155
156//------------------------------------------------------------------------------
157// VARIABLE ARGUMENTS MACRO COMPAT MACROS
158//------------------------------------------------------------------------------
159#define CAT(A, B) A##B
160#define SELECT(NAME, NUM) CAT(NAME##_, NUM)
161
162#define GET_COUNT(_1, _2, _3, _4, _5, _6, _7, _8, _9, COUNT, ...) COUNT
163#define VA_SIZE(...) GET_COUNT(__VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1)
164
165#define VA_SELECT(NAME, ...) SELECT(NAME, VA_SIZE(__VA_ARGS__))(__VA_ARGS__)
166//------------------------------------------------------------------------------
167
168#endif /* LUTILS_MACRO_H_ */