Thrill
0.1
|
DispatcherThread contains a net::Dispatcher object and an associated thread that runs in the dispatching loop.
Definition at line 60 of file dispatcher_thread.hpp.
#include <dispatcher_thread.hpp>
Public Types | |
using | Job = tlx::delegate< void(), mem::GPoolAllocator< char > > |
Signature of async jobs to be run by the dispatcher thread. More... | |
Public Member Functions | |
DispatcherThread (std::unique_ptr< class Dispatcher > dispatcher, size_t host_rank) | |
DispatcherThread (const DispatcherThread &)=delete | |
non-copyable: delete copy-constructor More... | |
~DispatcherThread () | |
DispatcherThread & | operator= (const DispatcherThread &)=delete |
non-copyable: delete assignment operator More... | |
void | RunInThread (const AsyncDispatcherThreadCallback &cb) |
Run generic callback in dispatcher thread to enqueue stuff. More... | |
void | Terminate () |
Terminate the dispatcher thread (if now already done). More... | |
Timeout Callbacks | |
void | AddTimer (std::chrono::milliseconds timeout, const TimerCallback &cb) |
Register a relative timeout callback. More... | |
Connection Callbacks | |
void | AddRead (Connection &c, const AsyncCallback &read_cb) |
Register a buffered read callback and a default exception callback. More... | |
void | AddWrite (Connection &c, const AsyncCallback &write_cb) |
Register a buffered write callback and a default exception callback. More... | |
void | Cancel (Connection &c) |
Cancel all callbacks on a given connection. More... | |
Asynchronous Data Reader/Writer Callbacks | |
void | AsyncRead (Connection &c, uint32_t seq, size_t size, const AsyncReadCallback &done_cb) |
asynchronously read n bytes and deliver them to the callback More... | |
void | AsyncRead (Connection &c, uint32_t seq, size_t size, data::PinnedByteBlockPtr &&block, const AsyncReadByteBlockCallback &done_cb) |
asynchronously read the full ByteBlock and deliver it to the callback More... | |
void | AsyncWrite (Connection &c, uint32_t seq, Buffer &&buffer, const AsyncWriteCallback &done_cb=AsyncWriteCallback()) |
void | AsyncWrite (Connection &c, uint32_t seq, Buffer &&buffer, data::PinnedBlock &&block, const AsyncWriteCallback &done_cb=AsyncWriteCallback()) |
void | AsyncWriteCopy (Connection &c, uint32_t seq, const void *buffer, size_t size, const AsyncWriteCallback &done_cb=AsyncWriteCallback()) |
void | AsyncWriteCopy (Connection &c, uint32_t seq, const std::string &str, const AsyncWriteCallback &done_cb=AsyncWriteCallback()) |
Private Member Functions | |
void | Enqueue (Job &&job) |
Enqueue job in queue for dispatching thread to run at its discretion. More... | |
void | WakeUpThread () |
wake up select() in dispatching thread. More... | |
void | Work () |
What happens in the dispatcher thread. More... | |
Private Attributes | |
std::atomic< bool > | busy_ { false } |
whether to call Interrupt() in WakeUpThread() More... | |
std::unique_ptr< class Dispatcher > | dispatcher_ |
enclosed dispatcher. More... | |
size_t | host_rank_ |
for thread name for logging More... | |
common::ConcurrentQueue< Job, mem::GPoolAllocator< Job > > | jobqueue_ |
Queue of jobs to be run by dispatching thread at its discretion. More... | |
std::atomic< bool > | terminate_ { false } |
termination flag More... | |
std::thread | thread_ |
thread of dispatcher More... | |
Static Private Attributes | |
static constexpr bool | debug = false |
using Job = tlx::delegate<void (), mem::GPoolAllocator<char> > |
Signature of async jobs to be run by the dispatcher thread.
Definition at line 66 of file dispatcher_thread.hpp.
DispatcherThread | ( | std::unique_ptr< class Dispatcher > | dispatcher, |
size_t | host_rank | ||
) |
Definition at line 22 of file dispatcher_thread.cpp.
References DispatcherThread::thread_, and DispatcherThread::Work().
~DispatcherThread | ( | ) |
Definition at line 30 of file dispatcher_thread.cpp.
References DispatcherThread::Terminate().
|
delete |
non-copyable: delete copy-constructor
void AddRead | ( | Connection & | c, |
const AsyncCallback & | read_cb | ||
) |
Register a buffered read callback and a default exception callback.
Definition at line 60 of file dispatcher_thread.cpp.
References DispatcherThread::dispatcher_, DispatcherThread::Enqueue(), and DispatcherThread::WakeUpThread().
void AddTimer | ( | std::chrono::milliseconds | timeout, |
const TimerCallback & | cb | ||
) |
Register a relative timeout callback.
Definition at line 52 of file dispatcher_thread.cpp.
References DispatcherThread::dispatcher_, DispatcherThread::Enqueue(), and DispatcherThread::WakeUpThread().
void AddWrite | ( | Connection & | c, |
const AsyncCallback & | write_cb | ||
) |
Register a buffered write callback and a default exception callback.
Definition at line 67 of file dispatcher_thread.cpp.
References DispatcherThread::dispatcher_, DispatcherThread::Enqueue(), and DispatcherThread::WakeUpThread().
void AsyncRead | ( | Connection & | c, |
uint32_t | seq, | ||
size_t | size, | ||
const AsyncReadCallback & | done_cb | ||
) |
asynchronously read n bytes and deliver them to the callback
Definition at line 81 of file dispatcher_thread.cpp.
References DispatcherThread::dispatcher_, DispatcherThread::Enqueue(), and DispatcherThread::WakeUpThread().
Referenced by Multiplexer::AsyncReadMultiplexerHeader(), and Multiplexer::OnMultiplexerHeader().
void AsyncRead | ( | Connection & | c, |
uint32_t | seq, | ||
size_t | size, | ||
data::PinnedByteBlockPtr && | block, | ||
const AsyncReadByteBlockCallback & | done_cb | ||
) |
asynchronously read the full ByteBlock and deliver it to the callback
Definition at line 90 of file dispatcher_thread.cpp.
References DispatcherThread::dispatcher_, DispatcherThread::Enqueue(), and DispatcherThread::WakeUpThread().
void AsyncWrite | ( | Connection & | c, |
uint32_t | seq, | ||
Buffer && | buffer, | ||
const AsyncWriteCallback & | done_cb = AsyncWriteCallback() |
||
) |
asynchronously write byte and block and callback when delivered. The block is reference counted by the async writer.
Definition at line 100 of file dispatcher_thread.cpp.
References DispatcherThread::dispatcher_, DispatcherThread::Enqueue(), and DispatcherThread::WakeUpThread().
Referenced by DispatcherThread::AsyncWriteCopy(), and StreamSet< StreamData >::OnWriterClosed().
void AsyncWrite | ( | Connection & | c, |
uint32_t | seq, | ||
Buffer && | buffer, | ||
data::PinnedBlock && | block, | ||
const AsyncWriteCallback & | done_cb = AsyncWriteCallback() |
||
) |
asynchronously write TWO buffers and callback when delivered. The buffer2 are MOVED into the async writer. This is most useful to write a header and a payload Buffers that are hereby guaranteed to be written in order.
Definition at line 109 of file dispatcher_thread.cpp.
References DispatcherThread::dispatcher_, DispatcherThread::Enqueue(), and DispatcherThread::WakeUpThread().
void AsyncWriteCopy | ( | Connection & | c, |
uint32_t | seq, | ||
const void * | buffer, | ||
size_t | size, | ||
const AsyncWriteCallback & | done_cb = AsyncWriteCallback() |
||
) |
asynchronously write buffer and callback when delivered. COPIES the data into a Buffer!
Definition at line 122 of file dispatcher_thread.cpp.
References DispatcherThread::AsyncWrite().
Referenced by DispatcherThread::AsyncWriteCopy().
void AsyncWriteCopy | ( | Connection & | c, |
uint32_t | seq, | ||
const std::string & | str, | ||
const AsyncWriteCallback & | done_cb = AsyncWriteCallback() |
||
) |
asynchronously write buffer and callback when delivered. COPIES the data into a Buffer!
Definition at line 128 of file dispatcher_thread.cpp.
References DispatcherThread::AsyncWriteCopy().
void Cancel | ( | Connection & | c | ) |
Cancel all callbacks on a given connection.
Definition at line 74 of file dispatcher_thread.cpp.
References DispatcherThread::dispatcher_, DispatcherThread::Enqueue(), and DispatcherThread::WakeUpThread().
|
private |
Enqueue job in queue for dispatching thread to run at its discretion.
Definition at line 134 of file dispatcher_thread.cpp.
References DispatcherThread::jobqueue_.
Referenced by DispatcherThread::AddRead(), DispatcherThread::AddTimer(), DispatcherThread::AddWrite(), DispatcherThread::AsyncRead(), DispatcherThread::AsyncWrite(), DispatcherThread::Cancel(), and DispatcherThread::RunInThread().
|
delete |
non-copyable: delete assignment operator
void RunInThread | ( | const AsyncDispatcherThreadCallback & | cb | ) |
Run generic callback in dispatcher thread to enqueue stuff.
Definition at line 45 of file dispatcher_thread.cpp.
References DispatcherThread::dispatcher_, DispatcherThread::Enqueue(), and DispatcherThread::WakeUpThread().
void Terminate | ( | ) |
Terminate the dispatcher thread (if now already done).
Definition at line 34 of file dispatcher_thread.cpp.
References DispatcherThread::terminate_, DispatcherThread::thread_, and DispatcherThread::WakeUpThread().
Referenced by DispatcherThread::~DispatcherThread().
|
private |
wake up select() in dispatching thread.
Definition at line 174 of file dispatcher_thread.cpp.
References DispatcherThread::busy_, and DispatcherThread::dispatcher_.
Referenced by DispatcherThread::AddRead(), DispatcherThread::AddTimer(), DispatcherThread::AddWrite(), DispatcherThread::AsyncRead(), DispatcherThread::AsyncWrite(), DispatcherThread::Cancel(), DispatcherThread::RunInThread(), and DispatcherThread::Terminate().
|
private |
What happens in the dispatcher thread.
Definition at line 138 of file dispatcher_thread.cpp.
References DispatcherThread::busy_, DispatcherThread::dispatcher_, DispatcherThread::host_rank_, DispatcherThread::jobqueue_, LOG, thrill::common::NameThisThread(), thrill::common::SetCpuAffinity(), DispatcherThread::terminate_, and thrill::mem::to_string().
Referenced by DispatcherThread::DispatcherThread().
|
private |
whether to call Interrupt() in WakeUpThread()
Definition at line 170 of file dispatcher_thread.hpp.
Referenced by DispatcherThread::WakeUpThread(), and DispatcherThread::Work().
|
staticprivate |
Definition at line 62 of file dispatcher_thread.hpp.
|
private |
enclosed dispatcher.
Definition at line 164 of file dispatcher_thread.hpp.
Referenced by DispatcherThread::AddRead(), DispatcherThread::AddTimer(), DispatcherThread::AddWrite(), DispatcherThread::AsyncRead(), DispatcherThread::AsyncWrite(), DispatcherThread::Cancel(), DispatcherThread::RunInThread(), DispatcherThread::WakeUpThread(), and DispatcherThread::Work().
|
private |
for thread name for logging
Definition at line 173 of file dispatcher_thread.hpp.
Referenced by DispatcherThread::Work().
|
private |
Queue of jobs to be run by dispatching thread at its discretion.
Definition at line 158 of file dispatcher_thread.hpp.
Referenced by DispatcherThread::Enqueue(), and DispatcherThread::Work().
|
private |
termination flag
Definition at line 167 of file dispatcher_thread.hpp.
Referenced by DispatcherThread::Terminate(), and DispatcherThread::Work().
|
private |
thread of dispatcher
Definition at line 161 of file dispatcher_thread.hpp.
Referenced by DispatcherThread::DispatcherThread(), and DispatcherThread::Terminate().