CppCommon  1.0.4.1
C++ Common Library
thread.inl
Go to the documentation of this file.
1 
9 namespace CppCommon {
10 
11 template <class TOutputStream>
12 inline TOutputStream& operator<<(TOutputStream& stream, ThreadPriority priority)
13 {
14  switch (priority)
15  {
17  stream << "IDLE";
18  break;
20  stream << "LOWEST";
21  break;
23  stream << "LOW";
24  break;
26  stream << "NORMAL";
27  break;
29  stream << "HIGH";
30  break;
32  stream << "HIGHEST";
33  break;
35  stream << "REALTIME";
36  break;
37  default:
38  stream << "<unknown>";
39  break;
40  }
41  return stream;
42 }
43 
44 template <class Fn, class... Args>
45 inline std::thread Thread::Start(Fn&& fn, Args&&... args)
46 {
47  return std::thread([fn = fn, args...]()
48  {
49  // Setup exception handler for the new thread
50  ExceptionsHandler::SetupThread();
51 
52  // Call the base thread function
53  fn(std::move(args)...);
54  });
55 }
56 
57 } // namespace CppCommon
static std::thread Start(Fn &&fn, Args &&... args)
Start a new thread with an exception handler registered.
Definition: thread.inl:45
C++ Common project definitions.
Definition: token_bucket.h:15
std::ostream & operator<<(std::ostream &os, const uint128_t &value)
Definition: uint128.inl:155
ThreadPriority
Thread priorities.
Definition: thread.h:28
@ NORMAL
Normal thread priority.
@ LOW
Low thread priority.
@ REALTIME
Realtime thread priority.
@ LOWEST
Lowest thread priority.
@ IDLE
Idle thread priority.
@ HIGH
High thread priority.
@ HIGHEST
Highest thread priority.