Condy v1.5.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 SendFd,
17 Schedule,
18};
19
20inline std::pair<void *, WorkType> decode_work(void *ptr) {
21 intptr_t mask = (1 << 3) - 1;
22 intptr_t addr = reinterpret_cast<intptr_t>(ptr);
23 WorkType type = static_cast<WorkType>(addr & mask);
24 // NOLINTNEXTLINE(performance-no-int-to-ptr)
25 void *actual_ptr = reinterpret_cast<void *>(addr & (~mask));
26 return std::make_pair(actual_ptr, type);
27}
28
29inline void *encode_work(void *ptr, WorkType type) {
30 intptr_t addr = reinterpret_cast<intptr_t>(ptr);
31 // Ensure align of 8
32 assert(addr % 8 == 0);
33 addr |= static_cast<intptr_t>(type);
34 // NOLINTNEXTLINE(performance-no-int-to-ptr)
35 return reinterpret_cast<void *>(addr);
36}
37
38} // namespace condy
The main namespace for the Condy library.
Definition condy.hpp:28