Condy v1.5.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;
16class WorkInvoker;
17
18namespace detail {
19
20class Context : public ThreadLocalSingleton<Context> {
21public:
22 void init(Ring *ring, Runtime *runtime) {
23 ring_ = ring;
24 runtime_ = runtime;
25 bgid_pool_.reset();
26 }
27 void reset() {
28 ring_ = nullptr;
29 runtime_ = nullptr;
30 bgid_pool_.reset();
31 }
32
33 Ring *ring() { return ring_; }
34
35 Runtime *runtime() { return runtime_; }
36
37 uint16_t next_bgid() { return bgid_pool_.allocate(); }
38
39 void recycle_bgid(uint16_t bgid) { bgid_pool_.recycle(bgid); }
40
41private:
42 Ring *ring_ = nullptr;
43 Runtime *runtime_ = nullptr;
44 IdPool<uint16_t> bgid_pool_;
45};
46
47} // namespace detail
48
49} // namespace condy
The event loop runtime for executing asynchronous.
Definition runtime.hpp:68
The main namespace for the Condy library.
Definition condy.hpp:28
Internal utility classes and functions used by Condy.