nlib
Thread.h
Go to the documentation of this file.
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_THREADING_THREAD_H_
17 #define INCLUDE_NN_NLIB_THREADING_THREAD_H_
18 
19 #include "nn/nlib/Config.h"
20 #include "nn/nlib/Swap.h"
21 #include "nn/nlib/UniquePtr.h"
22 #include "nn/nlib/TypeTraits.h"
23 #include "nn/nlib/DateTime.h"
24 
25 NLIB_NAMESPACE_BEGIN
26 namespace threading {
27 struct None {};
28 
30  public:
31  ThreadSettings() NLIB_NOEXCEPT : is_initialized_(false) {}
33  if (is_initialized_) {
35  NLIB_ASSERT_NOERR(e);
36  NLIB_UNUSED(e);
37  }
38  }
39  void SetDetachState(bool detached) NLIB_NOEXCEPT {
40  this->Init_();
42  &attr_,
43  NLIB_THREAD_ATTR_KEY_DETACHSTATE,
44  detached ? 1 : 0);
45  NLIB_ASSERT_NOERR(e);
46  NLIB_UNUSED(e);
47  }
49  this->Init_();
50  int detached;
52  &attr_,
53  NLIB_THREAD_ATTR_KEY_DETACHSTATE,
54  &detached);
55  NLIB_ASSERT_NOERR(e);
56  NLIB_UNUSED(e);
57  return (detached != 0);
58  }
60  this->Init_();
62  &attr_,
63  NLIB_THREAD_ATTR_KEY_STACKSIZE,
64  size);
65  return e;
66  }
68  this->Init_();
69  int size;
71  &attr_,
72  NLIB_THREAD_ATTR_KEY_STACKSIZE,
73  &size);
74  NLIB_ASSERT_NOERR(e);
75  NLIB_UNUSED(e);
76  return size;
77  }
79  this->Init_();
81  &attr_,
82  NLIB_THREAD_ATTR_KEY_PRIORITY,
83  priority);
84  return e;
85  }
86  int GetPriority() const NLIB_NOEXCEPT {
87  this->Init_();
88  int priority;
90  &attr_,
91  NLIB_THREAD_ATTR_KEY_PRIORITY,
92  &priority);
93  NLIB_ASSERT_NOERR(e);
94  NLIB_UNUSED(e);
95  return priority;
96  }
98  return is_initialized_ ? &attr_ : NULL;
99  }
100  const nlib_thread_attr* GetPtr() const NLIB_NOEXCEPT {
101  return is_initialized_ ? &attr_ : NULL;
102  }
103 
104  private:
105  void Init_() const NLIB_NOEXCEPT {
106  if (!is_initialized_) {
107  errno_t e = nlib_thread_attr_init(&attr_);
108  NLIB_ASSERT_NOERR(e);
109  NLIB_UNUSED(e);
110  is_initialized_ = true;
111  }
112  }
113  mutable bool is_initialized_;
114  mutable nlib_thread_attr attr_;
115 };
116 
117 template <class T1 = None, class T2 = None, class T3 = None, class T4 = None, class T5 = None>
118 struct ThreadArg {
121  typedef void (*Func)(ArgType& ptr); // NOLINT
122  NLIB_CEXPR ThreadArg() : func(NULL), arg1(), arg2(), arg3(), arg4(), arg5() {}
123  NLIB_CEXPR ThreadArg(Func func_, T1 arg1_, T2 arg2_, T3 arg3_, T4 arg4_, T5 arg5_)
124  : func(func_), arg1(arg1_), arg2(arg2_), arg3(arg3_), arg4(arg4_), arg5(arg5_) {}
125  static void Call(ArgType& ptr) { ptr->func(ptr); } // NOLINT
126  public:
127  Func func;
128  T1 arg1;
129  T2 arg2;
130  T3 arg3;
131  T4 arg4;
132  T5 arg5;
133 };
134 
135 template <>
136 struct ThreadArg<None, None, None, None, None> {
137  typedef ThreadArg<> ThisType;
138  typedef void ArgType;
139  typedef void (*Func)();
140 };
141 
142 template <class T1>
143 struct ThreadArg<T1, None, None, None, None> {
144  typedef ThreadArg<T1> ThisType;
146  typedef void (*Func)(ArgType& ptr); // NOLINT
147  NLIB_CEXPR ThreadArg() : func(NULL), arg1() {}
148  NLIB_CEXPR ThreadArg(Func func_, T1 arg1_) : func(func_), arg1(arg1_) {}
149  static void Call(ArgType& ptr) { ptr->func(ptr); } // NOLINT
150  public:
151  Func func;
152  T1 arg1;
153 };
154 
155 template <class T1, class T2>
156 struct ThreadArg<T1, T2, None, None, None> {
157  typedef ThreadArg<T1, T2> ThisType;
159  typedef void (*Func)(ArgType& ptr); // NOLINT
160  NLIB_CEXPR ThreadArg() : func(NULL), arg1(), arg2() {}
161  NLIB_CEXPR ThreadArg(Func func_, T1 arg1_, T2 arg2_) : func(func_), arg1(arg1_), arg2(arg2_) {}
162  static void Call(ArgType& ptr) { ptr->func(ptr); } // NOLINT
163  public:
164  Func func;
165  T1 arg1;
166  T2 arg2;
167 };
168 
169 template <class T1, class T2, class T3>
170 struct ThreadArg<T1, T2, T3, None, None> {
173  typedef void (*Func)(ArgType& ptr); // NOLINT
174  NLIB_CEXPR ThreadArg() : func(NULL), arg1(), arg2(), arg3() {}
175  NLIB_CEXPR ThreadArg(Func func_, T1 arg1_, T2 arg2_, T3 arg3_)
176  : func(func_), arg1(arg1_), arg2(arg2_), arg3(arg3_) {}
177  static void Call(ArgType& ptr) { ptr->func(ptr); } // NOLINT
178  public:
179  Func func;
180  T1 arg1;
181  T2 arg2;
182  T3 arg3;
183 };
184 
185 template <class T1, class T2, class T3, class T4>
186 struct ThreadArg<T1, T2, T3, T4, None> {
189  typedef void (*Func)(ArgType& ptr); // NOLINT
190  NLIB_CEXPR ThreadArg() : func(NULL), arg1(), arg2(), arg3(), arg4() {}
191  NLIB_CEXPR ThreadArg(Func func_, T1 arg1_, T2 arg2_, T3 arg3_, T4 arg4_)
192  : func(func_), arg1(arg1_), arg2(arg2_), arg3(arg3_), arg4(arg4_) {}
193  static void Call(ArgType& ptr) { ptr->func(ptr); } // NOLINT
194  public:
195  Func func;
196  T1 arg1;
197  T2 arg2;
198  T3 arg3;
199  T4 arg4;
200 };
201 
202 #ifdef _MSC_VER
203 #pragma warning(push)
204 #pragma warning(disable : 4180)
205 #endif
206 
207 // code snippets:
208 // Thread th;
209 // void func(...) {}
210 // th.Start(func, ...); # to create a thread and run func() on it
211 // th.Join(); # or th.Detach();
213  public:
214  typedef void (*ThreadFunc)(void* arg);
217  if (thread_id_ != NLIB_THREAD_INVALID) this->Join();
218  }
219  NLIB_MOVE_MEMBER_HELPER_1(Thread, thread_id_)
220  errno_t StartRaw(ThreadFunc func, void* arg) NLIB_NOEXCEPT;
221  errno_t StartRaw(ThreadFunc func, void* arg, const ThreadSettings& settings) NLIB_NOEXCEPT;
222  errno_t Join() NLIB_NOEXCEPT {
223  if (!thread_id_) return ESRCH;
224  errno_t e = nlib_thread_join(thread_id_);
225  if (e == 0) {
226  thread_id_ = NLIB_THREAD_INVALID;
227  return 0;
228  } else {
229  return e;
230  }
231  }
232  errno_t Detach() NLIB_NOEXCEPT {
233  errno_t e = nlib_thread_detach(thread_id_);
234  if (e == 0) thread_id_ = NLIB_THREAD_INVALID;
235  return e;
236  }
237  bool IsJoinable() const NLIB_NOEXCEPT { return thread_id_ != NLIB_THREAD_INVALID; }
238  errno_t GetPriority(int32_t* priority) NLIB_NOEXCEPT {
239  return nlib_thread_getpriority(this->GetNativeHandle(), reinterpret_cast<int*>(priority));
240  }
241  errno_t ChangePriority(int32_t priority) NLIB_NOEXCEPT {
242  return nlib_thread_setpriority(this->GetNativeHandle(), priority);
243  }
244  errno_t SetAffinity(uint32_t affinity) NLIB_NOEXCEPT {
245  return nlib_thread_setaffinity(thread_id_, affinity);
246  }
247  nlib_thread GetNativeHandle() const NLIB_NOEXCEPT { return thread_id_; }
248  void swap(Thread& rhs) NLIB_NOEXCEPT { // NOLINT
249  using std::swap;
250  swap(thread_id_, rhs.thread_id_);
251  }
252  bool operator==(const Thread& rhs) NLIB_NOEXCEPT {
253  return nlib_thread_equal(thread_id_, rhs.thread_id_) ? true : false;
254  }
255  bool operator!=(const Thread& rhs) NLIB_NOEXCEPT {
256  return nlib_thread_equal(thread_id_, rhs.thread_id_) ? false : true;
257  }
258 
259  static errno_t YieldThread() NLIB_NOEXCEPT { return nlib_yield(); }
260  static errno_t Sleep(const TimeSpan& span) NLIB_NOEXCEPT {
261  return nlib_sleep(span.ToTimeValue().tick);
262  }
263 
264  public:
265  errno_t StartRaw(const ThreadSettings& settings, ThreadArg<>::Func func) NLIB_NOEXCEPT {
266  errno_t e = this->StartRaw(Thread::Exec, reinterpret_cast<void*>(func), settings);
267  return e;
268  }
269  errno_t StartRaw(ThreadArg<>::Func func) NLIB_NOEXCEPT {
270  errno_t e = this->StartRaw(Thread::Exec, reinterpret_cast<void*>(func));
271  return e;
272  }
273  template <class ThArg>
274  errno_t StartRaw(const ThreadSettings& settings,
275  UniquePtr<ThArg>& ptr) NLIB_NOEXCEPT { // NOLINT
276  if (!ptr) return EINVAL;
277  errno_t e = this->StartRaw((ThreadFunc)Thread::Exec<ThArg>, // NOLINT
278  reinterpret_cast<void*>(ptr.get()), settings);
279  if (e == 0) ptr.release();
280  return e;
281  }
282  template <class ThArg>
283  errno_t StartRaw(UniquePtr<ThArg>& ptr) NLIB_NOEXCEPT { // NOLINT
284  if (!ptr) return EINVAL;
285  errno_t e = this->StartRaw((ThreadFunc)Thread::Exec<ThArg>, // NOLINT
286  reinterpret_cast<void*>(ptr.get()));
287  if (e == 0) ptr.release();
288  return e;
289  }
290 
291  private:
292  static void Exec(void* p) {
293  ThreadArg<>::Func f = reinterpret_cast<ThreadArg<>::Func>(p);
294  f();
295  }
296  template <class T>
297  static void Exec(void* p) {
298  UniquePtr<T> args(reinterpret_cast<T*>(p));
299  T::Call(args);
300  }
301 
302 #define NLIB_THFUNC_USESWAP_NO(tp) \
303  typename EnableIf< \
304  !IsSame<None, typename RemoveCv<B>::type>::value && \
305  (IsSame<FalseType, typename RemoveCv<B>::type>::value || !IsSwappable<tp>::value), \
306  const tp&>::type
307 #define NLIB_THFUNC_USESWAP_YES(tp) \
308  typename EnableIf<!IsSame<None, typename RemoveCv<B>::type>::value && \
309  IsSame<TrueType, typename RemoveCv<B>::type>::value && \
310  IsSwappable<tp>::value, \
311  const tp&>::type
312 
313  template <class T>
314  struct ArgType : public Conditional<
315  IsArithmetic<T>::value || IsPointer<T>::value || IsMemberPointer<T>::value,
316  FalseType, TrueType> {};
317 
318  template <class FUNC>
319  struct Args0 {
320  typedef typename RemoveRef<FUNC>::type FUNC_;
321  template <class B>
322  Args0(NLIB_THFUNC_USESWAP_NO(FUNC_) func_, B)
323  : func(func_) {}
324  template <class B>
325  Args0(NLIB_THFUNC_USESWAP_YES(FUNC_) func_, B)
326  : func() {
327  using std::swap;
328  swap(const_cast<FUNC&>(func_), func);
329  }
330  template <class B>
331  Args0(typename EnableIf<IsSame<typename RemoveCv<B>::type, None>::value, const FUNC&>::type
332  func_,
333  B)
334  : func(func_) {}
335  FUNC_ func;
336 
337  private:
339  };
340  template <class FUNC, class T1>
341  struct Args1 : public Args0<FUNC> {
342  typedef Args0<FUNC> BaseType;
343  typedef typename RemoveRef<T1>::type T1_;
344  template <class B>
345  Args1(const FUNC& func_, NLIB_THFUNC_USESWAP_NO(T1) arg1_, B)
346  : BaseType(func_, typename IsSwappable<FUNC>::type()), arg1(arg1_) {}
347  template <class B>
348  Args1(const FUNC& func_, NLIB_THFUNC_USESWAP_YES(T1) arg1_, B)
349  : BaseType(func_, typename IsSwappable<FUNC>::type()), arg1() {
350  using std::swap;
351  swap(const_cast<T1&>(arg1_), arg1);
352  }
353  template <class B>
354  Args1(typename EnableIf<IsSame<typename RemoveCv<B>::type, None>::value, const FUNC&>::type
355  func_,
356  const T1& arg1_, B b)
357  : BaseType(func_, b), arg1(arg1_) {}
358  T1_ arg1;
359  };
360  template <class FUNC, class T1, class T2>
361  struct Args2 : public Args1<FUNC, T1> {
362  typedef Args1<FUNC, T1> BaseType;
363  typedef typename RemoveRef<T2>::type T2_;
364  template <class B>
365  Args2(const FUNC& func_, const T1& arg1_, NLIB_THFUNC_USESWAP_NO(T2) arg2_, B)
366  : BaseType(func_, arg1_, typename ArgType<T1>::type()), arg2(arg2_) {}
367  template <class B>
368  Args2(const FUNC& func_, const T1& arg1_, NLIB_THFUNC_USESWAP_YES(T2) arg2_, B)
369  : BaseType(func_, arg1_, typename ArgType<T1>::type()), arg2() {
370  using std::swap;
371  swap(const_cast<T2&>(arg2_), arg2);
372  }
373  template <class B>
374  Args2(typename EnableIf<IsSame<typename RemoveCv<B>::type, None>::value, const FUNC&>::type
375  func_,
376  const T1& arg1_, const T2& arg2_, B b)
377  : BaseType(func_, arg1_, b), arg2(arg2_) {}
378  T2_ arg2;
379  };
380  template <class FUNC, class T1, class T2, class T3>
381  struct Args3 : public Args2<FUNC, T1, T2> {
382  typedef Args2<FUNC, T1, T2> BaseType;
383  typedef typename RemoveRef<T3>::type T3_;
384  template <class B>
385  Args3(const FUNC& func_, const T1& arg1_, const T2& arg2_, NLIB_THFUNC_USESWAP_NO(T3) arg3_,
386  B)
387  : BaseType(func_, arg1_, arg2_, typename ArgType<T2>::type()), arg3(arg3_) {}
388  template <class B>
389  Args3(const FUNC& func, const T1& arg1_, const T2& arg2_, NLIB_THFUNC_USESWAP_YES(T3) arg3_,
390  B)
391  : BaseType(func, arg1_, arg2_, typename ArgType<T2>::type()), arg3() {
392  using std::swap;
393  swap(const_cast<T3&>(arg3_), arg3);
394  }
395  template <class B>
396  Args3(typename EnableIf<IsSame<typename RemoveCv<B>::type, None>::value, const FUNC&>::type
397  func_,
398  const T1& arg1_, const T2& arg2_, const T3& arg3_, B b)
399  : BaseType(func_, arg1_, arg2_, b), arg3(arg3_) {}
400  T3_ arg3;
401  };
402  template <class FUNC, class T1, class T2, class T3, class T4>
403  struct Args4 : public Args3<FUNC, T1, T2, T3> {
404  typedef Args3<FUNC, T1, T2, T3> BaseType;
405  typedef typename RemoveRef<T4>::type T4_;
406  template <class B>
407  Args4(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_,
408  NLIB_THFUNC_USESWAP_NO(T4) arg4_, B)
409  : BaseType(func_, arg1_, arg2_, arg3_, typename ArgType<T3>::type()), arg4(arg4_) {}
410  template <class B>
411  Args4(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_,
412  NLIB_THFUNC_USESWAP_YES(T4) arg4_, B)
413  : BaseType(func_, arg1_, arg2_, arg3_, typename ArgType<T3>::type()), arg4() {
414  using std::swap;
415  swap(const_cast<T4&>(arg4_), arg4);
416  }
417  template <class B>
418  Args4(typename EnableIf<IsSame<typename RemoveCv<B>::type, None>::value, const FUNC&>::type
419  func_,
420  const T1& arg1_, const T2& arg2_, const T3& arg3_, const T4& arg4_, B b)
421  : BaseType(func_, arg1_, arg2_, arg3_, b), arg4(arg4_) {}
422  T4_ arg4;
423  };
424  template <class FUNC, class T1, class T2, class T3, class T4, class T5>
425  struct Args5 : public Args4<FUNC, T1, T2, T3, T4> {
426  typedef Args4<FUNC, T1, T2, T3, T4> BaseType;
427  typedef typename RemoveRef<T5>::type T5_;
428  template <class B>
429  Args5(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_, const T4& arg4_,
430  NLIB_THFUNC_USESWAP_NO(T5) arg5_, B)
431  : BaseType(func_, arg1_, arg2_, arg3_, arg4_, typename ArgType<T4>::type()),
432  arg5(arg5_) {}
433  template <class B>
434  Args5(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_, const T4& arg4_,
435  NLIB_THFUNC_USESWAP_YES(T4) arg5_, B)
436  : BaseType(func_, arg1_, arg2_, arg3_, arg4_, typename ArgType<T4>::type()), arg5() {
437  using std::swap;
438  swap(const_cast<T5&>(arg5_), arg5);
439  }
440  template <class B>
441  Args5(typename EnableIf<IsSame<typename RemoveCv<B>::type, None>::value, const FUNC&>::type
442  func_,
443  const T1& arg1_, const T2& arg2_, const T3& arg3_, const T4& arg4_, const T5& arg5_,
444  B b)
445  : BaseType(func_, arg1_, arg2_, arg3_, arg4_, b), arg5(arg5_) {}
446  T5_ arg5;
447  };
448 #undef NLIB_THFUNC_USESWAP_NO
449 #undef NLIB_THFUNC_USESWAP_YES
450 
451  template <class FUNC>
452  struct ThreadFuncX0 : public Args0<FUNC> {
453  typedef ThreadFuncX0<FUNC> ThisType;
454  typedef Args0<FUNC> BaseType;
455  template <class B>
456  ThreadFuncX0(const FUNC& func_, B b)
457  : BaseType(func_, b) {}
458  explicit ThreadFuncX0(const FUNC& func_) : BaseType(func_, None()) {}
459  static void Call(UniquePtr<ThisType>& ptr) { // NOLINT
460  ptr->func();
461  }
462  };
463  template <class FUNC, class T1>
464  struct ThreadFuncX1 : public Args1<FUNC, T1> {
465  typedef ThreadFuncX1<FUNC, T1> ThisType;
466  typedef Args1<FUNC, T1> BaseType;
467  template <class B>
468  ThreadFuncX1(const FUNC& func_, const T1& arg1_, B b)
469  : BaseType(func_, arg1_, b) {}
470  ThreadFuncX1(const FUNC& func_, const T1& arg1_) : BaseType(func_, arg1_, None()) {}
471  static void Call(UniquePtr<ThisType>& ptr) { // NOLINT
472  ptr->func(NLIB_MOVE(ptr->arg1));
473  }
474  };
475  template <class FUNC, class T1, class T2>
476  struct ThreadFuncX2 : public Args2<FUNC, T1, T2> {
477  typedef ThreadFuncX2<FUNC, T1, T2> ThisType;
478  typedef Args2<FUNC, T1, T2> BaseType;
479  template <class B>
480  ThreadFuncX2(const FUNC& func_, const T1& arg1_, const T2& arg2_, B b)
481  : BaseType(func_, arg1_, arg2_, b) {}
482  ThreadFuncX2(const FUNC& func_, const T1& arg1_, const T2& arg2_)
483  : BaseType(func_, arg1_, arg2_, None()) {}
484  static void Call(UniquePtr<ThisType>& ptr) { // NOLINT
485  ptr->func(NLIB_MOVE(ptr->arg1), NLIB_MOVE(ptr->arg2));
486  }
487  };
488  template <class FUNC, class T1, class T2, class T3>
489  struct ThreadFuncX3 : public Args3<FUNC, T1, T2, T3> {
490  typedef ThreadFuncX3<FUNC, T1, T2, T3> ThisType;
491  typedef Args3<FUNC, T1, T2, T3> BaseType;
492  template <class B>
493  ThreadFuncX3(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_, B b)
494  : BaseType(func_, arg1_, arg2_, arg3_, b) {}
495  ThreadFuncX3(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_)
496  : BaseType(func_, arg1_, arg2_, arg3_, None()) {}
497  static void Call(UniquePtr<ThisType>& ptr) { // NOLINT
498  ptr->func(NLIB_MOVE(ptr->arg1), NLIB_MOVE(ptr->arg2), NLIB_MOVE(ptr->arg3));
499  }
500  };
501  template <class FUNC, class T1, class T2, class T3, class T4>
502  struct ThreadFuncX4 : public Args4<FUNC, T1, T2, T3, T4> {
503  typedef ThreadFuncX4<FUNC, T1, T2, T3, T4> ThisType;
504  typedef Args4<FUNC, T1, T2, T3, T4> BaseType;
505  template <class B>
506  ThreadFuncX4(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_,
507  const T4& arg4_, B b)
508  : BaseType(func_, arg1_, arg2_, arg3_, arg4_, b) {}
509  ThreadFuncX4(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_,
510  const T4& arg4_)
511  : BaseType(func_, arg1_, arg2_, arg3_, arg4_, None()) {}
512  static void Call(UniquePtr<ThisType>& ptr) { // NOLINT
513  ptr->func(NLIB_MOVE(ptr->arg1), NLIB_MOVE(ptr->arg2), NLIB_MOVE(ptr->arg3),
514  NLIB_MOVE(ptr->arg4));
515  }
516  };
517  template <class FUNC, class T1, class T2, class T3, class T4, class T5>
518  struct ThreadFuncX5 : public Args5<FUNC, T1, T2, T3, T4, T5> {
519  typedef ThreadFuncX5<FUNC, T1, T2, T3, T4, T5> ThisType;
520  typedef Args5<FUNC, T1, T2, T3, T4, T5> BaseType;
521  template <class B>
522  ThreadFuncX5(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_,
523  const T4& arg4_, const T5& arg5_, B b)
524  : BaseType(func_, arg1_, arg2_, arg3_, arg4_, arg5_, b) {}
525  ThreadFuncX5(const FUNC& func_, const T1& arg1_, const T2& arg2_, const T3& arg3_,
526  const T4& arg4_, const T5& arg5_)
527  : BaseType(func_, arg1_, arg2_, arg3_, arg4_, arg5_, None()) {}
528  static void Call(UniquePtr<ThisType>& ptr) { // NOLINT
529  ptr->func(NLIB_MOVE(ptr->arg1), NLIB_MOVE(ptr->arg2), NLIB_MOVE(ptr->arg3),
530  NLIB_MOVE(ptr->arg4), NLIB_MOVE(ptr->arg5));
531  }
532  };
533 
534  public:
535  template <class FUNC>
536  errno_t Start(const ThreadSettings& settings, const FUNC& f, move_tag) {
538  new (std::nothrow) ThreadFuncX0<FUNC>(f, typename IsSwappable<FUNC>::type()));
539  if (!ptr) return ENOMEM;
540  return this->StartRaw(settings, ptr);
541  }
542  template <class FUNC>
543  errno_t Start(const FUNC& f, move_tag) {
545  new (std::nothrow) ThreadFuncX0<FUNC>(f, typename IsSwappable<FUNC>::type()));
546  if (!ptr) return ENOMEM;
547  return this->StartRaw(ptr);
548  }
549  template <class FUNC, class T1>
550  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, move_tag) {
552  new (std::nothrow) ThreadFuncX1<FUNC, T1>(f, arg1, typename ArgType<T1>::type()));
553  if (!ptr) return ENOMEM;
554  return this->StartRaw(settings, ptr);
555  }
556  template <class FUNC, class T1>
557  errno_t Start(const FUNC& f, const T1& arg1, move_tag) {
559  new (std::nothrow) ThreadFuncX1<FUNC, T1>(f, arg1, typename ArgType<T1>::type()));
560  if (!ptr) return ENOMEM;
561  return this->StartRaw(ptr);
562  }
563  template <class FUNC, class T1, class T2>
564  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, const T2& arg2,
565  move_tag) {
566  UniquePtr<ThreadFuncX2<FUNC, T1, T2> > ptr(new (std::nothrow) ThreadFuncX2<FUNC, T1, T2>(
567  f, arg1, arg2, typename ArgType<T2>::type()));
568  if (!ptr) return ENOMEM;
569  return this->StartRaw(settings, ptr);
570  }
571  template <class FUNC, class T1, class T2>
572  errno_t Start(const FUNC& f, const T1& arg1, const T2& arg2, move_tag) {
573  UniquePtr<ThreadFuncX2<FUNC, T1, T2> > ptr(new (std::nothrow) ThreadFuncX2<FUNC, T1, T2>(
574  f, arg1, arg2, typename ArgType<T2>::type()));
575  if (!ptr) return ENOMEM;
576  return this->StartRaw(ptr);
577  }
578  template <class FUNC, class T1, class T2, class T3>
579  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, const T2& arg2,
580  const T3& arg3, move_tag) {
582  new (std::nothrow)
583  ThreadFuncX3<FUNC, T1, T2, T3>(f, arg1, arg2, arg3, typename ArgType<T3>::type()));
584  if (!ptr) return ENOMEM;
585  return this->StartRaw(settings, ptr);
586  }
587  template <class FUNC, class T1, class T2, class T3>
588  errno_t Start(const FUNC& f, const T1& arg1, const T2& arg2, const T3& arg3, move_tag) {
590  new (std::nothrow)
591  ThreadFuncX3<FUNC, T1, T2, T3>(f, arg1, arg2, arg3, typename ArgType<T3>::type()));
592  if (!ptr) return ENOMEM;
593  return this->StartRaw(ptr);
594  }
595  template <class FUNC, class T1, class T2, class T3, class T4>
596  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, const T2& arg2,
597  const T3& arg3, const T4& arg4, move_tag) {
599  new (std::nothrow) ThreadFuncX4<FUNC, T1, T2, T3, T4>(f, arg1, arg2, arg3, arg4,
600  typename ArgType<T4>::type()));
601  if (!ptr) return ENOMEM;
602  return this->StartRaw(settings, ptr);
603  }
604  template <class FUNC, class T1, class T2, class T3, class T4>
605  errno_t Start(const FUNC& f, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4,
606  move_tag) {
608  new (std::nothrow) ThreadFuncX4<FUNC, T1, T2, T3, T4>(f, arg1, arg2, arg3, arg4,
609  typename ArgType<T4>::type()));
610  if (!ptr) return ENOMEM;
611  return this->StartRaw(ptr);
612  }
613  template <class FUNC, class T1, class T2, class T3, class T4, class T5>
614  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, const T2& arg2,
615  const T3& arg3, const T4& arg4, const T5& arg5, move_tag) {
617  new (std::nothrow) ThreadFuncX5<FUNC, T1, T2, T3, T4, T5>(
618  f, arg1, arg2, arg3, arg4, arg5, typename ArgType<T5>::type()));
619  if (!ptr) return ENOMEM;
620  return this->StartRaw(settings, ptr);
621  }
622  template <class FUNC, class T1, class T2, class T3, class T4, class T5>
623  errno_t Start(const FUNC& f, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4,
624  const T5& arg5, move_tag) {
626  new (std::nothrow) ThreadFuncX5<FUNC, T1, T2, T3, T4, T5>(
627  f, arg1, arg2, arg3, arg4, arg5, typename ArgType<T5>::type()));
628  if (!ptr) return ENOMEM;
629  return this->StartRaw(ptr);
630  }
631  template <class FUNC>
632  errno_t Start(const ThreadSettings& settings, const FUNC& f) {
633  UniquePtr<ThreadFuncX0<FUNC> > ptr(new (std::nothrow) ThreadFuncX0<FUNC>(f));
634  if (!ptr) return ENOMEM;
635  return this->StartRaw(settings, ptr);
636  }
637  template <class FUNC>
638  errno_t Start(const FUNC& f) {
639  UniquePtr<ThreadFuncX0<FUNC> > ptr(new (std::nothrow) ThreadFuncX0<FUNC>(f));
640  if (!ptr) return ENOMEM;
641  return this->StartRaw(ptr);
642  }
643  template <class FUNC, class T1>
644  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1) {
645  UniquePtr<ThreadFuncX1<FUNC, T1> > ptr(new (std::nothrow) ThreadFuncX1<FUNC, T1>(f, arg1));
646  if (!ptr) return ENOMEM;
647  return this->StartRaw(settings, ptr);
648  }
649  template <class FUNC, class T1>
650  errno_t Start(const FUNC& f, const T1& arg1) {
651  UniquePtr<ThreadFuncX1<FUNC, T1> > ptr(new (std::nothrow) ThreadFuncX1<FUNC, T1>(f, arg1));
652  if (!ptr) return ENOMEM;
653  return this->StartRaw(ptr);
654  }
655  template <class FUNC, class T1, class T2>
656  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, const T2& arg2) {
657  UniquePtr<ThreadFuncX2<FUNC, T1, T2> > ptr(new (std::nothrow)
658  ThreadFuncX2<FUNC, T1, T2>(f, arg1, arg2));
659  if (!ptr) return ENOMEM;
660  return this->StartRaw(settings, ptr);
661  }
662  template <class FUNC, class T1, class T2>
663  errno_t Start(const FUNC& f, const T1& arg1, const T2& arg2) {
664  UniquePtr<ThreadFuncX2<FUNC, T1, T2> > ptr(new (std::nothrow)
665  ThreadFuncX2<FUNC, T1, T2>(f, arg1, arg2));
666  if (!ptr) return ENOMEM;
667  return this->StartRaw(ptr);
668  }
669  template <class FUNC, class T1, class T2, class T3>
670  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, const T2& arg2,
671  const T3& arg3) {
673  new (std::nothrow) ThreadFuncX3<FUNC, T1, T2, T3>(f, arg1, arg2, arg3));
674  if (!ptr) return ENOMEM;
675  return this->StartRaw(settings, ptr);
676  }
677  template <class FUNC, class T1, class T2, class T3>
678  errno_t Start(const FUNC& f, const T1& arg1, const T2& arg2, const T3& arg3) {
680  new (std::nothrow) ThreadFuncX3<FUNC, T1, T2, T3>(f, arg1, arg2, arg3));
681  if (!ptr) return ENOMEM;
682  return this->StartRaw(ptr);
683  }
684  template <class FUNC, class T1, class T2, class T3, class T4>
685  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, const T2& arg2,
686  const T3& arg3, const T4& arg4) {
688  new (std::nothrow) ThreadFuncX4<FUNC, T1, T2, T3, T4>(f, arg1, arg2, arg3, arg4));
689  if (!ptr) return ENOMEM;
690  return this->StartRaw(settings, ptr);
691  }
692  template <class FUNC, class T1, class T2, class T3, class T4>
693  errno_t Start(const FUNC& f, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4) {
695  new (std::nothrow) ThreadFuncX4<FUNC, T1, T2, T3, T4>(f, arg1, arg2, arg3, arg4));
696  if (!ptr) return ENOMEM;
697  return this->StartRaw(ptr);
698  }
699  template <class FUNC, class T1, class T2, class T3, class T4, class T5>
700  errno_t Start(const ThreadSettings& settings, const FUNC& f, const T1& arg1, const T2& arg2,
701  const T3& arg3, const T4& arg4, const T5& arg5) {
703  std::nothrow) ThreadFuncX5<FUNC, T1, T2, T3, T4, T5>(f, arg1, arg2, arg3, arg4, arg5));
704  if (!ptr) return ENOMEM;
705  return this->StartRaw(settings, ptr);
706  }
707  template <class FUNC, class T1, class T2, class T3, class T4, class T5>
708  errno_t Start(const FUNC& f, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4,
709  const T5& arg5) {
711  std::nothrow) ThreadFuncX5<FUNC, T1, T2, T3, T4, T5>(f, arg1, arg2, arg3, arg4, arg5));
712  if (!ptr) return ENOMEM;
713  return this->StartRaw(ptr);
714  }
715 
716  private:
717  nlib_thread thread_id_;
719 };
720 
721 #ifdef _MSC_VER
722 #pragma warning(pop)
723 #endif
724 
725 template <>
726 struct Thread::Args0<void()> {
727  template <class X>
728  Args0(void (*func_)(), X)
729  : func(func_) {}
730  Args0(void (*func_)()) : func(func_) {}
731  void (*func)();
732 
733  private:
735 };
736 
737 template <class T1>
738 struct Thread::Args0<void(T1)> {
739  template <class X>
740  Args0(void (*func_)(T1), X)
741  : func(func_) {}
742  Args0(void (*func_)(T1)) : func(func_) {}
743  void (*func)(T1);
744 
745  private:
747 };
748 
749 template <class T1, class T2>
750 struct Thread::Args0<void(T1, T2)> {
751  template <class X>
752  Args0(void (*func_)(T1, T2), X)
753  : func(func_) {}
754  Args0(void (*func_)(T1, T2)) : func(func_) {}
755  void (*func)(T1, T2);
756 
757  private:
759 };
760 
761 template <class T1, class T2, class T3>
762 struct Thread::Args0<void(T1, T2, T3)> {
763  template <class X>
764  Args0(void (*func_)(T1, T2, T3), X)
765  : func(func_) {}
766  Args0(void (*func_)(T1, T2, T3)) : func(func_) {}
767  void (*func)(T1, T2, T3);
768 
769  private:
771 };
772 
773 template <class T1, class T2, class T3, class T4>
774 struct Thread::Args0<void(T1, T2, T3, T4)> {
775  template <class X>
776  Args0(void (*func_)(T1, T2, T3, T4), X)
777  : func(func_) {}
778  Args0(void (*func_)(T1, T2, T3, T4)) : func(func_) {}
779  void (*func)(T1, T2, T3, T4);
780 
781  private:
783 };
784 
785 template <class T1, class T2, class T3, class T4, class T5>
786 struct Thread::Args0<void(T1, T2, T3, T4, T5)> {
787  template <class X>
788  Args0(void (*func_)(T1, T2, T3, T4, T5), X)
789  : func(func_) {}
790  Args0(void (*func_)(T1, T2, T3, T4, T5)) : func(func_) {}
791  void (*func)(T1, T2, T3, T4, T5);
792 
793  private:
795 };
796 
798  unsigned int num_cpu;
799  (void)nlib_thread_getconcurrency(&num_cpu);
800  return num_cpu;
801 }
802 
803 namespace this_thread {
805 inline errno_t Sleep(const TimeSpan& span) NLIB_NOEXCEPT {
807 }
808 inline errno_t SleepMilliSeconds(unsigned int millisec) NLIB_NOEXCEPT {
809  return Sleep(TimeSpan(0, 0, millisec));
810 }
812  nlib_thread_id id;
813  errno_t e = nlib_thread_getid(&id);
814  return e == 0 ? id : -1;
815 }
816 inline errno_t GetCpu(int* cpuid) NLIB_NOEXCEPT { return nlib_thread_getcpu(cpuid); }
817 inline errno_t SetName(const char* literal_string) NLIB_NOEXCEPT {
818  nlib_thread th;
819  errno_t e = nlib_thread_self(&th);
820  if (e != 0) return e;
821  return nlib_thread_setname(th, literal_string);
822 }
825 
826 } // namespace this_thread
827 
828 } // namespace threading
829 NLIB_NAMESPACE_END
830 
831 NLIB_DEFINE_STD_SWAP(::nlib_ns::threading::Thread)
832 
833 #endif // INCLUDE_NN_NLIB_THREADING_THREAD_H_
errno_t GetCpu(int *cpuid) noexcept
Gets the CPU on which the called thread is executing.
Definition: Thread.h:816
errno_t YieldThread() noexcept
Yields control to a different thread.
Definition: Thread.h:804
errno_t Start(const ThreadSettings &settings, const FUNC &f, move_tag)
This function is nearly identical to the version without start options, except that it can specify th...
Definition: Thread.h:536
errno_t Start(const FUNC &f, const T1 &arg1, const T2 &arg2, move_tag)
Starts a function that has two arguments in a different thread. This function is nearly identical to ...
Definition: Thread.h:572
nlib_thread GetNativeHandle() const noexcept
Gets the implementation dependent thread ID.
Definition: Thread.h:247
static errno_t Sleep(const TimeSpan &span) noexcept
Sleeps only for the duration of span.
Definition: Thread.h:260
int nlib_thread_equal(nlib_thread th1, nlib_thread th2)
Checks whether two threads point to the same thread.
constexpr Thread() noexcept
Instantiates the object with default parameters (default constructor).
Definition: Thread.h:215
int GetStackSize() const noexcept
Returns the set stack size.
Definition: Thread.h:67
errno_t Sleep(const TimeSpan &span) noexcept
Makes the thread sleep for a specified period of time.
Definition: Thread.h:805
constexpr ThreadArg(Func func_, T1 arg1_, T2 arg2_, T3 arg3_, T4 arg4_, T5 arg5_)
This constructor initializes the data structure field.
Definition: Thread.h:123
Substitute definitions for the C++11 standard header type_traits. These substitute definitions are us...
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3)
This function is nearly identical to the version without start options, except that it can specify th...
Definition: Thread.h:670
bool operator!=(const Thread &rhs) noexcept
Compares threads using the nlib_thread_equal function.
Definition: Thread.h:255
constexpr ThreadArg()
Instantiates the object with default parameters (default constructor).
Definition: Thread.h:122
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:163
T1 arg1
Object passed to a function being run in a different thread.
Definition: Thread.h:128
errno_t Detach() noexcept
Detaches the thread.
Definition: Thread.h:232
Func func
Pointer to a function being run in a different thread.
Definition: Thread.h:127
bool GetDetachState() const noexcept
Gets whether the thread is set to start in a detached state.
Definition: Thread.h:48
errno_t nlib_thread_setaffinity(nlib_thread thread, uint32_t affinity)
Sets a processor affinity mask for the specified thread.
errno_t GetPriority(int32_t *priority) noexcept
Gets the thread priority.
Definition: Thread.h:238
T3 arg3
Object passed to a function being run in a different thread.
Definition: Thread.h:130
errno_t Start(const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4, const T5 &arg5, move_tag)
Starts a function that has five arguments in a different thread. This function is nearly identical to...
Definition: Thread.h:623
~Thread() noexcept
Destructor. Joins if the thread has not been joined.
Definition: Thread.h:216
struct nlib_thread_attr_ nlib_thread_attr
The thread attribute to apply to a newly created thread.
Definition: Platform.h:1214
errno_t ChangePriority(int32_t priority) noexcept
Sets the thread priority.
Definition: Thread.h:241
T5 arg5
Object passed to a function being run in a different thread.
Definition: Thread.h:132
void SetDetachState(bool detached) noexcept
Sets whether to start a thread in a detached state.
Definition: Thread.h:39
errno_t nlib_thread_self(nlib_thread *thread)
Stores the nlib_thread value corresponding to the executing thread.
errno_t Start(const FUNC &f, const T1 &arg1, const T2 &arg2)
Starts a function that has two arguments in a different thread. This function is nearly identical to ...
Definition: Thread.h:663
errno_t Start(const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3)
Starts a function that has three arguments in a different thread. This function is nearly identical t...
Definition: Thread.h:678
UniquePtr owns the pointer, and when it goes out of scope, the pointer is released by the destructor ...
Definition: UniquePtr.h:109
errno_t Start(const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4, const T5 &arg5)
Starts a function that has five arguments in a different thread. This function is nearly identical to...
Definition: Thread.h:708
Defines that class that is corresponding to std::unique_ptr.
Class to create and start threads.
Definition: Thread.h:212
errno_t nlib_thread_getid(nlib_thread_id *id)
Stores a unique integer value corresponding to the executing thread.
Structure to run a thread in a Thread class.
Definition: Thread.h:118
void swap(Thread &rhs) noexcept
Swaps the contents of an object.
Definition: Thread.h:248
errno_t Start(const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, move_tag)
Starts a function that has three arguments in a different thread. This function is nearly identical t...
Definition: Thread.h:588
errno_t nlib_thread_attr_setint(nlib_thread_attr *attr, int key, int value)
Sets an integer corresponding to the key of the thread attribute object.
int GetPriority() const noexcept
Gets the thread priority.
Definition: Thread.h:86
bool IsJoinable() const noexcept
Checks whether a join is possible.
Definition: Thread.h:237
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
errno_t nlib_thread_getconcurrency(unsigned int *num_cpu)
Gets the number of hardware threads.
errno_t SetStackSize(int size) noexcept
Sets the stack size.
Definition: Thread.h:59
errno_t Start(const FUNC &f, const T1 &arg1, move_tag)
Starts a function that has one argument in a different thread.
Definition: Thread.h:557
errno_t StartRaw(UniquePtr< ThArg > &ptr) noexcept
Starts running another thread.
Definition: Thread.h:283
errno_t SetName(const char *literal_string) noexcept
Attaches a name to the thread.
Definition: Thread.h:817
Class to wrap nlib_thread_attr. nlib_thread_attr_init() and nlib_thread_attr_destroy() are run automa...
Definition: Thread.h:29
errno_t StartRaw(const ThreadSettings &settings, UniquePtr< ThArg > &ptr) noexcept
Starts running another thread.
Definition: Thread.h:274
static errno_t YieldThread() noexcept
Calls the nlib_yield function.
Definition: Thread.h:259
errno_t Join() noexcept
Waits for a thread to complete execution.
Definition: Thread.h:222
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, move_tag)
This function is nearly identical to the version without start options, except that it can specify th...
Definition: Thread.h:579
An empty structure indicating that an argument to a function needs to be moved.
Definition: Config.h:249
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1)
This function is nearly identical to the version without start options, except that it can specify th...
Definition: Thread.h:644
bool operator==(const Thread &rhs) noexcept
Compares threads using the nlib_thread_equal function.
Definition: Thread.h:252
errno_t nlib_thread_attr_destroy(nlib_thread_attr *attr)
Destroys a thread-initialization object.
errno_t Start(const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4)
Starts a function that has four arguments in a different thread. This function is nearly identical to...
Definition: Thread.h:693
errno_t Start(const FUNC &f, const T1 &arg1)
Starts a function that has one argument in a different thread.
Definition: Thread.h:650
#define NLIB_THREAD_INVALID
Value indicating an invalid thread.
Definition: Platform.h:1198
errno_t nlib_thread_attr_getint(const nlib_thread_attr *attr, int key, int *value)
Gets the integer corresponding to the key of the thread attribute object.
errno_t Start(const ThreadSettings &settings, const FUNC &f)
This function is nearly identical to the version without start options, except that it can specify th...
Definition: Thread.h:632
#define nlib_yield
Relinquishes thread execution rights.
errno_t SetPriority(int priority) noexcept
Sets the thread priority. The priority value is platform dependent.
Definition: Thread.h:78
Defines the class for handling times and durations.
nlib_thread_id GetId() noexcept
Gets the current thread ID.
Definition: Thread.h:811
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:99
errno_t nlib_thread_attr_init(nlib_thread_attr *attr)
Initializes a thread attribute object and sets it to the default.
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:93
A file that contains the configuration information for each development environment.
errno_t nlib_sleep(nlib_duration t)
Sleeps for the duration of t.
errno_t Start(const FUNC &f)
Starts a function that has no arguments in a different thread.
Definition: Thread.h:638
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4)
This function is nearly identical to the version without start options, except that it can specify th...
Definition: Thread.h:685
errno_t nlib_thread_setpriority(nlib_thread thread, int priority)
Sets the execution priority of the thread. The meaning of the numerical value is implementation-depen...
int nlib_thread_id
A unique integer value for each thread.
Definition: Platform.h:1224
size_t GetHardwareConcurrency() noexcept
Returns the number of hardware threads.
Definition: Thread.h:797
errno_t SetAffinity(uint32_t affinity) noexcept
Sets the processor affinity mask for the thread.
Definition: Thread.h:244
errno_t nlib_thread_join(nlib_thread thread)
Waits for the thread to terminate.
ThreadArg< T1, T2, T3, T4, T5 > ThisType
typedef for this data structure type.
Definition: Thread.h:119
errno_t StartRaw(const ThreadSettings &settings, ThreadArg<>::Func func) noexcept
Starts a function that has no arguments in a different thread.
Definition: Thread.h:265
UniquePtr< ThisType > ArgType
typedef for the thread function argument type.
Definition: Thread.h:120
errno_t nlib_thread_setname(nlib_thread thread, const char *name)
Attaches a name to the thread.
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4, move_tag)
This function is nearly identical to the version without start options, except that it can specify th...
Definition: Thread.h:596
errno_t nlib_thread_detach(nlib_thread thread)
Detaches an executing thread.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:229
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4, const T5 &arg5)
This function is nearly identical to the version without start options, except that it can specify th...
Definition: Thread.h:700
errno_t nlib_thread_getcpu(int *result)
Gets the CPU on which the called thread is executing.
errno_t nlib_thread_getpriority(nlib_thread thread, int *priority)
Gets the current execution priority of the thread. The meaning of the numerical value is implementati...
The class for representing the time.
Definition: DateTime.h:106
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1, const T2 &arg2, move_tag)
This function is nearly identical to the version without start options, except that it can specify th...
Definition: Thread.h:564
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)
This function is nearly identical to the version without start options, except that it can specify th...
Definition: Thread.h:614
errno_t SleepMilliSeconds(unsigned int millisec) noexcept
Makes the thread sleep for a specified period of time.
Definition: Thread.h:808
errno_t StartRaw(ThreadArg<>::Func func) noexcept
Starts a function that has no arguments in a different thread.
Definition: Thread.h:269
T4 arg4
Object passed to a function being run in a different thread.
Definition: Thread.h:131
errno_t GetPriority(int32_t *priority) noexcept
Calls nlib_thread_getpriority and gets the thread&#39;s execution priority.
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1, move_tag)
This function is nearly identical to the version without start options, except that it can specify th...
Definition: Thread.h:550
T2 arg2
Object passed to a function being run in a different thread.
Definition: Thread.h:129
pthread_t nlib_thread
The identifier for threads.
errno_t Start(const FUNC &f, move_tag)
Starts a function that has no arguments in a different thread. This function is nearly identical to t...
Definition: Thread.h:543
errno_t Start(const FUNC &f, const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4, move_tag)
Starts a function that has four arguments in a different thread. This function is nearly identical to...
Definition: Thread.h:605
errno_t ChangePriority(int32_t priority) noexcept
Calls nlib_thread_setpriority and sets the thread&#39;s execution priority.
errno_t Start(const ThreadSettings &settings, const FUNC &f, const T1 &arg1, const T2 &arg2)
This function is nearly identical to the version without start options, except that it can specify th...
Definition: Thread.h:656
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37