MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / WorkerThread

Method WorkerThread

lib/mdflib/mdfviewer/src/util/logfile.cpp:110–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108}
109
110void LogFile::WorkerThread() {
111 try {
112 BackupFiles(filename_);
113 } catch (const std::exception &error) {
114 LOG_ERROR() << "Failed to backup log files at start. Error: "
115 << error.what();
116 }
117
118 do {
119 std::unique_lock<std::mutex> lock(locker_);
120 condition_.wait_for(lock, 1000ms, [&] { return stop_thread_.load(); });
121
122 int message_count = 0;
123 for (; !message_list_.empty() && message_count <= 10000; ++message_count) {
124 LogMessage m = message_list_.front();
125 message_list_.pop();
126 lock.unlock();
127 HandleMessage(m);
128 lock.lock();
129 }
130 if (file_ != nullptr) {
131 std::fclose(file_);
132 file_ = nullptr;
133 }
134 try {
135 if (message_count > 0) {
136 path p(filename_);
137 if (file_ == nullptr && exists(p) && file_size(p) > 10'000'000) {
138 BackupFiles(filename_);
139 }
140 }
141 } catch (const std::exception &error) {
142 LOG_ERROR() << "Failed to backup log files. Error: " << error.what();
143 }
144 } while (!stop_thread_);
145
146 while (!message_list_.empty()) {
147 LogMessage m = message_list_.front();
148 message_list_.pop();
149 HandleMessage(m);
150 }
151
152 if (file_ != nullptr) {
153 std::fclose(file_);
154 file_ = nullptr;
155 }
156}
157
158void LogFile::HandleMessage(const LogMessage &m) {
159 if (file_ == nullptr) {

Callers

nothing calls this directly

Calls 4

BackupFilesFunction · 0.85
wait_forMethod · 0.80
emptyMethod · 0.80
loadMethod · 0.45

Tested by

no test coverage detected