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 � 2004 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 "stdafx.h"
20 
21 #include "../../../core/exception.hpp"
22 #include "../../../core/thread_base.hpp"
23 
24 // Implementation details..... Don't look below here!!! ;)
25 
26 using namespace libjmmcg;
27 
28 // "thread_base" implementation...
29 
30 template<> __declspec(dllexport) ppd::private_::thread_base<ppd::generic_traits::MS_Win32, ppd::sequential_mode>::thread_traits::api_params_type::core_work_fn_ret_t __stdcall
31 ppd::private_::thread_base<ppd::generic_traits::MS_Win32, ppd::sequential_mode>
32 ::core_work_fn(thread_traits::api_params_type::core_work_fn_arg_t ptr) {
33  assert(ptr);
34  thread_base<generic_traits::MS_Win32, sequential_mode> * const pthis=reinterpret_cast<thread_base<generic_traits::MS_Win32,sequential_mode> *>(ptr);
35  assert(pthis);
36  if (pthis) {
37  try {
38  const api_threading_traits<generic_traits::MS_Win32, sequential_mode>::api_params_type::states ret=pthis->process_chk();
39  return static_cast<thread_traits::api_params_type::core_work_fn_ret_t>(ret);
40  } catch (const os_traits::thread_exception::value_type &e) {
41  assert(!"JMMCG-exception caught.");
42  pthis->exception_thrown_in_thread.set(os_traits::thread_exception::value_type(StringToTString(e.what()), info::function(__LINE__, __PRETTY_FUNCTION__, typeid(core_work_fn), info::function::argument(_T("void *"), tostring(ptr))), JMMCG_REVISION_HDR(_T(LIBJMMCG_VERSION_NUMBER))));
43  return static_cast<thread_traits::api_params_type::core_work_fn_ret_t>(api_threading_traits<generic_traits::MS_Win32, sequential_mode>::api_params_type::jmmcg_exception);
44  } catch (const std::exception &e) {
45  assert(!"STL-exception caught.");
46  pthis->exception_thrown_in_thread.set(os_traits::thread_exception::value_type(StringToTString(e.what()), info::function(__LINE__, __PRETTY_FUNCTION__, typeid(core_work_fn), info::function::argument(_T("void *"), tostring(ptr))), JMMCG_REVISION_HDR(_T(LIBJMMCG_VERSION_NUMBER))));
47  return static_cast<thread_traits::api_params_type::core_work_fn_ret_t>(api_threading_traits<generic_traits::MS_Win32, sequential_mode>::api_params_type::stl_exception);
48  } catch (...) {
49  assert(!"Unknown exception caught.");
50  pthis->exception_thrown_in_thread.set(os_traits::thread_exception::value_type(_T("Unknown exception caught."), info::function(__LINE__, __PRETTY_FUNCTION__, typeid(core_work_fn), info::function::argument(_T("void *"), tostring(ptr))), JMMCG_REVISION_HDR(_T(LIBJMMCG_VERSION_NUMBER))));
51  }
52  return static_cast<thread_traits::api_params_type::core_work_fn_ret_t>(api_threading_traits<generic_traits::MS_Win32, sequential_mode>::api_params_type::unknown_exception);
53  }
54  // In reality, no errors are actively reported to the user for this case, as the pthis was null.
55  // So we almost silently fail, and hope that they aren't sooooo dumb as to not notice that their work isn't being processed...
56  // This is because the only "opportunity" I have to report it is as an exception in the destructor. Hooo-boy would that be evil...
57  // Just think of the memory leaks.... So I don't do that. That's the breaks....
58  return static_cast<thread_traits::api_params_type::core_work_fn_ret_t>(api_threading_traits<generic_traits::MS_Win32, sequential_mode>::api_params_type::null_this_pointer);
59 }
60 
61 template<> __declspec(dllexport) ppd::private_::thread_base<ppd::generic_traits::MS_Win32, ppd::heavyweight_threading>::thread_traits::api_params_type::core_work_fn_ret_t __stdcall
62 ppd::private_::thread_base<ppd::generic_traits::MS_Win32, ppd::heavyweight_threading>::core_work_fn(thread_traits::api_params_type::core_work_fn_arg_t ptr) {
63  assert(ptr);
64  thread_base<generic_traits::MS_Win32,heavyweight_threading> * const pthis=reinterpret_cast<thread_base<generic_traits::MS_Win32, heavyweight_threading> *>(ptr);
65  assert(pthis);
66  if (pthis) {
67  try {
68  const api_threading_traits<generic_traits::MS_Win32, heavyweight_threading>::api_params_type::states ret=pthis->process_chk();
69  return static_cast<thread_traits::api_params_type::core_work_fn_ret_t>(ret);
70  } catch (const os_traits::thread_exception::value_type &e) {
71  JMMCG_TRACE(_T("JMMCG-exception caught: ")<<e.what());
72  assert(!"JMMCG-exception caught.");
73  pthis->exception_thrown_in_thread.set(os_traits::thread_exception::value_type(StringToTString(e.what()), info::function(__LINE__, __PRETTY_FUNCTION__, typeid(core_work_fn), info::function::argument(_T("void *"), tostring(ptr))), JMMCG_REVISION_HDR(_T(LIBJMMCG_VERSION_NUMBER))));
74  return static_cast<thread_traits::api_params_type::core_work_fn_ret_t>(api_threading_traits<generic_traits::MS_Win32, heavyweight_threading>::api_params_type::jmmcg_exception);
75  } catch (const std::exception &e) {
76  JMMCG_TRACE(_T("STL-exception caught: ")<<e.what());
77  assert(!"STL-exception caught.");
78  pthis->exception_thrown_in_thread.set(os_traits::thread_exception::value_type(StringToTString(e.what()), info::function(__LINE__, __PRETTY_FUNCTION__, typeid(core_work_fn), info::function::argument(_T("void *"), tostring(ptr))), JMMCG_REVISION_HDR(_T(LIBJMMCG_VERSION_NUMBER))));
79  return static_cast<thread_traits::api_params_type::core_work_fn_ret_t>(api_threading_traits<generic_traits::MS_Win32, heavyweight_threading>::api_params_type::stl_exception);
80  } catch (...) {
81  JMMCG_TRACE(_T("Unknown exception caught."));
82  pthis->exception_thrown_in_thread.set(os_traits::thread_exception::value_type(_T("Unknown exception caught."), info::function(__LINE__, __PRETTY_FUNCTION__, typeid(core_work_fn), info::function::argument(_T("void *"), tostring(ptr))), JMMCG_REVISION_HDR(_T(LIBJMMCG_VERSION_NUMBER))));
83  }
84  return static_cast<thread_traits::api_params_type::core_work_fn_ret_t>(api_threading_traits<generic_traits::MS_Win32, heavyweight_threading>::api_params_type::unknown_exception);
85  }
86  // In reality, no errors are actively reported to the user for this case, as the pthis was null.
87  // So we almost silently fail, and hope that they aren't sooooo dumb as to not notice that their work isn't being processed...
88  // This is because the only "opportunity" I have to report it is as an exception in the destructor. Hooo-boy would that be evil...
89  // Just think of the memory leaks.... So I don't do that. That's the breaks....
90  return static_cast<thread_traits::api_params_type::core_work_fn_ret_t>(api_threading_traits<generic_traits::MS_Win32, heavyweight_threading>::api_params_type::null_this_pointer);
91 }