GNU Radio Manual and C++ API Reference 3.10.5.1
The Free & Open Software Radio Ecosystem
thread_body_wrapper.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2008,2009,2013 Free Software Foundation, Inc.
4 *
5 * This file is part of GNU Radio
6 *
7 * SPDX-License-Identifier: GPL-3.0-or-later
8 *
9 */
10
11#ifndef INCLUDED_THREAD_BODY_WRAPPER_H
12#define INCLUDED_THREAD_BODY_WRAPPER_H
13
14#include <gnuradio/api.h>
15#include <gnuradio/logger.h>
17#include <exception>
18
19namespace gr {
20namespace thread {
21
23
24template <class F>
26{
27private:
28 F d_f;
29 std::string d_name;
30 bool d_catch_exceptions;
31 gr::logger_ptr d_logger;
32 gr::logger_ptr d_debug_logger;
33
34public:
35 explicit thread_body_wrapper(F f,
36 const std::string& name = "",
37 bool catch_exceptions = true)
38 : d_f(f), d_name(name), d_catch_exceptions(catch_exceptions)
39 {
40 gr::configure_default_loggers(d_logger, d_debug_logger, "thread_body_wrapper");
41 }
42
44 {
46
47 if (d_catch_exceptions) {
48 try {
49 d_f();
50 } catch (boost::thread_interrupted const&) {
51 } catch (std::exception const& e) {
52 d_logger->error("ERROR thread[{:s}]: {:s}", d_name, e.what());
53 } catch (...) {
54 d_logger->error("ERROR thread[{:s}]: caught unrecognized exception",
55 d_name);
56 }
57
58 } else {
59 try {
60 d_f();
61 } catch (boost::thread_interrupted const&) {
62 }
63 }
64 }
65};
66
67} /* namespace thread */
68} /* namespace gr */
69
70#endif /* INCLUDED_THREAD_BODY_WRAPPER_H */
Definition: thread_body_wrapper.h:26
thread_body_wrapper(F f, const std::string &name="", bool catch_exceptions=true)
Definition: thread_body_wrapper.h:35
void operator()()
Definition: thread_body_wrapper.h:43
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:18
boost::thread thread
Definition: thread.h:36
GR_RUNTIME_API void mask_signals()
GNU Radio logging wrapper.
Definition: basic_block.h:29
std::shared_ptr< logger > logger_ptr
Definition: logger.h:225
GR_RUNTIME_API bool configure_default_loggers(gr::logger_ptr &l, gr::logger_ptr &d, const std::string &name)