nlib
Thread.h
[詳解]
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_THREADING_THREAD_H_
4 #define INCLUDE_NN_NLIB_THREADING_THREAD_H_
5 
6 #include "nn/nlib/Config.h"
7 #include "nn/nlib/Swap.h"
8 #include "nn/nlib/UniquePtr.h"
9 #include "nn/nlib/TypeTraits.h"
10 #include "nn/nlib/DateTime.h"
11 
12 NLIB_NAMESPACE_BEGIN
13 namespace threading {
14 struct None {};
15 
17  public:
18  ThreadSettings() NLIB_NOEXCEPT : m_Initialized(false) {}
20  if (m_Initialized) {
21  errno_t e = nlib_thread_attr_destroy(&m_Attr);
22  NLIB_ASSERT_NOERR(e);
23  NLIB_UNUSED(e);
24  }
25  }
26  void SetDetachState(bool detached) NLIB_NOEXCEPT {
27  this->Init_();
29  &m_Attr,
30  NLIB_THREAD_ATTR_KEY_DETACHSTATE,
31  detached ? 1 : 0);
32  NLIB_ASSERT_NOERR(e);
33  NLIB_UNUSED(e);
34  }
36  NLIB_ASSERT(m_Initialized);
37  int detached;
39  &m_Attr,
40  NLIB_THREAD_ATTR_KEY_DETACHSTATE,
41  &detached);
42  NLIB_ASSERT_NOERR(e);
43  NLIB_UNUSED(e);
44  return (detached != 0);
45  }
47  this->Init_();
49  &m_Attr,
50  NLIB_THREAD_ATTR_KEY_STACKSIZE,
51  size);
52  return e;
53  }
55  NLIB_ASSERT(m_Initialized);
56  int size;
58  &m_Attr,
59  NLIB_THREAD_ATTR_KEY_STACKSIZE,
60  &size);
61  NLIB_ASSERT_NOERR(e);
62  NLIB_UNUSED(e);
63  return size;
64  }
66  this->Init_();
68  &m_Attr,
69  NLIB_THREAD_ATTR_KEY_PRIORITY,
70  priority);
71  return e;
72  }
73  int GetPriority() const NLIB_NOEXCEPT {
74  NLIB_ASSERT(m_Initialized);
75  int priority;
77  &m_Attr,
78  NLIB_THREAD_ATTR_KEY_PRIORITY,
79  &priority);
80  NLIB_ASSERT_NOERR(e);
81  NLIB_UNUSED(e);
82  return priority;
83  }
85  return m_Initialized ? &m_Attr : NULL;
86  }
87  const nlib_thread_attr* GetPtr() const NLIB_NOEXCEPT {
88  return m_Initialized ? &m_Attr : NULL;
89  }
90 
91  private:
92  void Init_() NLIB_NOEXCEPT {
93  if (!m_Initialized) {
94  errno_t e = nlib_thread_attr_init(&m_Attr);
95  NLIB_ASSERT_NOERR(e);
96  NLIB_UNUSED(e);
97  m_Initialized = true;
98  }
99  }
100  bool m_Initialized;
101  nlib_thread_attr m_Attr;
102 };
103 
104 template <class T1 = None, class T2 = None, class T3 = None, class T4 = None, class T5 = None>
105 struct ThreadArg {
108  typedef void (*Func)(ArgType& ptr); // NOLINT
109  NLIB_CEXPR ThreadArg() : func(NULL), arg1(), arg2(), arg3(), arg4(), arg5() {}
110  NLIB_CEXPR ThreadArg(Func func_, T1 arg1_, T2 arg2_, T3 arg3_, T4 arg4_, T5 arg5_)
111  : func(func_), arg1(arg1_), arg2(arg2_), arg3(arg3_), arg4(arg4_), arg5(arg5_) {}
112  static void Call(ArgType& ptr) { ptr->func(ptr); } // NOLINT
113  public:
114  Func func;
115  T1 arg1;
116  T2 arg2;
117  T3 arg3;
118  T4 arg4;
119  T5 arg5;
120 };
121 
122 template <>
123 struct ThreadArg<None, None, None, None, None> {
124  typedef ThreadArg<> ThisType;
125  typedef void ArgType;
126  typedef void (*Func)();
127 };
128 
129 template <class T1>
130 struct ThreadArg<T1, None, None, None, None> {
131  typedef ThreadArg<T1> ThisType;
132  typedef UniquePtr<ThisType> ArgType;
133  typedef void (*Func)(ArgType& ptr); // NOLINT
134  NLIB_CEXPR ThreadArg() : func(NULL), arg1() {}
135  NLIB_CEXPR ThreadArg(Func func_, T1 arg1_) : func(func_), arg1(arg1_) {}
136  static void Call(ArgType& ptr) { ptr->func(ptr); } // NOLINT
137  public:
138  Func func;
139  T1 arg1;
140 };
141 
142 template <class T1, class T2>
143 struct ThreadArg<T1, T2, None, None, None> {
144  typedef ThreadArg<T1, T2> ThisType;
145  typedef UniquePtr<ThisType> ArgType;
146  typedef void (*Func)(ArgType& ptr); // NOLINT
147  NLIB_CEXPR ThreadArg() : func(NULL), arg1(), arg2() {}
148  NLIB_CEXPR ThreadArg(Func func_, T1 arg1_, T2 arg2_) : func(func_), arg1(arg1_), arg2(arg2_) {}
149  static void Call(ArgType& ptr) { ptr->func(ptr); } // NOLINT
150  public:
151  Func func;
152  T1 arg1;
153  T2 arg2;
154 };
155 
156 template <class T1, class T2, class T3>
157 struct ThreadArg<T1, T2, T3, None, None> {
158  typedef ThreadArg<T1, T2, T3> ThisType;
159  typedef UniquePtr<ThisType> ArgType;
160  typedef void (*Func)(ArgType& ptr); // NOLINT
161  NLIB_CEXPR ThreadArg() : func(NULL), arg1(), arg2(), arg3() {}
162  NLIB_CEXPR ThreadArg(Func func_, T1 arg1_, T2 arg2_, T3 arg3_)
163  : func(func_), arg1(arg1_), arg2(arg2_), arg3(arg3_) {}
164  static void Call(ArgType& ptr) { ptr->func(ptr); } // NOLINT
165  public:
166  Func func;
167  T1 arg1;
168  T2 arg2;
169  T3 arg3;
170 };
171 
172 template <class T1, class T2, class T3, class T4>
173 struct ThreadArg<T1, T2, T3, T4, None> {
174  typedef ThreadArg<T1, T2, T3, T4> ThisType;
175  typedef UniquePtr<ThisType> ArgType;
176  typedef void (*Func)(ArgType& ptr); // NOLINT
177  NLIB_CEXPR ThreadArg() : func(NULL), arg1(), arg2(), arg3(), arg4() {}
178  NLIB_CEXPR ThreadArg(Func func_, T1 arg1_, T2 arg2_, T3 arg3_, T4 arg4_)
179  : func(func_), arg1(arg1_), arg2(arg2_), arg3(arg3_), arg4(arg4_) {}
180  static void Call(ArgType& ptr) { ptr->func(ptr); } // NOLINT
181  public:
182  Func func;
183  T1 arg1;
184  T2 arg2;
185  T3 arg3;
186  T4 arg4;
187 };
188 
189 #ifdef _MSC_VER
190 #pragma warning(push)
191 #pragma warning(disable : 4180)
192 #endif
193 
194 // code snippets:
195 // Thread th;
196 // void func(...) {}
197 // th.Start(func, ...); # to create a thread and run func() on it
198 // th.Join(); # or th.Detach();
200  public:
201  typedef void (*ThreadFunc)(void* arg);
204  if (m_ThreadId != NLIB_THREAD_INVALID) this->Join();
205  }
206  NLIB_MOVE_MEMBER_HELPER_1(Thread, m_ThreadId)
207  errno_t StartRaw(ThreadFunc func, void* arg) NLIB_NOEXCEPT {
208  ThreadSettings defaultSettings;
209  return this->StartRaw(func, arg, defaultSettings);
210  }
211  NLIB_VIS_PUBLIC errno_t StartRaw(ThreadFunc func, void* arg,
212  const ThreadSettings& settings) NLIB_NOEXCEPT;
213  errno_t Join() NLIB_NOEXCEPT {
214  if (!m_ThreadId) return ESRCH;
215  errno_t e = nlib_thread_join(m_ThreadId);
216  if (e == 0) {
217  m_ThreadId = NLIB_THREAD_INVALID;
218  return 0;
219  } else {
220  return e;
221  }
222  }
223  errno_t Detach() NLIB_NOEXCEPT {
224  errno_t e = nlib_thread_detach(m_ThreadId);
225  if (e == 0) m_ThreadId = NLIB_THREAD_INVALID;
226  return e;
227  }
228  bool IsJoinable() const NLIB_NOEXCEPT { return m_ThreadId != NLIB_THREAD_INVALID; }
229  errno_t GetPriority(int32_t* priority) NLIB_NOEXCEPT {
230  return nlib_thread_getpriority(this->GetNativeHandle(), reinterpret_cast<int*>(priority));
231  }
232  errno_t ChangePriority(int32_t priority) NLIB_NOEXCEPT {
233  return nlib_thread_setpriority(this->GetNativeHandle(), priority);
234  }
235  errno_t SetAffinity(uint32_t affinity) NLIB_NOEXCEPT {
236  return nlib_thread_setaffinity(m_ThreadId, affinity);
237  }
238  nlib_thread GetNativeHandle() const NLIB_NOEXCEPT { return m_ThreadId; }
239  void swap(Thread& rhs) NLIB_NOEXCEPT { // NOLINT
240  using std::swap;
241  swap(m_ThreadId, rhs.m_ThreadId);
242  }
243  bool operator==(const Thread& rhs) NLIB_NOEXCEPT {
244  return nlib_thread_equal(m_ThreadId, rhs.m_ThreadId) ? true : false;
245  }
246  bool operator!=(const Thread& rhs) NLIB_NOEXCEPT {
247  return nlib_thread_equal(m_ThreadId, rhs.m_ThreadId) ? false : true;
248  }
249 
250  static errno_t YieldThread() NLIB_NOEXCEPT { return nlib_yield(); }
251  static errno_t Sleep(const TimeSpan& span) NLIB_NOEXCEPT {
252  return nlib_sleep(span.ToTimeValue().tick);
253  }
254 
255  public:
256  errno_t StartRaw(const ThreadSettings& settings, ThreadArg<>::Func func) NLIB_NOEXCEPT {
257  errno_t e = this->StartRaw(Thread::Exec, reinterpret_cast<void*>(func), settings);
258  return e;
259  }
260  errno_t StartRaw(ThreadArg<>::Func func) NLIB_NOEXCEPT {
261  ThreadSettings defaultSettings;
262  return this->StartRaw(defaultSettings, func);
263  }
264  template <class ThArg>
265  errno_t StartRaw(const ThreadSettings& settings,
266  UniquePtr<ThArg>& ptr) NLIB_NOEXCEPT { // NOLINT
267  if (!ptr) return EINVAL;
268  errno_t e = this->StartRaw((ThreadFunc)Thread::Exec<ThArg>, // NOLINT
269  reinterpret_cast<void*>(ptr.get()), settings);
270  if (e == 0) ptr.release();
271  return e;
272  }
273  template <class ThArg>
274  errno_t StartRaw(UniquePtr<ThArg>& ptr) NLIB_NOEXCEPT { // NOLINT
275  ThreadSettings defaultSettings;
276  return this->StartRaw(defaultSettings, ptr);
277  }
278 
279  private:
280  static void Exec(void* p) {
281  ThreadArg<>::Func f = reinterpret_cast<ThreadArg<>::Func>(p);
282  f();
283  }
284  template <class T>
285  static void Exec(void* p) {
286  UniquePtr<T> args(reinterpret_cast<T*>(p));
287  T::Call(args);
288  }
289 
290 #define NLIB_THFUNC_USESWAP_NO(tp) \
291  typename EnableIf< \
292  !IsSame<None, typename RemoveCv<B>::type>::value && \
293  (IsSame<FalseType, typename RemoveCv<B>::type>::value || !IsSwappable<tp>::value), \
294  const tp&>::type
295 #define NLIB_THFUNC_USESWAP_YES(tp) \
296  typename EnableIf<!IsSame<None, typename RemoveCv<B>::type>::value && \
297  IsSame<TrueType, typename RemoveCv<B>::type>::value && \
298  IsSwappable<tp>::value, \
299  const tp&>::type
300 
301  template <class T>
302  struct ArgType : public Conditional<
303  IsArithmetic<T>::value || IsPointer<T>::value || IsMemberPointer<T>::value,
304  FalseType, TrueType> {};
305 
306  template <class FUNC>
307  struct Args0 {
308  typedef typename RemoveRef<FUNC>::type FUNC_;
309  template <class B>
310  Args0(NLIB_THFUNC_USESWAP_NO(FUNC_) func_, B)
311  : func(func_) {}
312  template <class B>
313  Args0(NLIB_THFUNC_USESWAP_YES(FUNC_) func_, B)
314  : func() {
315  using std::swap;
316  swap(const_cast<FUNC&>(func_), func);
317  }
318  template <class B>
319  Args0(typename EnableIf<IsSame<typename RemoveCv<B>::type, None>::value, const FUNC&>::type
320  func_,
321  B)
322  : func(func_) {}
323  FUNC_ func;
324 
325  private:
327  };
328  template <class FUNC, class T1>
329  struct Args1 : public Args0<FUNC> {
330  typedef Args0<FUNC> BaseType;
331  typedef typename RemoveRef<T1>::type T1_;
332  template <class B>
333  Args1(const FUNC& func_, NLIB_THFUNC_USESWAP_NO(T1) arg1_, B)
334  : BaseType(func_, typename IsSwappable<FUNC>::type()), arg1(arg1_) {}
335  template <class B>
336  Args1(const FUNC& func_, NLIB_THFUNC_USESWAP_YES(T1) arg1_, B)
337  : BaseType(func_, typename IsSwappable<FUNC>::type()), arg1() {
338  using std::swap;
339  swap(const_cast<T1&>(arg1_), arg1);
340  }
341  template <class B>
342  Args1(typename EnableIf<IsSame<typename RemoveCv<B>::type, None>::value, const FUNC&>::type
343  func_,
344  const T1& arg1_, B b)
345  : BaseType(func_, b), arg1(arg1_) {}
346  T1_ arg1;
347  };
348  template <class FUNC, class T1, class T2>
349  struct Args2 : public Args1<FUNC, T1> {
350  typedef Args1<FUNC, T1> BaseType;
351  typedef typename RemoveRef<T2>::type T2_;
352  template <class B>
353  Args2(const FUNC& func_, const T1& arg1_, NLIB_THFUNC_USESWAP_NO(T2) arg2_, B)
354  : BaseType(func_, arg1_, typename ArgType<T1>::type()), arg2(arg2_) {}
355  template <class B>
356  Args2(const FUNC& func_, const T1& arg1_, NLIB_THFUNC_USESWAP_YES(T2) arg2_, B)
357  : BaseType(func_, arg1_, typename ArgType<T1>::type()), arg2() {
358  using std::swap;
359  swap(const_cast<T2&>(arg2_), arg2);
360  }
361  template <class B>
362  Args2(typename EnableIf<IsSame<typename RemoveCv<B>::type, None>::value, const FUNC&>::type
363  func_,
364  const T1& arg1_, const T2& arg2_, B b)
365  : BaseType(func_, arg1_, b), arg2(arg2_) {}
366  T2_ arg2;
367  };
368  template <class FUNC, class T1, class T2, class T3>
369  struct Args3 : public Args2<FUNC, T1, T2> {
370  typedef Args2<FUNC, T1, T2> BaseType;
371  typedef typename RemoveRef<T3>::type T3_;
372  template <class B>
373  Args3(const FUNC& func_, const T1& arg1_, const T2& arg2_, NLIB_THFUNC_USESWAP_NO(T3) arg3_,
374  B)
375  : BaseType(func_, arg1_, arg2_, typename ArgType<T2>::type()), arg3(arg3_) {}
376  template <class B>
377  Args3(const FUNC& func, const T1& arg1_, const T2& arg2_, NLIB_THFUNC_USESWAP_YES(T3) arg3_,
378  B)
379  : BaseType(func, arg1_, arg2_, typename ArgType<T2>::type()), arg3() {
380  using std::swap;
381  swap(const_cast<T3&>(arg3_), arg3);
382  }
383  template <class B>
384  Args3(typename EnableIf<IsSame<typename RemoveCv<B>::type, None>::value, const FUNC&>::type
385  func_,
386  const T1& arg1_, const T2& arg2_, const T3& arg3_, B b)
387  : BaseType(func_, arg1_, arg2_, b), arg3(arg3_) {}
388  T3_ arg3;
389  };
390  template <class FUNC, class T1, class T2, class T3, class T4>
391  struct Args4 : public Args3<FUNC, T1, T2, T3> {
392  typedef Args3<FUNC, T1, T2, T3> BaseType;
393  typedef typename RemoveRef<T4>::type T4_;
394  template <class B>
395  Args4(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_,
396  NLIB_THFUNC_USESWAP_NO(T4) arg4_, B)
397  : BaseType(func_, arg1_, arg2_, arg3_, typename ArgType<T3>::type()), arg4(arg4_) {}
398  template <class B>
399  Args4(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_,
400  NLIB_THFUNC_USESWAP_YES(T4) arg4_, B)
401  : BaseType(func_, arg1_, arg2_, arg3_, typename ArgType<T3>::type()), arg4() {
402  using std::swap;
403  swap(const_cast<T4&>(arg4_), arg4);
404  }
405  template <class B>
406  Args4(typename EnableIf<IsSame<typename RemoveCv<B>::type, None>::value, const FUNC&>::type
407  func_,
408  const T1& arg1_, const T2& arg2_, const T3& arg3_, const T4& arg4_, B b)
409  : BaseType(func_, arg1_, arg2_, arg3_, b), arg4(arg4_) {}
410  T4_ arg4;
411  };
412  template <class FUNC, class T1, class T2, class T3, class T4, class T5>
413  struct Args5 : public Args4<FUNC, T1, T2, T3, T4> {
414  typedef Args4<FUNC, T1, T2, T3, T4> BaseType;
415  typedef typename RemoveRef<T5>::type T5_;
416  template <class B>
417  Args5(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_, const T4& arg4_,
418  NLIB_THFUNC_USESWAP_NO(T5) arg5_, B)
419  : BaseType(func_, arg1_, arg2_, arg3_, arg4_, typename ArgType<T4>::type()),
420  arg5(arg5_) {}
421  template <class B>
422  Args5(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_, const T4& arg4_,
423  NLIB_THFUNC_USESWAP_YES(T4) arg5_, B)
424  : BaseType(func_, arg1_, arg2_, arg3_, arg4_, typename ArgType<T4>::type()), arg5() {
425  using std::swap;
426  swap(const_cast<T5&>(arg5_), arg5);
427  }
428  template <class B>
429  Args5(typename EnableIf<IsSame<typename RemoveCv<B>::type, None>::value, const FUNC&>::type
430  func_,
431  const T1& arg1_, const T2& arg2_, const T3& arg3_, const T4& arg4_, const T5& arg5_,
432  B b)
433  : BaseType(func_, arg1_, arg2_, arg3_, arg4_, b), arg5(arg5_) {}
434  T5_ arg5;
435  };
436 #undef NLIB_THFUNC_USESWAP_NO
437 #undef NLIB_THFUNC_USESWAP_YES
438 
439  template <class FUNC>
440  struct ThreadFuncX0 : public Args0<FUNC> {
441  typedef ThreadFuncX0<FUNC> ThisType;
442  typedef Args0<FUNC> BaseType;
443  template <class B>
444  ThreadFuncX0(const FUNC& func_, B b)
445  : BaseType(func_, b) {}
446  explicit ThreadFuncX0(const FUNC& func_) : BaseType(func_, None()) {}
447  static void Call(UniquePtr<ThisType>& ptr) { // NOLINT
448  ptr->func();
449  }
450  };
451  template <class FUNC, class T1>
452  struct ThreadFuncX1 : public Args1<FUNC, T1> {
453  typedef ThreadFuncX1<FUNC, T1> ThisType;
454  typedef Args1<FUNC, T1> BaseType;
455  template <class B>
456  ThreadFuncX1(const FUNC& func_, const T1& arg1_, B b)
457  : BaseType(func_, arg1_, b) {}
458  ThreadFuncX1(const FUNC& func_, const T1& arg1_) : BaseType(func_, arg1_, None()) {}
459  static void Call(UniquePtr<ThisType>& ptr) { // NOLINT
460  ptr->func(NLIB_MOVE(ptr->arg1));
461  }
462  };
463  template <class FUNC, class T1, class T2>
464  struct ThreadFuncX2 : public Args2<FUNC, T1, T2> {
465  typedef ThreadFuncX2<FUNC, T1, T2> ThisType;
466  typedef Args2<FUNC, T1, T2> BaseType;
467  template <class B>
468  ThreadFuncX2(const FUNC& func_, const T1& arg1_, const T2& arg2_, B b)
469  : BaseType(func_, arg1_, arg2_, b) {}
470  ThreadFuncX2(const FUNC& func_, const T1& arg1_, const T2& arg2_)
471  : BaseType(func_, arg1_, arg2_, None()) {}
472  static void Call(UniquePtr<ThisType>& ptr) { // NOLINT
473  ptr->func(NLIB_MOVE(ptr->arg1), NLIB_MOVE(ptr->arg2));
474  }
475  };
476  template <class FUNC, class T1, class T2, class T3>
477  struct ThreadFuncX3 : public Args3<FUNC, T1, T2, T3> {
478  typedef ThreadFuncX3<FUNC, T1, T2, T3> ThisType;
479  typedef Args3<FUNC, T1, T2, T3> BaseType;
480  template <class B>
481  ThreadFuncX3(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_, B b)
482  : BaseType(func_, arg1_, arg2_, arg3_, b) {}
483  ThreadFuncX3(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_)
484  : BaseType(func_, arg1_, arg2_, arg3_, None()) {}
485  static void Call(UniquePtr<ThisType>& ptr) { // NOLINT
486  ptr->func(NLIB_MOVE(ptr->arg1), NLIB_MOVE(ptr->arg2), NLIB_MOVE(ptr->arg3));
487  }
488  };
489  template <class FUNC, class T1, class T2, class T3, class T4>
490  struct ThreadFuncX4 : public Args4<FUNC, T1, T2, T3, T4> {
491  typedef ThreadFuncX4<FUNC, T1, T2, T3, T4> ThisType;
492  typedef Args4<FUNC, T1, T2, T3, T4> BaseType;
493  template <class B>
494  ThreadFuncX4(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_,
495  const T4& arg4_, B b)
496  : BaseType(func_, arg1_, arg2_, arg3_, arg4_, b) {}
497  ThreadFuncX4(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_,
498  const T4& arg4_)
499  : BaseType(func_, arg1_, arg2_, arg3_, arg4_, None()) {}
500  static void Call(UniquePtr<ThisType>& ptr) { // NOLINT
501  ptr->func(NLIB_MOVE(ptr->arg1), NLIB_MOVE(ptr->arg2), NLIB_MOVE(ptr->arg3),
502  NLIB_MOVE(ptr->arg4));
503  }
504  };
505  template <class FUNC, class T1, class T2, class T3, class T4, class T5>
506  struct ThreadFuncX5 : public Args5<FUNC, T1, T2, T3, T4, T5> {
507  typedef ThreadFuncX5<FUNC, T1, T2, T3, T4, T5> ThisType;
508  typedef Args5<FUNC, T1, T2, T3, T4, T5> BaseType;
509  template <class B>
510  ThreadFuncX5(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_,
511  const T4& arg4_, const T5& arg5_, B b)
512  : BaseType(func_, arg1_, arg2_, arg3_, arg4_, arg5_, b) {}
513  ThreadFuncX5(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_,
514  const T4& arg4_, const T5& arg5_)
515  : BaseType(func_, arg1_, arg2_, arg3_, arg4_, arg5_, None()) {}
516  static void Call(UniquePtr<ThisType>& ptr) { // NOLINT
517  ptr->func(NLIB_MOVE(ptr->arg1), NLIB_MOVE(ptr->arg2), NLIB_MOVE(ptr->arg3),
518  NLIB_MOVE(ptr->arg4), NLIB_MOVE(ptr->arg5));
519  }
520  };
521 
522  public:
523  template <class FUNC>
524  errno_t Start(const ThreadSettings& settings, const FUNC& f, move_tag) {
526  new (std::nothrow) ThreadFuncX0<FUNC>(f, typename IsSwappable<FUNC>::type()));
527  if (!ptr) return ENOMEM;
528  return this->StartRaw(settings, ptr);
529  }
530  template <class FUNC>
531  errno_t Start(const FUNC& f, move_tag) {
532  ThreadSettings settings;
533  return this->Start(settings, f, move_tag());
534  }
535  template <class FUNC, class T1>
536  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, move_tag) {
538  new (std::nothrow) ThreadFuncX1<FUNC, T1>(f, arg1, typename ArgType<T1>::type()));
539  if (!ptr) return ENOMEM;
540  return this->StartRaw(settings, ptr);
541  }
542  template <class FUNC, class T1>
543  errno_t Start(const FUNC& f, const T1& arg1, move_tag) {
544  ThreadSettings settings;
545  return this->Start(settings, f, arg1, move_tag());
546  }
547  template <class FUNC, class T1, class T2>
548  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, const T2& arg2,
549  move_tag) {
550  UniquePtr<ThreadFuncX2<FUNC, T1, T2> > ptr(new (std::nothrow) ThreadFuncX2<FUNC, T1, T2>(
551  f, arg1, arg2, typename ArgType<T2>::type()));
552  if (!ptr) return ENOMEM;
553  return this->StartRaw(settings, ptr);
554  }
555  template <class FUNC, class T1, class T2>
556  errno_t Start(const FUNC& f, const T1& arg1, const T2& arg2, move_tag) {
557  ThreadSettings settings;
558  return this->Start(settings, f, arg1, arg2, move_tag());
559  }
560  template <class FUNC, class T1, class T2, class T3>
561  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, const T2& arg2,
562  const T3& arg3, move_tag) {
564  new (std::nothrow)
565  ThreadFuncX3<FUNC, T1, T2, T3>(f, arg1, arg2, arg3, typename ArgType<T3>::type()));
566  if (!ptr) return ENOMEM;
567  return this->StartRaw(settings, ptr);
568  }
569  template <class FUNC, class T1, class T2, class T3>
570  errno_t Start(const FUNC& f, const T1& arg1, const T2& arg2, const T3& arg3, move_tag) {
571  ThreadSettings settings;
572  return this->Start(settings, f, arg1, arg2, arg3, move_tag());
573  }
574  template <class FUNC, class T1, class T2, class T3, class T4>
575  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, const T2& arg2,
576  const T3& arg3, const T4& arg4, move_tag) {
578  new (std::nothrow) ThreadFuncX4<FUNC, T1, T2, T3, T4>(f, arg1, arg2, arg3, arg4,
579  typename ArgType<T4>::type()));
580  if (!ptr) return ENOMEM;
581  return this->StartRaw(settings, ptr);
582  }
583  template <class FUNC, class T1, class T2, class T3, class T4>
584  errno_t Start(const FUNC& f, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4,
585  move_tag) {
586  ThreadSettings settings;
587  return this->Start(settings, f, arg1, arg2, arg3, arg4, move_tag());
588  }
589  template <class FUNC, class T1, class T2, class T3, class T4, class T5>
590  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, const T2& arg2,
591  const T3& arg3, const T4& arg4, const T5& arg5, move_tag) {
593  new (std::nothrow) ThreadFuncX5<FUNC, T1, T2, T3, T4, T5>(
594  f, arg1, arg2, arg3, arg4, arg5, typename ArgType<T5>::type()));
595  if (!ptr) return ENOMEM;
596  return this->StartRaw(settings, ptr);
597  }
598  template <class FUNC, class T1, class T2, class T3, class T4, class T5>
599  errno_t Start(const FUNC& f, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4,
600  const T5& arg5, move_tag) {
601  ThreadSettings settings;
602  return this->Start(settings, f, arg1, arg2, arg3, arg4, arg5, move_tag());
603  }
604  template <class FUNC>
605  errno_t Start(const ThreadSettings& settings, const FUNC& f) {
606  UniquePtr<ThreadFuncX0<FUNC> > ptr(new (std::nothrow) ThreadFuncX0<FUNC>(f));
607  if (!ptr) return ENOMEM;
608  return this->StartRaw(settings, ptr);
609  }
610  template <class FUNC>
611  errno_t Start(const FUNC& f) {
612  ThreadSettings settings;
613  return this->Start(settings, f);
614  }
615  template <class FUNC, class T1>
616  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1) {
617  UniquePtr<ThreadFuncX1<FUNC, T1> > ptr(new (std::nothrow) ThreadFuncX1<FUNC, T1>(f, arg1));
618  if (!ptr) return ENOMEM;
619  return this->StartRaw(settings, ptr);
620  }
621  template <class FUNC, class T1>
622  errno_t Start(const FUNC& f, const T1& arg1) {
623  ThreadSettings settings;
624  return this->Start(settings, f, arg1);
625  }
626  template <class FUNC, class T1, class T2>
627  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, const T2& arg2) {
628  UniquePtr<ThreadFuncX2<FUNC, T1, T2> > ptr(new (std::nothrow)
629  ThreadFuncX2<FUNC, T1, T2>(f, arg1, arg2));
630  if (!ptr) return ENOMEM;
631  return this->StartRaw(settings, ptr);
632  }
633  template <class FUNC, class T1, class T2>
634  errno_t Start(const FUNC& f, const T1& arg1, const T2& arg2) {
635  ThreadSettings settings;
636  return this->Start(settings, f, arg1, arg2);
637  }
638  template <class FUNC, class T1, class T2, class T3>
639  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, const T2& arg2,
640  const T3& arg3) {
642  new (std::nothrow) ThreadFuncX3<FUNC, T1, T2, T3>(f, arg1, arg2, arg3));
643  if (!ptr) return ENOMEM;
644  return this->StartRaw(settings, ptr);
645  }
646  template <class FUNC, class T1, class T2, class T3>
647  errno_t Start(const FUNC& f, const T1& arg1, const T2& arg2, const T3& arg3) {
648  ThreadSettings settings;
649  return this->Start(settings, f, arg1, arg2, arg3);
650  }
651  template <class FUNC, class T1, class T2, class T3, class T4>
652  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, const T2& arg2,
653  const T3& arg3, const T4& arg4) {
655  new (std::nothrow) ThreadFuncX4<FUNC, T1, T2, T3, T4>(f, arg1, arg2, arg3, arg4));
656  if (!ptr) return ENOMEM;
657  return this->StartRaw(settings, ptr);
658  }
659  template <class FUNC, class T1, class T2, class T3, class T4>
660  errno_t Start(const FUNC& f, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4) {
661  ThreadSettings settings;
662  return this->Start(settings, f, arg1, arg2, arg3, arg4);
663  }
664  template <class FUNC, class T1, class T2, class T3, class T4, class T5>
665  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, const T2& arg2,
666  const T3& arg3, const T4& arg4, const T5& arg5) {
668  std::nothrow) ThreadFuncX5<FUNC, T1, T2, T3, T4, T5>(f, arg1, arg2, arg3, arg4, arg5));
669  if (!ptr) return ENOMEM;
670  return this->StartRaw(settings, ptr);
671  }
672  template <class FUNC, class T1, class T2, class T3, class T4, class T5>
673  errno_t Start(const FUNC& f, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4,
674  const T5& arg5) {
675  ThreadSettings settings;
676  return this->Start(settings, f, arg1, arg2, arg3, arg4, arg5);
677  }
678 
679  private:
680  nlib_thread m_ThreadId;
682 };
683 
684 #ifdef _MSC_VER
685 #pragma warning(pop)
686 #endif
687 
688 template <>
689 struct Thread::Args0<void()> {
690  template <class X>
691  Args0(void (*func_)(), X)
692  : func(func_) {}
693  Args0(void (*func_)()) : func(func_) {}
694  void (*func)();
695 
696  private:
698 };
699 
700 template <class T1>
701 struct Thread::Args0<void(T1)> {
702  template <class X>
703  Args0(void (*func_)(T1), X)
704  : func(func_) {}
705  Args0(void (*func_)(T1)) : func(func_) {}
706  void (*func)(T1);
707 
708  private:
710 };
711 
712 template <class T1, class T2>
713 struct Thread::Args0<void(T1, T2)> {
714  template <class X>
715  Args0(void (*func_)(T1, T2), X)
716  : func(func_) {}
717  Args0(void (*func_)(T1, T2)) : func(func_) {}
718  void (*func)(T1, T2);
719 
720  private:
722 };
723 
724 template <class T1, class T2, class T3>
725 struct Thread::Args0<void(T1, T2, T3)> {
726  template <class X>
727  Args0(void (*func_)(T1, T2, T3), X)
728  : func(func_) {}
729  Args0(void (*func_)(T1, T2, T3)) : func(func_) {}
730  void (*func)(T1, T2, T3);
731 
732  private:
734 };
735 
736 template <class T1, class T2, class T3, class T4>
737 struct Thread::Args0<void(T1, T2, T3, T4)> {
738  template <class X>
739  Args0(void (*func_)(T1, T2, T3, T4), X)
740  : func(func_) {}
741  Args0(void (*func_)(T1, T2, T3, T4)) : func(func_) {}
742  void (*func)(T1, T2, T3, T4);
743 
744  private:
746 };
747 
748 template <class T1, class T2, class T3, class T4, class T5>
749 struct Thread::Args0<void(T1, T2, T3, T4, T5)> {
750  template <class X>
751  Args0(void (*func_)(T1, T2, T3, T4, T5), X)
752  : func(func_) {}
753  Args0(void (*func_)(T1, T2, T3, T4, T5)) : func(func_) {}
754  void (*func)(T1, T2, T3, T4, T5);
755 
756  private:
758 };
759 
760 inline size_t GetHardwareConcurrency() NLIB_NOEXCEPT {
761  unsigned int numCpu;
762  (void)nlib_thread_getconcurrency(&numCpu);
763  return numCpu;
764 }
765 
766 namespace this_thread {
767 inline errno_t YieldThread() NLIB_NOEXCEPT { return nlib_yield(); }
768 inline errno_t Sleep(const TimeSpan& span) NLIB_NOEXCEPT {
770 }
771 inline errno_t SleepMilliSeconds(unsigned int millisec) NLIB_NOEXCEPT {
772  return Sleep(TimeSpan(0, 0, millisec));
773 }
774 inline nlib_thread_id GetId() NLIB_NOEXCEPT {
775  nlib_thread_id id;
776  errno_t e = nlib_thread_getid(&id);
777  return e == 0 ? id : -1;
778 }
779 inline errno_t GetCpu(int* cpuid) NLIB_NOEXCEPT { return nlib_thread_getcpu(cpuid); }
780 inline errno_t SetName(const char* literalString) NLIB_NOEXCEPT {
781  return nlib_thread_setname(literalString);
782 }
785 
786 } // namespace this_thread
787 
788 } // namespace threading
789 NLIB_NAMESPACE_END
790 
791 NLIB_DEFINE_STD_SWAP(::nlib_ns::threading::Thread)
792 
793 #endif // INCLUDE_NN_NLIB_THREADING_THREAD_H_
errno_t GetCpu(int *cpuid) noexcept
呼び出したスレッドが実行されているCPUを取得します。
Definition: Thread.h:779
errno_t YieldThread() noexcept
他のスレッドに制御を譲ります。
Definition: Thread.h:767
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Platform.h:2151
errno_t Start(const ThreadSettings &settings, const FUNC &f, move_tag)
スレッドの起動オプションを指定できること以外はそうでないバージョンと同じです。
Definition: Thread.h:524
errno_t Start(const FUNC &f, const T1 &arg1, const T2 &arg2, move_tag)
引数を2つもつ関数を別スレッドで実行開始します。 引数を2つ持つこと以外は、引数が1つのバージョンと同じ...
Definition: Thread.h:556
static errno_t Sleep(const TimeSpan &span) noexcept
span の期間だけスリープします。
Definition: Thread.h:251
int nlib_thread_equal(nlib_thread th1, nlib_thread th2)
2つのスレッドが同一スレッドを指すかどうかチェックします。
constexpr Thread() noexcept
デフォルトコンストラクタです。
Definition: Thread.h:202
errno_t Sleep(const TimeSpan &span) noexcept
スリープします。
Definition: Thread.h:768
constexpr ThreadArg(Func func_, T1 arg1_, T2 arg2_, T3 arg3_, T4 arg4_, T5 arg5_)
コンストラクタで構造体のフィールドを初期化します。
Definition: Thread.h:110
C++11の標準ヘッダとなるtype_traitsの代用定義です。 コンパイラや標準ライブラリによってサポートされてい...
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3)
スレッドの起動オプションを指定できること以外はそうでないバージョンと同じです。
Definition: Thread.h:639
bool operator!=(const Thread &rhs) noexcept
nlib_thread_equal()を用いてスレッドを比較します。
Definition: Thread.h:246
constexpr ThreadArg()
デフォルトコンストラクタです。
Definition: Thread.h:109
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:126
T1 arg1
別スレッドで実行する関数に渡されるオブジェクトです。
Definition: Thread.h:115
errno_t Detach() noexcept
スレッドをデタッチします。
Definition: Thread.h:223
Func func
別スレッドで実行する関数へのポインタです。
Definition: Thread.h:114
errno_t nlib_thread_setaffinity(nlib_thread thread, uint32_t affinity)
指定されたスレッドのプロセッサアフィニティマスクを設定します。
errno_t GetPriority(int32_t *priority) noexcept
スレッドの優先度を取得します。
Definition: Thread.h:229
nlib_thread GetNativeHandle() const noexcept
実装依存のスレッド識別子を取得します。
Definition: Thread.h:238
T3 arg3
別スレッドで実行する関数に渡されるオブジェクトです。
Definition: Thread.h:117
errno_t Start(const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4, const T5 &arg5, move_tag)
引数を5つもつ関数を別スレッドで実行開始します。引数を5つ持つこと以外は、引数が1つのバージョンと同じで...
Definition: Thread.h:599
~Thread() noexcept
デストラクタです。スレッドがJoinされていない場合はJoinします。
Definition: Thread.h:203
struct nlib_thread_attr_ nlib_thread_attr
新しく作られるスレッドに適用されるスレッド属性
Definition: Platform.h:849
errno_t ChangePriority(int32_t priority) noexcept
スレッドの優先度を設定します。
Definition: Thread.h:232
T5 arg5
別スレッドで実行する関数に渡されるオブジェクトです。
Definition: Thread.h:119
void SetDetachState(bool detached) noexcept
デタッチした状態でスレッドを起動するかどうかを設定します。
Definition: Thread.h:26
errno_t Start(const FUNC &f, const T1 &arg1, const T2 &arg2)
引数を2つもつ関数を別スレッドで実行開始します。引数を2つ持つこと以外は、引数が1つのバージョンと同じで...
Definition: Thread.h:634
errno_t Start(const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3)
引数を3つもつ関数を別スレッドで実行開始します。引数を3つ持つこと以外は、引数が1つのバージョンと同じで...
Definition: Thread.h:647
UniquePtrはポインタの所有権を保持し、UniquePtrがスコープから出るときにデストラクタでポインタをDELで指...
Definition: UniquePtr.h:96
errno_t Start(const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4, const T5 &arg5)
引数を5つもつ関数を別スレッドで実行開始します。引数を5つ持つこと以外は、引数が1つのバージョンと同じで...
Definition: Thread.h:673
std::unique_ptrに相当するクラスが定義されています。
スレッドの生成・開始を行うためのクラスです。
Definition: Thread.h:199
errno_t nlib_thread_getid(nlib_thread_id *id)
実行中のスレッドに対応する一意の整数値を格納する。
Threadクラスでスレッドを実行するために利用できる構造体です。
Definition: Thread.h:105
void swap(Thread &rhs) noexcept
オブジェクトの内容をスワップします。
Definition: Thread.h:239
errno_t Start(const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, move_tag)
引数を3つもつ関数を別スレッドで実行開始します。 引数を3つ持つこと以外は、引数が1つのバージョンと同じ...
Definition: Thread.h:570
errno_t nlib_thread_attr_setint(nlib_thread_attr *attr, int key, int value)
スレッドの属性オブジェクトのキーに対応する整数を設定する。
errno_t nlib_thread_getconcurrency(unsigned int *num_cpu)
ハードウェアスレッドの数を取得します。
errno_t SetStackSize(int size) noexcept
スタックサイズを設定します。
Definition: Thread.h:46
errno_t Start(const FUNC &f, const T1 &arg1, move_tag)
引数を1つもつ関数を別スレッドで実行開始します。
Definition: Thread.h:543
errno_t StartRaw(UniquePtr< ThArg > &ptr) noexcept
別スレッドの実行を開始します。
Definition: Thread.h:274
errno_t nlib_yield(void)
スレッドの実行権を手放す。
int GetPriority() const noexcept
スレッドの優先度を取得します。
Definition: Thread.h:73
nlib_thread_attrをラップするクラスです。必要に応じて自動的にnlib_thread_attr_init()とnlib_thread_attr...
Definition: Thread.h:16
errno_t StartRaw(const ThreadSettings &settings, UniquePtr< ThArg > &ptr) noexcept
別スレッドの実行を開始します。
Definition: Thread.h:265
static errno_t YieldThread() noexcept
nlib_yield()を呼び出します。
Definition: Thread.h:250
errno_t Join() noexcept
スレッドの実行完了を待ちます。
Definition: Thread.h:213
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, move_tag)
スレッドの起動オプションを指定できること以外はそうでないバージョンと同じです。
Definition: Thread.h:561
空の構造体で、関数の引数をムーブすべきことを示すために利用されます。
Definition: Config.h:219
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1)
スレッドの起動オプションを指定できること以外はそうでないバージョンと同じです。
Definition: Thread.h:616
bool operator==(const Thread &rhs) noexcept
nlib_thread_equal()を用いてスレッドを比較します。
Definition: Thread.h:243
bool GetDetachState() const noexcept
デタッチ状態でスレッドを起動する設定かどうかを返します。
Definition: Thread.h:35
errno_t nlib_thread_attr_destroy(nlib_thread_attr *attr)
スレッド初期化オブジェクトを破壊します。
errno_t Start(const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4)
引数を4つもつ関数を別スレッドで実行開始します。引数を4つ持つこと以外は、引数が1つのバージョンと同じで...
Definition: Thread.h:660
errno_t Start(const FUNC &f, const T1 &arg1)
引数を1つもつ関数を別スレッドで実行開始します。
Definition: Thread.h:622
int GetStackSize() const noexcept
設定されているスタックサイズを返します。
Definition: Thread.h:54
#define NLIB_THREAD_INVALID
無効なスレッドを指し示す値
Definition: Platform.h:834
errno_t nlib_thread_attr_getint(const nlib_thread_attr *attr, int key, int *value)
スレッドの属性オブジェクトのキーに対応する整数を取得する。
errno_t Start(const ThreadSettings &settings, const FUNC &f)
スレッドの起動オプションを指定できること以外はそうでないバージョンと同じです。
Definition: Thread.h:605
errno_t SetPriority(int priority) noexcept
スレッドの優先度を設定します。優先度の値はプラットフォーム依存です。
Definition: Thread.h:65
時刻や時間を扱うためのクラスが定義されています。
nlib_thread_id GetId() noexcept
カレントスレッドのIDを取得します。
Definition: Thread.h:774
errno_t nlib_thread_attr_init(nlib_thread_attr *attr)
スレッド属性オブジェクトを初期化して、デフォルトに設定する。
開発環境別の設定が書かれるファイルです。
errno_t nlib_sleep(nlib_duration t)
t の間スリープする。
errno_t Start(const FUNC &f)
引数を持たない関数を別スレッドで実行開始します。
Definition: Thread.h:611
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4)
スレッドの起動オプションを指定できること以外はそうでないバージョンと同じです。
Definition: Thread.h:652
errno_t nlib_thread_setpriority(nlib_thread thread, int priority)
スレッドの実行優先度を設定します。数値の意味は実装依存です。
int nlib_thread_id
スレッド毎にユニークな整数値
Definition: Platform.h:859
size_t GetHardwareConcurrency() noexcept
ハードウェアスレッドの数を返します。
Definition: Thread.h:760
errno_t SetAffinity(uint32_t affinity) noexcept
スレッドのプロセッサアフィニティマスクを設定します。
Definition: Thread.h:235
errno_t SetName(const char *literalString) noexcept
スレッドに名前をつけます。
Definition: Thread.h:780
errno_t nlib_thread_join(nlib_thread thread)
スレッドの終了を待ちます。
ThreadArg< T1, T2, T3, T4, T5 > ThisType
この構造体の型へのtypedefです。
Definition: Thread.h:106
errno_t StartRaw(const ThreadSettings &settings, ThreadArg<>::Func func) noexcept
引数を持たない関数を別スレッドで実行開始します。
Definition: Thread.h:256
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:51
UniquePtr< ThisType > ArgType
スレッド関数の引数型のtypedefです。
Definition: Thread.h:107
bool IsJoinable() const noexcept
join可能かどうか調べます。
Definition: Thread.h:228
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4, move_tag)
スレッドの起動オプションを指定できること以外はそうでないバージョンと同じです。
Definition: Thread.h:575
errno_t nlib_thread_detach(nlib_thread thread)
実行中のスレッドをデタッチ状態にします。
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4, const T5 &arg5)
スレッドの起動オプションを指定できること以外はそうでないバージョンと同じです。
Definition: Thread.h:665
errno_t nlib_thread_getcpu(int *result)
呼び出したスレッドが実行されているCPUを取得します。
errno_t nlib_thread_getpriority(nlib_thread thread, int *priority)
スレッドの現在の実行優先度を取得します。数値の意味は実装依存です。
時間を表すクラスです。
Definition: DateTime.h:93
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1, const T2 &arg2, move_tag)
スレッドの起動オプションを指定できること以外はそうでないバージョンと同じです。
Definition: Thread.h:548
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4, const T5 &arg5, move_tag)
スレッドの起動オプションを指定できること以外はそうでないバージョンと同じです。
Definition: Thread.h:590
errno_t SleepMilliSeconds(unsigned int millisec) noexcept
スリープします。
Definition: Thread.h:771
errno_t StartRaw(ThreadArg<>::Func func) noexcept
引数を持たない関数を別スレッドで実行開始します。
Definition: Thread.h:260
T4 arg4
別スレッドで実行する関数に渡されるオブジェクトです。
Definition: Thread.h:118
errno_t GetPriority(int32_t *priority) noexcept
nlib_thread_getpriority()を呼び出して、スレッドの実行優先順位を取得します。
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1, move_tag)
スレッドの起動オプションを指定できること以外はそうでないバージョンと同じです。
Definition: Thread.h:536
errno_t nlib_thread_setname(const char *string_literal)
スレッドに名前をつけます。
T2 arg2
別スレッドで実行する関数に渡されるオブジェクトです。
Definition: Thread.h:116
pthread_t nlib_thread
スレッドを指し示す識別子
errno_t Start(const FUNC &f, move_tag)
引数を持たない関数を別スレッドで実行開始します。 引数を持たないこと以外は、引数が1つのバージョンと同...
Definition: Thread.h:531
errno_t Start(const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4, move_tag)
引数を4つもつ関数を別スレッドで実行開始します。 引数を4つ持つこと以外は、引数が1つのバージョンと同じ...
Definition: Thread.h:584
errno_t ChangePriority(int32_t priority) noexcept
nlib_thread_setpriority()を呼び出して、スレッドの実行優先順位を設定します。
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1, const T2 &arg2)
スレッドの起動オプションを指定できること以外はそうでないバージョンと同じです。
Definition: Thread.h:627
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:24