VLink  2.0.0
A high-performance communication middleware
vlink::MultiLoop类 参考

MessageLoop subclass that forwards every task to an internal ThreadPool. 更多...

#include <multi_loop.h>

类 vlink::MultiLoop 继承关系图:
vlink::MultiLoop 的协作图:

Public 成员函数

 MultiLoop (size_t thread_num=4U)
 Constructs a MultiLoop with the default kNormalType queue and thread_num workers. 更多...
 
 MultiLoop (size_t thread_num, Type type)
 Constructs a MultiLoop with a specific queue type. 更多...
 
 ~MultiLoop () override
 Defaulted destructor. 更多...
 
bool is_in_same_thread () const override
 Reports whether the calling thread belongs to this loop. 更多...
 
bool wait_for_idle (int ms=Timer::kInfinite, bool check=true) override
 Waits until both the dispatcher queue and the worker pool reach idle. 更多...
 

Protected 成员函数

void on_begin () override
 Hook invoked once on the dispatcher when the loop starts; constructs the worker pool. 更多...
 
void on_end () override
 Hook invoked once on the dispatcher when the loop exits; shuts the worker pool down. 更多...
 
void on_task_changed (Callback &&callback, uint32_t start_time) override
 Forwards a task to the internal pool, falling back to the inline base implementation when the pool rejects the post. 更多...
 

额外继承的成员函数

 Internal queue implementation type. 更多...
 Back-pressure strategy applied when the bounded queue is at capacity. 更多...
 Built-in priority levels for kPriorityType loops; higher values dispatch first. 更多...

详细描述

MessageLoop subclass that forwards every task to an internal ThreadPool.

Inherits every posting API from MessageLoop. The dispatcher pulls tasks from the queue in FIFO order; the worker pool runs them concurrently so execution order is not guaranteed even though enqueue order is.

构造及析构函数说明

◆ MultiLoop() [1/2]

vlink::MultiLoop::MultiLoop ( size_t  thread_num = 4U)
explicit

Constructs a MultiLoop with the default kNormalType queue and thread_num workers.

参数
thread_numWorker count. Default: 4. A zero-worker pool rejects forwarded posts, so tasks fall back to inline execution on the dispatcher.

◆ MultiLoop() [2/2]

vlink::MultiLoop::MultiLoop ( size_t  thread_num,
Type  type 
)
explicit

Constructs a MultiLoop with a specific queue type.

参数
thread_numWorker count.
typeQueue implementation type from MessageLoop::Type.

◆ ~MultiLoop()

vlink::MultiLoop::~MultiLoop ( )
override

Defaulted destructor.

警告
Call quit and wait_for_quit before destruction; the base MessageLoop destructor runs after MultiLoop's members are already torn down and cannot guarantee the worker pool is reset.

成员函数说明

◆ is_in_same_thread()

bool vlink::MultiLoop::is_in_same_thread ( ) const
overridevirtual

Reports whether the calling thread belongs to this loop.

返回
true on the dispatcher or any worker thread of the internal pool.

重载 vlink::MessageLoop .

◆ on_begin()

void vlink::MultiLoop::on_begin ( )
overrideprotectedvirtual

Hook invoked once on the dispatcher when the loop starts; constructs the worker pool.

重载 vlink::MessageLoop .

◆ on_end()

void vlink::MultiLoop::on_end ( )
overrideprotectedvirtual

Hook invoked once on the dispatcher when the loop exits; shuts the worker pool down.

重载 vlink::MessageLoop .

◆ on_task_changed()

void vlink::MultiLoop::on_task_changed ( Callback &&  callback,
uint32_t  start_time 
)
overrideprotectedvirtual

Forwards a task to the internal pool, falling back to the inline base implementation when the pool rejects the post.

参数
callbackTask to dispatch.
start_timeMillisecond steady_clock timestamp captured at enqueue time.

重载 vlink::MessageLoop .

◆ wait_for_idle()

bool vlink::MultiLoop::wait_for_idle ( int  ms = Timer::kInfinite,
bool  check = true 
)
overridevirtual

Waits until both the dispatcher queue and the worker pool reach idle.

参数
msMaximum wait in milliseconds; Timer::kInfinite means no limit.
checkWhen true, rejects calls from threads owned by this loop.
返回
true when both queues drained before the timeout.

重载 vlink::MessageLoop .


该类的文档由以下文件生成: