Public Types

typedef std::function< void()> Initializer
 
typedef std::function< void()> Task
 

Public Member Functions

void schedule (Task const &task) noexcept
 
void reserve () noexcept
 
void release () noexcept
 

Static Public Member Functions

static void run (Initializer const &initializer)
 
static Contextget () noexcept
 

Detailed Description

Each thread may have single private rili::Context which can be pass between asynchronous task sources and sinks to signal new task execution reservation or result. Tasks execution start when run method is called within thread.

Execution is stoped when:

  • there is no "reserved" task requests
  • there is no "ready" to execute tasks

How to use:

  • To reserve task which will be ready in future rili::Context::reserve() should be used.
  • To release reserved previously future task release() should be used.
  • To signal ready to execute task schedule(Task const&) should be used.
  • To create or get context instance for current thread get() should be used.

No two rili::Context may represent the same task execution and no two rili::Context may be owned by the same thread.

Remarks
is non-copyable.
See also
rili::TaskGuard

Member Typedef Documentation

typedef std::function<void()> rili::Context::Initializer

is used as type which is accepted by rili::Context::run

typedef std::function<void()> rili::Context::Task

is used as type which is accepted by rili::Context::schedule

Member Function Documentation

static Context& rili::Context::get ( )
staticnoexcept

Get or create rili::Context for current thread.

New rili::Context is created if was not created earlier for current thread. If rili::Context was created previously return existing instance.

Returns
rili::Context associated to current thread.
Remarks
rili::Context reference will be invalidated when associated thread will end.
void rili::Context::release ( )
noexcept

Signals rili::Context that previously reserved task was completed.

For rili::Context it means that it should stop waiting for completion of this task. Each use of this method always should come in pair with rili::Context::reserve() (and optionally rili::Context::schedule(Task const&)).

Warning
Every release() call must have corresponding previous reserve().
Note
Is strongly recommended to use rili::TaskGuard in most cases instead, which give such guarantee.
Remarks
is not blocking.
is thread safe.
See also
rili::TaskGuard
rili::Context::reserve()
rili::Context::schedule(Task const&)
void rili::Context::reserve ( )
noexcept

Signals rili::Context that there will be in future task to execute but is not ready yet.

For rili::Context it means that it should wait for new ready task if there are no tasks to execute. Each use of this method always should come in pair with rili::Context::release() (and optionally rili::Context::schedule(Task const&)).

Warning
Every reserve() call must be followed finally by corresponding release().
Note
Is strongly recommended to use rili::TaskGuard in most cases instead, which give such guarantee.
Remarks
is not blocking.
is thread safe.
See also
rili::TaskGuard
rili::Context::release()
rili::Context::schedule(Task const&)
static void rili::Context::run ( Initializer const &  initializer)
static

Execute given Initializer in own scope.

After that execute ready tasks and wait until all reserved tasks will be completed (and when will be ready immediately execute).

Parameters
initializeris callback which will be executed to initialize first tasks
Exceptions
rethrowexceptions thrown by Initializer
rethrowexceptions thrown by tasks from rili::Context::schedule(Task const&)
Remarks
Is blocking.
Returns when there are no reserved "future tasks" nor ready tasks to execute in current thread.
Can be called multiple times within the same thread.
void rili::Context::schedule ( Task const &  task)
noexcept

Is used to signal rili::Context about existing "ready to run" task. It will be executed in associated thread as soon as possible.

Parameters
taskis function which will be executed in socope of given rili::Context instance.
Note
Typically schedule(Task const&) should be called after reserve() and before release().
See also
rili::Context::reserve()
rili::Context::release()
rili::TaskGuard

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