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/// Returns reference to the blocking task processor
32TaskProcessor& GetBlockingTaskProcessor();
33
34/// Returns task coroutine stack size
35std::size_t GetStackSize();
36
37/// @cond
38// Returns ev thread handle, internal use only
39ev::ThreadControl& GetEventThread();
40/// @endcond
41
42namespace impl {
43
44// For internal use only.
45void* GetRawCurrentTaskContext() noexcept;
46
47// For internal use only.
48bool IsCritical();
49
50// Note: an actually useful deadline should be acquired from server::request::GetTaskInheritedDeadline.
51// For internal use only.
52Deadline GetDeadline() noexcept;
53
54} // namespace impl
55
56} // namespace current_task
57
58namespace impl {
59
60// For internal use only.
61std::uint64_t GetCreatedTaskCount(TaskProcessor&);
62
63} // namespace impl
64
65} // namespace engine
66
67USERVER_NAMESPACE_END