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
19/// @brief Namespace with functions to work with current task from within it
20namespace current_task {
21
22/// Returns true only when running in userver coroutine environment,
23/// i.e. in an engine::TaskProcessor thread.
24bool IsTaskProcessorThread() noexcept;
25
26/// Returns reference to the task processor executing the caller
27TaskProcessor& GetTaskProcessor();
28
29/// Returns reference to the blocking task processor
30TaskProcessor& GetBlockingTaskProcessor();
31
32/// Returns task coroutine stack size
33std::size_t GetStackSize();
34
35/// @cond
36// Returns ev thread handle, internal use only
37ev::ThreadControl& GetEventThread();
38/// @endcond
39
40namespace impl {
41
42// For internal use only.
43void* GetRawCurrentTaskContext() noexcept;
44
45// For internal use only.
46bool IsCritical();
47
48} // namespace impl
49
50} // namespace current_task
51
52namespace impl {
53
54// For internal use only.
55std::uint64_t GetCreatedTaskCount(TaskProcessor&);
56
57} // namespace impl
58
59} // namespace engine
60
61USERVER_NAMESPACE_END