Condy v1.1.0
C++ Asynchronous System Call Layer for Linux
Loading...
Searching...
No Matches
work_type.hpp
Go to the documentation of this file.
1
4
5#pragma once
6
7#include <cassert>
8#include <cstdint>
9#include <utility>
10
11namespace condy {
12
13enum class WorkType : uint8_t {
14 Common,
15 Ignore,
16 Notify,
17 SendFd,
18 Schedule,
19 MultiShot,
20 ZeroCopy,
21};
22
23inline std::pair<void *, WorkType> decode_work(void *ptr) {
24 intptr_t mask = (1 << 3) - 1;
25 intptr_t addr = reinterpret_cast<intptr_t>(ptr);
26 WorkType type = static_cast<WorkType>(addr & mask);
27 // NOLINTNEXTLINE(performance-no-int-to-ptr)
28 void *actual_ptr = reinterpret_cast<void *>(addr & (~mask));
29 return std::make_pair(actual_ptr, type);
30}
31
32inline void *encode_work(void *ptr, WorkType type) {
33 intptr_t addr = reinterpret_cast<intptr_t>(ptr);
34 // Ensure align of 8
35 assert(addr % 8 == 0);
36 addr |= static_cast<intptr_t>(type);
37 // NOLINTNEXTLINE(performance-no-int-to-ptr)
38 return reinterpret_cast<void *>(addr);
39}
40
41} // namespace condy
The main namespace for the Condy library.
Definition condy.hpp:28