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

Shared observable handle returned by tracked posting APIs. 更多...

#include <task_handle.h>

vlink::TaskHandle 的协作图:

Public 成员函数

 TaskHandle () noexcept
 Constructs an invalid handle that references no task. 更多...
 
 ~TaskHandle ()
 Destroys the handle reference. 更多...
 
 TaskHandle (const TaskHandle &) noexcept
 Copy-constructs a handle that shares state with other. 更多...
 
TaskHandleoperator= (const TaskHandle &) noexcept
 Copy-assigns from another handle; both handles share state afterwards. 更多...
 
 TaskHandle (TaskHandle &&) noexcept
 Move-constructs a handle, transferring the shared state from the source. 更多...
 
TaskHandleoperator= (TaskHandle &&) noexcept
 Move-assigns from another handle, transferring its shared state. 更多...
 
bool valid () const noexcept
 Reports whether this handle refers to a live task state block. 更多...
 
TaskExecutionState state () const noexcept
 Returns the current lifecycle stage of the task. 更多...
 
bool is_done () const noexcept
 Reports whether the task has reached a terminal state. 更多...
 
CancellationToken cancellation_token () const noexcept
 Returns the task-local cancellation token associated with this handle. 更多...
 
bool cancel () const
 Requests cooperative cancellation of the task. 更多...
 
bool wait (int timeout_ms=kInfinite) const
 Blocks until the task reaches a terminal state or the timeout elapses. 更多...
 

静态 Public 属性

static constexpr int kInfinite {-1}
 Sentinel timeout value for wait() meaning wait indefinitely. 更多...
 

友元

class MessageLoop
 
class ThreadPool
 
class TrackedTask
 

详细描述

Shared observable handle returned by tracked posting APIs.

Backed by a std::shared_ptr to an internal state block, so copies and moves all point at the same task. Provides cooperative cancellation, blocking wait on the terminal state, and a task-local CancellationToken that running callbacks can poll.

构造及析构函数说明

◆ TaskHandle() [1/3]

vlink::TaskHandle::TaskHandle ( )
noexcept

Constructs an invalid handle that references no task.

valid() returns false and state() returns TaskExecutionState::kInvalid.

◆ ~TaskHandle()

vlink::TaskHandle::~TaskHandle ( )

Destroys the handle reference.

注解
Destruction does not cancel the associated task; the dispatcher retains its own reference to the state block.

◆ TaskHandle() [2/3]

vlink::TaskHandle::TaskHandle ( const TaskHandle )
noexcept

Copy-constructs a handle that shares state with other.

◆ TaskHandle() [3/3]

vlink::TaskHandle::TaskHandle ( TaskHandle &&  )
noexcept

Move-constructs a handle, transferring the shared state from the source.

成员函数说明

◆ cancel()

bool vlink::TaskHandle::cancel ( ) const

Requests cooperative cancellation of the task.

No-op when the handle is invalid or already terminal. When the task has not started running (kInvalid or kQueued) this call transitions the state to kCancelled; in any non-terminal case it also flips the cancellation source so running callbacks polling the token observe the request.

返回
true when this call either transitioned the state or flipped the source; false when the handle was invalid or already terminal.

◆ cancellation_token()

CancellationToken vlink::TaskHandle::cancellation_token ( ) const
noexcept

Returns the task-local cancellation token associated with this handle.

Running callbacks may poll this token for cooperative abort. Callbacks registered on the token fire outside the handle mutex, so they may safely re-enter the handle.

返回
Associated token; an empty token when the handle is not valid.

◆ is_done()

bool vlink::TaskHandle::is_done ( ) const
noexcept

Reports whether the task has reached a terminal state.

返回
true once state() is one of kCompleted, kCancelled, kDropped, kRejected or kFailed.

◆ operator=() [1/2]

TaskHandle& vlink::TaskHandle::operator= ( const TaskHandle )
noexcept

Copy-assigns from another handle; both handles share state afterwards.

返回
Reference to *this.

◆ operator=() [2/2]

TaskHandle& vlink::TaskHandle::operator= ( TaskHandle &&  )
noexcept

Move-assigns from another handle, transferring its shared state.

返回
Reference to *this.

◆ state()

TaskExecutionState vlink::TaskHandle::state ( ) const
noexcept

Returns the current lifecycle stage of the task.

返回
Latest TaskExecutionState; kInvalid when the handle is not valid.

◆ valid()

bool vlink::TaskHandle::valid ( ) const
noexcept

Reports whether this handle refers to a live task state block.

返回
false when default-constructed or moved-from.

◆ wait()

bool vlink::TaskHandle::wait ( int  timeout_ms = kInfinite) const

Blocks until the task reaches a terminal state or the timeout elapses.

Never throws on cancellation; inspect state() after the call to distinguish the possible outcomes.

参数
timeout_msMaximum wait in milliseconds; kInfinite waits forever.
返回
true when a terminal state was reached before the deadline.

友元及相关函数文档

◆ MessageLoop

friend class MessageLoop
friend

◆ ThreadPool

friend class ThreadPool
friend

◆ TrackedTask

friend class TrackedTask
friend

类成员变量说明

◆ kInfinite

constexpr int vlink::TaskHandle::kInfinite {-1}
staticconstexpr

Sentinel timeout value for wait() meaning wait indefinitely.


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