#include <ThreadHandoff.h>
Definition at line 33 of file ThreadHandoff.h.
◆ ThreadHandoff() [1/2]
ThreadHandoff::ThreadHandoff |
( |
int |
stackSize | ) |
|
|
explicit |
Definition at line 40 of file ThreadHandoff.cc.
References Exception, m_loopReady, m_mutex, m_thread, m_threadHandoff, and threadLoop().
43 if (0 != (erno = pthread_attr_init(&attr))) {
45 <<
"Failed to initialize thread attributes (" << erno <<
") " << errorMessage(erno);
48 if (0 != (erno = pthread_attr_setstacksize(&attr, stackSize))) {
50 <<
"Failed to set stack size " << stackSize <<
" " << errorMessage(erno);
52 std::unique_lock<std::mutex> lk(
m_mutex);
56 throw cms::Exception(
"ThreadCreateFailed") <<
" failed to create a pthread (" << erno <<
") " << errorMessage(erno);
std::condition_variable m_threadHandoff
static void * threadLoop(void *iArgs)
◆ ~ThreadHandoff()
ThreadHandoff::~ThreadHandoff |
( |
| ) |
|
◆ ThreadHandoff() [2/2]
◆ operator=()
◆ runAndWait()
template<typename F >
void omt::ThreadHandoff::runAndWait |
( |
F && |
iF | ) |
|
|
inline |
Definition at line 42 of file ThreadHandoff.h.
References MillePedeFileConverter_cfg::e, f, m_loopReady, m_mutex, m_threadHandoff, m_toRun, and eostools::move().
Referenced by OscarMTProducer::beginRun(), OscarMTProducer::endRun(), OscarMTProducer::produce(), stopThread(), and OscarMTProducer::~OscarMTProducer().
45 std::unique_lock<std::mutex> lck(
m_mutex);
52 auto e =
f.exception();
54 std::rethrow_exception(
e);
std::condition_variable m_threadHandoff
◆ stopThread()
void omt::ThreadHandoff::stopThread |
( |
| ) |
|
|
inline |
◆ threadLoop()
void * ThreadHandoff::threadLoop |
( |
void * |
iArgs | ) |
|
|
staticprivate |
Definition at line 98 of file ThreadHandoff.cc.
Referenced by ThreadHandoff().
103 std::unique_lock<std::mutex> lck(theThis->m_mutex);
104 theThis->m_loopReady =
true;
105 theThis->m_threadHandoff.notify_one();
108 theThis->m_toRun =
nullptr;
109 theThis->m_threadHandoff.wait(lck, [theThis]() {
return nullptr != theThis->m_toRun; });
110 theThis->m_toRun->execute();
111 theThis->m_loopReady =
true;
112 theThis->m_threadHandoff.notify_one();
113 }
while (not theThis->m_stopThread);
114 theThis->m_loopReady =
true;
◆ m_loopReady
bool omt::ThreadHandoff::m_loopReady {false} |
|
private |
◆ m_mutex
◆ m_stopThread
bool omt::ThreadHandoff::m_stopThread {false} |
|
private |
◆ m_thread
pthread_t omt::ThreadHandoff::m_thread |
|
private |
◆ m_threadHandoff
std::condition_variable omt::ThreadHandoff::m_threadHandoff |
|
private |
◆ m_toRun