Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:29

0001 #ifndef HeterogeneousCore_SonicCore_SonicDispatcherPseudoAsync
0002 #define HeterogeneousCore_SonicCore_SonicDispatcherPseudoAsync
0003 
0004 #include "HeterogeneousCore/SonicCore/interface/SonicDispatcher.h"
0005 
0006 #include <memory>
0007 #include <condition_variable>
0008 #include <mutex>
0009 #include <thread>
0010 #include <atomic>
0011 #include <exception>
0012 
0013 class SonicClientBase;
0014 
0015 //pretend to be async + non-blocking by waiting for blocking calls to return in separate std::thread
0016 class SonicDispatcherPseudoAsync : public SonicDispatcher {
0017 public:
0018   //constructor
0019   SonicDispatcherPseudoAsync(SonicClientBase* client);
0020 
0021   //destructor
0022   ~SonicDispatcherPseudoAsync() override;
0023 
0024   //main operation
0025   void dispatch(edm::WaitingTaskWithArenaHolder holder) override;
0026 
0027 private:
0028   void waitForNext();
0029 
0030   //members
0031   bool hasCall_;
0032   std::mutex mutex_;
0033   std::condition_variable cond_;
0034   std::atomic<bool> stop_;
0035   std::unique_ptr<std::thread> thread_;
0036 };
0037 
0038 #endif