Loading...
Searching...
No Matches
thread_body_wrapper.h
Go to the documentation of this file.
/* -*- c++ -*- */
/*
* Copyright 2008,2009,2013 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#ifndef INCLUDED_THREAD_BODY_WRAPPER_H
#define INCLUDED_THREAD_BODY_WRAPPER_H
#include <gnuradio/api.h>
#include <gnuradio/logger.h>
#include <gnuradio/thread/thread.h>
#include <exception>
namespace gr {
namespace thread {
GR_RUNTIME_API void mask_signals();
template <class F>
class thread_body_wrapper
{
private:
F d_f;
std::string d_name;
bool d_catch_exceptions;
gr::logger_ptr d_logger;
gr::logger_ptr d_debug_logger;
public:
explicit thread_body_wrapper(F f,
const std::string& name = "",
bool catch_exceptions = true)
: d_f(f), d_name(name), d_catch_exceptions(catch_exceptions)
{
gr::configure_default_loggers(d_logger, d_debug_logger, "thread_body_wrapper");
}
void operator()()
{
mask_signals();
if (d_catch_exceptions) {
try {
d_f();
} catch (boost::thread_interrupted const&) {
} catch (std::exception const& e) {
d_logger->error("ERROR thread[{:s}]: {:s}", d_name, e.what());
} catch (...) {
d_logger->error("ERROR thread[{:s}]: caught unrecognized exception",
d_name);
}
} else {
try {
d_f();
} catch (boost::thread_interrupted const&) {
}
}
}
};
} /* namespace thread */
} /* namespace gr */
#endif /* INCLUDED_THREAD_BODY_WRAPPER_H */
gr::thread::thread_body_wrapper::thread_body_wrapper
thread_body_wrapper(F f, const std::string &name="", bool catch_exceptions=true)
Definition thread_body_wrapper.h:35
gr::thread::thread_body_wrapper::operator()
void operator()()
Definition thread_body_wrapper.h:43
api.h
GR_RUNTIME_API
#define GR_RUNTIME_API
Definition gnuradio-runtime/include/gnuradio/api.h:18
logger.h
gr::thread
Definition thread.h:31
gr::thread::mask_signals
GR_RUNTIME_API void mask_signals()
gr
GNU Radio logging wrapper.
Definition basic_block.h:29
gr::logger_ptr
std::shared_ptr< logger > logger_ptr
Definition logger.h:250
gr::configure_default_loggers
GR_RUNTIME_API bool configure_default_loggers(gr::logger_ptr &l, gr::logger_ptr &d, const std::string &name)
thread.h