CIRCT 24.0.0git
Loading...
Searching...
No Matches
esi::WriteChannelPort::DefaultAsyncWriter Struct Reference
Collaboration diagram for esi::WriteChannelPort::DefaultAsyncWriter:

Public Member Functions

 DefaultAsyncWriter (WriteChannelPort &port, DataFetchCallback fetch, WriteErrorCallback onError)
void stop ()
 Stop this connection: after this returns, it doesn't touch the port again.
void notify ()
 Mark that the DataFetchCallback may have data, then poll().
void poll ()
 Write fetched data (fetching more as needed) until the DataFetchCallback has none, the backend backpressures, or the connection is stopped.

Private Types

enum class  DrainResult

Private Member Functions

DrainResult drain ()
 The body of poll(). Requires mutex.

Private Attributes

WriteChannelPort & port
const DataFetchCallback fetch
const WriteErrorCallback onError
std::recursive_mutex mutex
 Held while writing, including while calling the callbacks.
bool draining = false
 Set by the thread holding mutex while in drain(), so callbacks don't start another one.
std::atomic< bool > stopped = false
 Set when the port is disconnected (or reconnected) or destroyed.
std::atomic< bool > dataAvailable = true
 False once fetch returns nullptr (or throws), until notify() is called.
std::unique_ptr< SegmentedMessageData > pendingMsg
 A fetched message which the port hasn't accepted yet.

Detailed Description

Definition at line 705 of file Ports.cpp.

Member Enumeration Documentation

◆ DrainResult

Definition at line 732 of file Ports.cpp.

Constructor & Destructor Documentation

◆ DefaultAsyncWriter()

esi::WriteChannelPort::DefaultAsyncWriter::DefaultAsyncWriter ( WriteChannelPort & port,
DataFetchCallback fetch,
WriteErrorCallback onError )
inline

Definition at line 706 of file Ports.cpp.

References fetch, onError, and port.

Member Function Documentation

◆ drain()

WriteChannelPort::DefaultAsyncWriter::DrainResult esi::WriteChannelPort::DefaultAsyncWriter::drain ( )
private

The body of poll(). Requires mutex.

Definition at line 791 of file Ports.cpp.

References dataAvailable, fetch, esi::WriteChannelPort::kMaxAsyncWritesPerCall, onError, pendingMsg, port, and stopped.

Referenced by poll().

◆ notify()

void esi::WriteChannelPort::DefaultAsyncWriter::notify ( )
inline

Mark that the DataFetchCallback may have data, then poll().

Definition at line 721 of file Ports.cpp.

References dataAvailable, and poll().

◆ poll()

void esi::WriteChannelPort::DefaultAsyncWriter::poll ( )

Write fetched data (fetching more as needed) until the DataFetchCallback has none, the backend backpressures, or the connection is stopped.

Does nothing if another thread is doing so, or if called from a callback.

Definition at line 769 of file Ports.cpp.

References dataAvailable, drain(), draining, and mutex.

Referenced by notify().

◆ stop()

void esi::WriteChannelPort::DefaultAsyncWriter::stop ( )
inline

Stop this connection: after this returns, it doesn't touch the port again.

Waits for another thread writing on it to stop.

Definition at line 712 of file Ports.cpp.

References mutex, pendingMsg, and stopped.

Member Data Documentation

◆ dataAvailable

std::atomic<bool> esi::WriteChannelPort::DefaultAsyncWriter::dataAvailable = true
private

False once fetch returns nullptr (or throws), until notify() is called.

Atomic since notify() sets it without mutex.

Definition at line 763 of file Ports.cpp.

Referenced by drain(), notify(), and poll().

◆ draining

bool esi::WriteChannelPort::DefaultAsyncWriter::draining = false
private

Set by the thread holding mutex while in drain(), so callbacks don't start another one.

We need this instead of relying on a normal mutex because a normal mutex when 'try_to_lock' is called by the same thread the behavior is undefined.

Definition at line 757 of file Ports.cpp.

Referenced by poll().

◆ fetch

const DataFetchCallback esi::WriteChannelPort::DefaultAsyncWriter::fetch
private

Definition at line 746 of file Ports.cpp.

Referenced by DefaultAsyncWriter(), and drain().

◆ mutex

std::recursive_mutex esi::WriteChannelPort::DefaultAsyncWriter::mutex
private

Held while writing, including while calling the callbacks.

Recursive so that the callbacks can disconnect the port or call notifyAsyncDataAvailable().

Definition at line 752 of file Ports.cpp.

Referenced by poll(), and stop().

◆ onError

const WriteErrorCallback esi::WriteChannelPort::DefaultAsyncWriter::onError
private

Definition at line 747 of file Ports.cpp.

Referenced by DefaultAsyncWriter(), and drain().

◆ pendingMsg

std::unique_ptr<SegmentedMessageData> esi::WriteChannelPort::DefaultAsyncWriter::pendingMsg
private

A fetched message which the port hasn't accepted yet.

Guarded by mutex.

Definition at line 766 of file Ports.cpp.

Referenced by drain(), and stop().

◆ port

WriteChannelPort& esi::WriteChannelPort::DefaultAsyncWriter::port
private

Definition at line 745 of file Ports.cpp.

Referenced by DefaultAsyncWriter(), and drain().

◆ stopped

std::atomic<bool> esi::WriteChannelPort::DefaultAsyncWriter::stopped = false
private

Set when the port is disconnected (or reconnected) or destroyed.

After that, this connection doesn't touch the port.

Definition at line 760 of file Ports.cpp.

Referenced by drain(), and stop().


The documentation for this struct was generated from the following file: