#include <ThreadHandoff.h>
Definition at line 33 of file ThreadHandoff.h.
◆ ThreadHandoff() [1/2]
ThreadHandoff::ThreadHandoff |
( |
int |
stackSize | ) |
|
|
explicit |
Definition at line 41 of file ThreadHandoff.cc.
References Exception, m_loopReady, m_mutex, m_thread, m_threadHandoff, and threadLoop().
44 if (0 != (erno = pthread_attr_init(&attr))) {
46 <<
"Failed to initialize thread attributes (" << erno <<
") " << errorMessage(erno);
49 if (0 != (erno = pthread_attr_setstacksize(&attr, stackSize))) {
51 <<
"Failed to set stack size " << stackSize <<
" " << errorMessage(erno);
53 std::unique_lock<std::mutex> lk(
m_mutex);
57 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 99 of file ThreadHandoff.cc.
Referenced by ThreadHandoff().
104 std::unique_lock<std::mutex> lck(theThis->m_mutex);
105 theThis->m_loopReady =
true;
106 theThis->m_threadHandoff.notify_one();
109 theThis->m_toRun =
nullptr;
110 theThis->m_threadHandoff.wait(lck, [theThis]() {
return nullptr != theThis->m_toRun; });
111 theThis->m_toRun->execute();
112 theThis->m_loopReady =
true;
113 theThis->m_threadHandoff.notify_one();
114 }
while (not theThis->m_stopThread);
115 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