1 #ifndef OPM_THREADHANDLE_HPP 2 #define OPM_THREADHANDLE_HPP 5 #include <dune/common/exceptions.hh> 23 virtual void run() = 0;
24 virtual bool isEndMarker ()
const {
return false; }
27 template <
class Object>
33 void run() { obj_.run(); }
41 bool isEndMarker ()
const {
return true; }
50 std::queue< std::unique_ptr< ObjectInterface > > objQueue_;
59 std::this_thread::sleep_for( std::chrono::milliseconds(10) );
65 : objQueue_(), mutex_()
72 while( ! objQueue_.empty() )
79 void push_back( std::unique_ptr< ObjectInterface >&& obj )
83 objQueue_.emplace( std::move(obj) );
91 while( objQueue_.empty() )
102 std::unique_ptr< ObjectInterface > obj( objQueue_.front().release() );
110 if( obj->isEndMarker() ){
111 if( ! objQueue_.empty() ) {
112 OPM_THROW(std::logic_error,
"ThreadHandleQueue: not all queued objects were executed");
131 static void startThread( ThreadHandleQueue* obj )
136 ThreadHandleQueue threadObjectQueue_;
137 std::unique_ptr< std::thread > thread_;
141 ThreadHandle(
const ThreadHandle& ) =
delete;
147 : threadObjectQueue_(),
152 thread_.reset(
new std::thread( startThread, &threadObjectQueue_ ) );
159 template <
class Object>
168 threadObjectQueue_.push_back( std::unique_ptr< ObjectInterface > (objPtr) );
172 OPM_THROW(std::logic_error,
"ThreadHandle::dispatch called without thread being initialized (i.e. on non-ioRank)");
182 threadObjectQueue_.push_back( std::unique_ptr< ObjectInterface > (
new EndObject()) ) ;
Definition: ThreadHandle.hpp:37
~ThreadHandle()
destructor terminating the thread
Definition: ThreadHandle.hpp:177
void run()
do the work until the queue received an end object
Definition: ThreadHandle.hpp:88
Definition: ThreadHandle.hpp:14
ThreadHandle(const bool createThread)
constructor creating ThreadHandle
Definition: ThreadHandle.hpp:146
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: AdditionalObjectDeleter.hpp:22
void push_back(std::unique_ptr< ObjectInterface > &&obj)
insert object into threads queue
Definition: ThreadHandle.hpp:79
Definition: ThreadHandle.hpp:28
Definition: ThreadHandle.hpp:47
Definition: ThreadHandle.hpp:17
void dispatch(Object &&obj)
dispatch object to queue of separate thread
Definition: ThreadHandle.hpp:160
ThreadHandleQueue()
constructor creating object that is executed by thread
Definition: ThreadHandle.hpp:64