Lockless Task Scheduler  v1.0a
A lockless task scheduler
print.h
1 // ***********************************************************************
2 // Assembly : task_scheduler
3 // Author : viknash
4 // ***********************************************************************
5 // <copyright file="print.h" >
6 // Copyright (c) viknash. All rights reserved.
7 // </copyright>
8 // <summary></summary>
9 // ***********************************************************************
10 #pragma once
11 
12 #include <atomic>
13 #include <cstdint>
14 #include <iostream>
15 #include <mutex>
16 #include <sstream>
17 #include <thread>
18 
19 #include "platform.h"
20 #include "globals.h"
21 
22 
26 namespace task_scheduler
27 {
28 
29 #if defined(TASK_SCHEDULER_DEBUG)
30  struct out_t
34  {
40  template < typename T > out_t &operator<<(T &&x)
41  {
42  buffer << x;
43  return *this;
44  };
45 
49  out_t() { buffer << thread_name << "> "; }
50 
54  ~out_t()
55  {
56  std::lock_guard< std::mutex > lk(get<globals>()->io_mutex);
57  ts_windows_only(SetConsoleTextAttribute(get<globals>()->console_handle, get_thread_number()););
58  tcout << buffer.str() << std::endl;
59  }
60 
64  tostringstream buffer;
65  };
66 #else // defined(TASK_SCHEDULER_DEBUG)
67  struct out_t
71  {
77  template < typename T > out_t &operator<<(T &&x) { return *this; };
78  };
79 #endif // defined(TASK_SCHEDULER_DEBUG)
80 
81 #define ts_print_internal(arg) \
82  out_t arg; \
83  arg
84 
85 #define ts_print(x) \
86  { \
87  ts_print_internal(ts_unique_variable(printout)) << x; \
88  }
89 };
out_t & operator<<(T &&x)
Operators the specified x.
Definition: print.h:77
Class stl_allocator.
Definition: allocator.h:16
Struct out_t
Definition: print.h:70
thread_local tstring thread_name
The thread name
Definition: globals.h:68
uint8_t get_thread_number()
Gets the thread number.
Definition: globals.h:82