Thrill  0.1
DispatcherThread Class Reference

Detailed Description

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.

+ Collaboration diagram for DispatcherThread:

#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 ()
 
DispatcherThreadoperator= (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 Dispatcherdispatcher_
 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
 

Member Typedef Documentation

◆ Job

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.

Constructor & Destructor Documentation

◆ DispatcherThread() [1/2]

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().

◆ DispatcherThread() [2/2]

DispatcherThread ( const DispatcherThread )
delete

non-copyable: delete copy-constructor

Member Function Documentation

◆ AddRead()

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().

◆ AddTimer()

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().

◆ AddWrite()

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().

◆ AsyncRead() [1/2]

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().

◆ AsyncRead() [2/2]

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().

◆ AsyncWrite() [1/2]

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().

◆ AsyncWrite() [2/2]

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().

◆ AsyncWriteCopy() [1/2]

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().

◆ AsyncWriteCopy() [2/2]

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().

◆ Cancel()

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().

◆ Enqueue()

void Enqueue ( Job &&  job)
private

◆ operator=()

DispatcherThread& operator= ( const DispatcherThread )
delete

non-copyable: delete assignment operator

◆ RunInThread()

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().

◆ Terminate()

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().

◆ WakeUpThread()

◆ Work()

Member Data Documentation

◆ busy_

std::atomic<bool> busy_ { false }
private

whether to call Interrupt() in WakeUpThread()

Definition at line 170 of file dispatcher_thread.hpp.

Referenced by DispatcherThread::WakeUpThread(), and DispatcherThread::Work().

◆ debug

constexpr bool debug = false
staticprivate

Definition at line 62 of file dispatcher_thread.hpp.

◆ dispatcher_

◆ host_rank_

size_t host_rank_
private

for thread name for logging

Definition at line 173 of file dispatcher_thread.hpp.

Referenced by DispatcherThread::Work().

◆ jobqueue_

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().

◆ terminate_

std::atomic<bool> terminate_ { false }
private

termination flag

Definition at line 167 of file dispatcher_thread.hpp.

Referenced by DispatcherThread::Terminate(), and DispatcherThread::Work().

◆ thread_

std::thread thread_
private

thread of dispatcher

Definition at line 161 of file dispatcher_thread.hpp.

Referenced by DispatcherThread::DispatcherThread(), and DispatcherThread::Terminate().


The documentation for this class was generated from the following files: