userver: userver/engine/task/current_task.hpp Source File
Loading...
Searching...
No Matches
current_task.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/engine/task/current_task.hpp
4/// @brief Utility functions that query and operate on the current task
5
6#include <cstddef>
7#include <cstdint>
8
9#include <userver/engine/task/task_processor_fwd.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace engine::ev {
14class ThreadControl;
15} // namespace engine::ev
16
17namespace engine {
18
19class Deadline;
20
21/// @brief Namespace with functions to work with current task from within it
22namespace current_task {
23
24/// Returns true only when running in userver coroutine environment,
25/// i.e. in an engine::TaskProcessor thread.
26bool IsTaskProcessorThread() noexcept;
27
28/// Returns reference to the task processor executing the caller
29TaskProcessor& GetTaskProcessor();
30
31/// @brief Get the number of worker threads in the current task processor.
32///
33/// The value is configured with the `task_processors.*NAME*.worker_threads`
34/// static option of @ref components::ManagerControllerComponent.
35///
36/// @see @ref engine::GetWorkerCount
37std::size_t GetWorkerCount();
38
39/// Returns reference to the blocking task processor
40TaskProcessor& GetBlockingTaskProcessor();
41
42/// Returns task coroutine stack size
43std::size_t GetStackSize();
44
45/// @cond
46// Returns ev thread handle, internal use only
47ev::ThreadControl& GetEventThread();
48/// @endcond
49
50namespace impl {
51
52// For internal use only.
53void* GetRawCurrentTaskContext() noexcept;
54
55// For internal use only.
56bool IsCritical();
57
58// Note: an actually useful deadline should be acquired from server::request::GetTaskInheritedDeadline.
59// For internal use only.
60Deadline GetDeadline() noexcept;
61
62} // namespace impl
63
64} // namespace current_task
65
66namespace impl {
67
68// For internal use only.
69std::uint64_t GetCreatedTaskCount(TaskProcessor&);
70
71} // namespace impl
72
73} // namespace engine
74
75USERVER_NAMESPACE_END