Condy v1.6.0
C++ Asynchronous System Call Layer for Linux
Loading...
Searching...
No Matches
context.hpp
Go to the documentation of this file.
1
4
5#pragma once
6
7#include "condy/singleton.hpp"
8#include "condy/utils.hpp"
9#include <cassert>
10#include <cstdint>
11
12namespace condy {
13
14class Ring;
15class Runtime;
16
17namespace detail {
18
19class Context : public ThreadLocalSingleton<Context> {
20public:
21 void init(Ring *ring, Runtime *runtime) noexcept {
22 ring_ = ring;
23 runtime_ = runtime;
24 bgid_pool_.reset();
25 }
26 void reset() noexcept {
27 ring_ = nullptr;
28 runtime_ = nullptr;
29 bgid_pool_.reset();
30 }
31
32 Ring *ring() noexcept { return ring_; }
33
34 Runtime *runtime() noexcept { return runtime_; }
35
36 uint16_t next_bgid() { return bgid_pool_.allocate(); }
37
38 void recycle_bgid(uint16_t bgid) noexcept { bgid_pool_.recycle(bgid); }
39
40private:
41 Ring *ring_ = nullptr;
42 Runtime *runtime_ = nullptr;
43 IdPool<uint16_t> bgid_pool_;
44};
45
46} // namespace detail
47
48} // namespace condy
The event loop runtime for executing asynchronous.
Definition runtime.hpp:111
The main namespace for the Condy library.
Definition condy.hpp:30
Internal utility classes and functions used by Condy.