userver: userver/os_signals/processor.hpp Source File
Loading...
Searching...
No Matches
processor.hpp
Go to the documentation of this file.
1#pragma once
2
5
8#include <userver/utils/impl/internal_tag.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace os_signals {
13
14#if !defined(__APPLE__)
15
17inline constexpr int kSigUsr1 = 10;
18
20inline constexpr int kSigUsr2 = 12;
21
22#else
23inline constexpr int kSigUsr1 = 30;
24inline constexpr int kSigUsr2 = 31;
25#endif
26
36class Processor final {
37public:
38 explicit Processor(engine::TaskProcessor& task_processor);
39
47 template <class Class>
50 Class* obj,
51 std::string_view name,
52 int signum,
53 void (Class::*func)()
54 ) {
55 channel_.AddListener(scopes, concurrent::FunctionId(obj), name, [obj, func, signum](int sig) {
56 if (sig == signum) {
57 (obj->*func)();
58 }
59 });
60 }
61
68 template <class Class>
69 void AddListener(utils::ResourceScopeStorage& scopes, Class* obj, std::string_view name, void (Class::*func)(int)) {
70 channel_.AddListener(scopes, obj, name, func);
71 }
72
74 // For internal use
75 void Notify(int signum, utils::impl::InternalTag);
77private:
79 engine::TaskProcessor& task_processor_;
80};
81
82} // namespace os_signals
83
84USERVER_NAMESPACE_END