Add moo templates to make opmon info structs with std::atomic member variables #174
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Our normal codegen-ed structs (via
ostructs.hpp.j2
) have numeric member variables that are bare instances of the numeric typethey represent. Eg:
We pass these structs to the operational monitoring via the
get_info()
function, which is typically called from a different thread than the one in which the counters are actually filled. That means we have to "shadow" each of the members ofmymodule::Info
with astd::atomic
which is a member ofMyModule
, and then copy the value of each atomic into theInfo
object insideget_info()
. (In this example, we have to addstd::atomic<uint32_t> m_a_counter, m_another_counter;
members toMyModule
)We can avoid this duplication by holding a
mymodule::Info
as a member variable ofMyModule
and updating the counters in that object. This in turn means that the counters in theInfo
object have to be atomic, ie:This PR introduces a new pair of moo templates,
OpmonStructs.hpp.j2
andOpmonNljs.hpp.j2
, which correspond to moo's existingostructs.hpp.j2
andonljs2.hpp.j2
. The only real change is making all member variables that have moo-type "number" intostd::atomic
. (We also have to do a bit of work to make theto_json()
andfrom_json()
functions play nice with the atomicvariables.)
(
*.j2
files in theschema/
directory aren't currently installed bydaq_install()
, so we install them "manually" inCMakeLists.txt
. See DUNE-DAQ/daq-cmake#44 )To take advantage of the new-style info structs, no changes are needed to "info" schema files. But in
CMakeLists.txt
, calldaq_codegen()
for your "info" schema with the "opmon" templates, eg:In
MyModule
, add a member variable of typemymodule::Info
(m_info
, say) and fill/increment its members in any thread you like.get_info()
can then be implemented simply as:Notes: this doesn't change anything about the opmon interface. It's also completely optional, in that info structs can be left in the "old" format, with duplication, if desired.