Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:01:50

0001 #ifndef FWCore_Concurrency_ThreadSafeOutputFileStream_h
0002 #define FWCore_Concurrency_ThreadSafeOutputFileStream_h
0003 
0004 #include "oneapi/tbb/concurrent_queue.h"
0005 
0006 #include <atomic>
0007 #include <fstream>
0008 #include <string>
0009 
0010 namespace edm {
0011   class ThreadSafeOutputFileStream {
0012   public:
0013     ThreadSafeOutputFileStream(std::string const& name);
0014     ~ThreadSafeOutputFileStream();
0015 
0016     void write(std::string&& msg);
0017     explicit operator bool() const { return static_cast<bool>(file_); }
0018 
0019   private:
0020     std::ofstream file_;
0021     std::atomic<bool> msgBeingLogged_{false};
0022     oneapi::tbb::concurrent_queue<std::string> waitingMessages_{};
0023   };
0024 }  // namespace edm
0025 
0026 #endif