libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
thread_api_traits_impl.hpp
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 #ifndef _MT
20 # error You need to configure the project build settings to be multithreaded!
21 #endif
22 
23 #include <process.h>
24 
25 #pragma warning(push)
26 #pragma warning(disable:4800) // forcing value to bool 'true' or 'false' (performance warning)
27 
28 namespace jmmcg { namespace ppd {
29 
30 // Implementation details..... Don't look below here!!! ;)
31 
32 // "api_threading_traits" implementation...
33 
36  return static_cast<api_params_type::pid_type>(::GetCurrentProcessId());
37  }
38 
41  return static_cast<api_params_type::tid_type>(::GetCurrentThreadId());
42  }
43 
46  return static_cast<api_params_type::handle_type>(::GetCurrentThread());
47  }
48 
49  template<> inline void __fastcall
52  }
53 
57  strcpy(demangled_names.begin(), "TODO: Not supported on Win32");
58  return demangled_names;
59  }
60 
61  template<> inline void __fastcall
63 // TODO
64  }
65 
66  inline void dump_bt_to_cerr() {
68  std::cerr<<bt.begin()<<std::endl;
69  }
70 
71  template<> inline void __fastcall
74  }
75 
76  /// Run the work only once if it returns at all, unlike the multi-threaded variant.
77  /**
78  If the worker_fn() returns true then it will run once, then exit, otherwise it will depend upon the return value for pre_exit(). If this always returns false, then the system will enter an infinite loop. By default pre_exit() for sequential mode returns false.
79 
80  \see worker_fn(), pre_exit(), process()
81  */
82  template<> inline bool __fastcall
89  }
90  return true;
91  }
92 
95  return static_cast<api_params_type::suspend_count>(0);
96  }
97 
98  /// This does not run the work at all, unlike the multi-threaded variant.
102  return static_cast<api_params_type::suspend_count>(0);
103  }
104 
108  }
109 
110  template<> inline void __fastcall
112  }
113 
114  template<> inline void __fastcall
116  }
117 
118  template<> inline void __fastcall
120  }
121 
122  template<> inline void __fastcall
124  }
125 
128  return api_params_type::normal;
129  }
130 
131  template<> inline void __fastcall
133  }
134 
138  }
139 
140  template<> inline void __fastcall
142  }
143 
144  template<> inline void __fastcall
146  }
147 
151  }
152 
153  template<> inline bool __fastcall
155  assert(cp.work_fn);
156  assert(cp.arglist);
157  // Note that to use this, you must implement a lock around the assignment, so that you can guarantee that it is done before calling other functions that may rely on the value of "cp.handle", which is plain nasty, because most Win32 API fns require the handle, not the id, and you can't get the handle atomically...
159  assert(cp.id);
160  return static_cast<bool>(cp.id);
161  }
162 
168  return count;
169  }
170 
173  assert(parms.id);
176  return count;
177  }
178 
182  assert(thread.id);
185  }
186  return static_cast<api_params_type::states>(exit_code);
187  }
188 
189  template<> inline void __fastcall
192  }
193 
194  template<> inline void __fastcall
198  }
199 
200  template<> inline void __fastcall
204  }
205 
206  template<> inline void __fastcall
208  assert(thread);
210  }
211 
214  assert(thread);
215  return static_cast<api_params_type::priority_type>(::GetThreadPriority(thread));
216  }
217 
218  template<> inline void __fastcall
222  }
223 
229  return mask;
230  }
231 
234  return static_cast<api_params_type::pid_type>(::GetCurrentProcessId());
235  }
236 
239  return static_cast<api_params_type::tid_type>(::GetCurrentThreadId());
240  }
241 
244  return static_cast<api_params_type::handle_type>(::GetCurrentThread());
245  }
246 
247  template<> inline void __fastcall
249  }
250 
251  template<> inline void __fastcall
253  ::Sleep(period);
254  }
255 
258  return static_cast<api_params_type::states>(::WaitForSingleObject(params.handle, period));
259  }
260 
261  template<> inline void __fastcall
264  }
265 
269  }
270 
271  template<> inline void __fastcall
274  }
275 
276  template<> inline void __fastcall
279  }
280 
281 } }
282 
283 #pragma warning(pop)