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 Context & | get () 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
|
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.
|
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&)).
- Note
- Is strongly recommended to use rili::TaskGuard in most cases instead, which give such guarantee.
- Remarks
- is not blocking.
- is thread safe.
|
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&)).
- Note
- Is strongly recommended to use rili::TaskGuard in most cases instead, which give such guarantee.
- Remarks
- is not blocking.
- is thread safe.
|
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
-
initializer is callback which will be executed to initialize first tasks
- Exceptions
-
rethrow exceptions thrown by Initializer rethrow exceptions 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.
|
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
-
task is 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().
The documentation for this class was generated from the following file:
- rili/Context.hpp