Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
util::uring::Proactor Class Reference

Public Types

using IoResult = int
 
using CbType = std::function< void(IoResult, int64_t, Proactor *)>
 

Public Member Functions

void Run (unsigned ring_depth=512, int wq_fd=-1)
 
void Stop ()
 Signals proactor to stop. Does not wait for it.
 
SubmitEntry GetSubmitEntry (CbType cb, int64_t payload)
 Get the Submit Entry object in order to issue I/O request. More...
 
bool InMyThread () const
 Returns true if the called is running in this Proactor thread. More...
 
auto thread_id () const
 
bool HasFastPoll () const
 
template<typename Func >
void AsyncBrief (Func &&brief)
 
template<typename Func >
auto AwaitBrief (Func &&brief) -> decltype(brief())
 Similarly to AsyncBrief but waits 'f' to return.
 
template<typename Func , typename... Args>
void AsyncFiber (Func &&f, Args &&... args)
 
template<typename... Args>
boost::fibers::fiber LaunchFiber (Args &&... args)
 
template<typename Func >
auto AwaitBlocking (Func &&f) -> decltype(f())
 
void RegisterSignal (std::initializer_list< uint16_t > l, std::function< void(int)> cb)
 
void ClearSignal (std::initializer_list< uint16_t > l)
 
int ring_fd () const
 

Static Public Member Functions

static bool IsProactorThread ()
 
static uint64_t GetMonotonicTimeNs ()
 
static int32_t GetIndex ()
 
static void SetIndex (uint32_t index)
 

Detailed Description

Definition at line 25 of file proactor.h.

Member Function Documentation

◆ AsyncBrief()

template<typename Func >
void util::uring::Proactor::AsyncBrief ( Func &&  brief)

Message passing functions.Fire and forget - does not wait for the function to be called. f should not block, lock on mutexes or Await. Might block the calling fiber if the queue is full.

Definition at line 229 of file proactor.h.

◆ AsyncFiber()

template<typename Func , typename... Args>
void util::uring::Proactor::AsyncFiber ( Func &&  f,
Args &&...  args 
)
inline

Similarly to AsyncBrief but 'f' but wraps 'f' in fiber. f is allowed to fiber-block or await.

Definition at line 117 of file proactor.h.

◆ GetSubmitEntry()

SubmitEntry util::uring::Proactor::GetSubmitEntry ( CbType  cb,
int64_t  payload 
)

Get the Submit Entry object in order to issue I/O request.

Parameters
cb- completion callback.
payload- an argument to the completion callback that is further passed as the second argument to CbType(). Can be nullptr if no notification is required.
Returns
SubmitEntry with initialized userdata.

This method might block the calling fiber therefore it should not be called within proactor context. In other words it can not be called from *Brief([]...) calls to Proactor. In addition, this method can not be used for introducing IOSQE_IO_LINK chains since they require atomic SQE allocation.

Todo:
We should add GetSubmitEntries that can allocate multiple SQEs atomically. In that case we will need RegisterCallback function that takes an unregistered SQE and assigns a callback to it. GetSubmitEntry will be implemented using those functions.

Definition at line 378 of file proactor.cc.

◆ InMyThread()

bool util::uring::Proactor::InMyThread ( ) const
inline

Returns true if the called is running in this Proactor thread.

Returns
true
false

Definition at line 69 of file proactor.h.

◆ Run()

void util::uring::Proactor::Run ( unsigned  ring_depth = 512,
int  wq_fd = -1 
)

If tq_seq_ has changed since it was cached into tq_seq, then EmplaceTaskQueue succeeded and we might have more tasks to execute - lets run the loop again. Otherwise, set tq_seq_ to WAIT_SECTION, hinting that we are going to stall now. Other threads will need to wake-up the ring (see WakeRing()) but only the they will actually syscall only once.

Definition at line 151 of file proactor.cc.


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