Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 1012 vs 1013 for /trunk/Source Code/Core/Console.cpp

Diff revisions: vs.
  @@ -5,6 +5,10 @@
5 5 #include "Core/Time/Headers/ApplicationTimer.h"
6 6 #include <iomanip>
7 7
8 + #ifndef USE_BLOCKING_QUEUE
9 + //#define USE_BLOCKING_QUEUE
10 + #endif //USE_BLOCKING_QUEUE
11 +
8 12 namespace Divide {
9 13
10 14 bool Console::_timestamps = false;
  @@ -24,11 +28,33 @@
24 28 static const size_t BLOCK_SIZE = MAX_CONSOLE_ENTRIES;
25 29 };
26 30
31 + #if defined(USE_BLOCKING_QUEUE)
27 32 moodycamel::BlockingConcurrentQueue<Console::OutputEntry, MyTraits>& outBuffer() {
28 33 static moodycamel::BlockingConcurrentQueue<Console::OutputEntry, MyTraits> outputBuffer;
29 34 return outputBuffer;
30 35 }
36 + #else
37 + moodycamel::ConcurrentQueue<Console::OutputEntry, MyTraits>& outBuffer() {
38 + static moodycamel::ConcurrentQueue<Console::OutputEntry, MyTraits> outputBuffer;
39 + return outputBuffer;
40 + }
31 41
42 + std::mutex& condMutex() noexcept {
43 + static std::mutex condMutex;
44 + return condMutex;
45 + }
46 +
47 + std::condition_variable& entryEnqueCV() {
48 + static std::condition_variable entryEnqueCV;
49 + return entryEnqueCV;
50 + }
51 +
52 + std::atomic_bool& entryAdded() noexcept {
53 + static std::atomic_bool entryAdded;
54 + return entryAdded;
55 + }
56 +
57 + #endif
32 58 };
33 59
34 60 //! Do not remove the following license without express permission granted by DIVIDE-Studio
  @@ -101,6 +127,12 @@
101 127 if (!outBuffer().enqueue(/*ptok, */entry)) {
102 128 // ToDo: Something happened. Handle it, maybe? -Ionut
103 129 }
130 +
131 + #if !defined(USE_BLOCKING_QUEUE)
132 + UniqueLock lk(condMutex());
133 + entryAdded() = true;
134 + entryEnqueCV().notify_one();
135 + #endif
104 136 }
105 137 }
106 138
  @@ -108,7 +140,14 @@
108 140 //moodycamel::ConsumerToken ctok(outBuffer());
109 141 OutputEntry entry;
110 142 while (_running) {
143 + #if defined(USE_BLOCKING_QUEUE)
111 144 if (outBuffer().wait_dequeue_timed(/*ctok, */entry, Time::Milliseconds(16))) {
145 + #else
146 + UniqueLock lk(condMutex());
147 + entryEnqueCV().wait(lk, []() -> bool { return entryAdded(); });
148 +
149 + if (outBuffer().try_dequeue(/*ctok, */entry)) {
150 + #endif
112 151 ((entry._type == EntryType::Error && _errorStreamEnabled) ? std::cerr : std::cout) << entry._text.c_str();
113 152
114 153 for (const Console::ConsolePrintCallback& cbk : _guiConsoleCallbacks) {