00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef INCLUDED_THREAD_BODY_WRAPPER_H
00022 #define INCLUDED_THREAD_BODY_WRAPPER_H
00023
00024 #include <gruel/thread.h>
00025 #include <exception>
00026 #include <iostream>
00027
00028 namespace gruel
00029 {
00030
00031 void mask_signals();
00032
00033 template <class F>
00034 class thread_body_wrapper
00035 {
00036 F d_f;
00037 std::string d_name;
00038
00039 public:
00040
00041 explicit thread_body_wrapper(F f, const std::string &name="")
00042 : d_f(f), d_name(name) {}
00043
00044 void operator()()
00045 {
00046 mask_signals();
00047
00048 try {
00049 d_f();
00050 }
00051 catch(boost::thread_interrupted const &)
00052 {
00053 }
00054 catch(std::exception const &e)
00055 {
00056 std::cerr << "thread[" << d_name << "]: "
00057 << e.what() << std::endl;
00058 }
00059 catch(...)
00060 {
00061 std::cerr << "thread[" << d_name << "]: "
00062 << "caught unrecognized exception\n";
00063 }
00064 }
00065 };
00066 }
00067
00068 #endif