File indexing completed on 2024-04-06 12:11:56
0001 #include "FWCore/Concurrency/interface/ThreadSafeOutputFileStream.h"
0002
0003 #include <sstream>
0004
0005 namespace edm {
0006
0007 ThreadSafeOutputFileStream::ThreadSafeOutputFileStream(std::string const& name) : file_{name} {}
0008
0009 ThreadSafeOutputFileStream::~ThreadSafeOutputFileStream() {
0010 std::string tmp;
0011 while (waitingMessages_.try_pop(tmp)) {
0012 file_ << tmp;
0013 }
0014 file_.close();
0015 }
0016
0017 void ThreadSafeOutputFileStream::write(std::string&& msg) {
0018 waitingMessages_.push(std::move(msg));
0019 bool expected{false};
0020 if (msgBeingLogged_.compare_exchange_strong(expected, true)) {
0021 std::string tmp;
0022 while (waitingMessages_.try_pop(tmp)) {
0023 file_ << tmp;
0024 }
0025 msgBeingLogged_.store(false);
0026 }
0027 }
0028 }