libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
thread_base.cpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2005 by J.M.McGuiness, coder@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 #include "../core/private_/thread_base.hpp"
20 
21 #include <boost/exception/diagnostic_information.hpp>
22 
23 // Implementation details..... Don't look below here!!! ;)
24 
26 
27 // "thread_base" implementation...
28 
29 namespace jmmcg { namespace LIBJMMCG_VER_NAMESPACE { namespace ppd { namespace private_ {
30 
32 
35  assert(ptr);
36  thread_t_s * const pthis=reinterpret_cast<thread_t_s *>(ptr);
37  assert(pthis);
38  if (pthis) {
39  try {
42  int old_state;
43  [[maybe_unused]] const int pth_err=pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &old_state);
44  assert(pth_err==0);
47  return reinterpret_cast<thread_traits::api_params_type::core_work_fn_ret_t>(ret);
48 #if defined(__GNUC__) && !defined(__clang__)
49  } catch (abi::__forced_unwind const &) {
51  throw;
52 #endif
53  } catch (std::exception const &ex) {
54  JMMCG_TRACE(_T("STL-derived exception. Details: ")<<boost::diagnostic_information(ex));
56  } catch (...) {
57  JMMCG_TRACE(_T("Unknown exception caught. If it is a SIGSEGV, then the ss value in the thread_params ctor may need increasing."));
58  auto ex=std::current_exception();
59  if (ex) {
61  }
62  throw;
63  }
66  }
67  // In reality, no errors are actively reported to the user for this case, as the pthis was null.
68  // So we almost silently fail, and hope that they aren't sooooo dumb as to not notice that their work isn't being processed...
69  // This is because the only "opportunity" I have to report it is as an exception in the destructor. Hooo-boy would that be evil...
70  // Just think of the memory leaks.... So I don't do that. That's the breaks....
72 }
73 
75 
78  assert(ptr);
79  thread_t_m * const pthis=reinterpret_cast<thread_t_m *>(ptr);
80  assert(dynamic_cast<thread_t_m *>(pthis));
81  if (pthis) {
82  try {
85  int old_state;
86  [[maybe_unused]] const int pth_err=pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &old_state);
87  assert(pth_err==0);
90  return reinterpret_cast<thread_traits::api_params_type::core_work_fn_ret_t>(ret);
91 #if defined(__GNUC__) && !defined(__clang__)
92  } catch (abi::__forced_unwind const &) {
94  throw;
95 #endif
96  } catch (std::exception const &ex) {
97  JMMCG_TRACE(_T("STL-derived exception. Details: ")<<boost::diagnostic_information(ex));
99  } catch (...) {
100  JMMCG_TRACE(_T("Unknown exception caught. If it is a SIGSEGV, then the ss value in the thread_params ctor may need increasing."));
101  auto ex=std::current_exception();
102  if (ex) {
104  }
105  throw;
106  }
109  }
110  // In reality, no errors are actively reported to the user for this case, as the pthis was null.
111  // So we almost silently fail, and hope that they aren't sooooo dumb as to not notice that their work isn't being processed...
112  // This is because the only "opportunity" I have to report it is as an exception in the destructor. Hooo-boy would that be evil...
113  // Just think of the memory leaks.... So I don't do that. That's the breaks....
115 }
116 
117 } } } }