MCPcopy Create free account
hub / github.com/David-Haim/concurrencpp / callable_vtable

Class callable_vtable

include/concurrencpp/task.h:43–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41
42 template<class callable_type>
43 class callable_vtable {
44
45 private:
46 static callable_type* inline_ptr(void* src) noexcept {
47 return static_cast<callable_type*>(src);
48 }
49
50 static callable_type* allocated_ptr(void* src) noexcept {
51 return *static_cast<callable_type**>(src);
52 }
53
54 static callable_type*& allocated_ref_ptr(void* src) noexcept {
55 return *static_cast<callable_type**>(src);
56 }
57
58 static void move_destroy_inline(void* src, void* dst) noexcept {
59 auto callable_ptr = inline_ptr(src);
60 new (dst) callable_type(std::move(*callable_ptr));
61 callable_ptr->~callable_type();
62 }
63
64 static void move_destroy_allocated(void* src, void* dst) noexcept {
65 auto callable_ptr = std::exchange(allocated_ref_ptr(src), nullptr);
66 new (dst) callable_type*(callable_ptr);
67 }
68
69 static void execute_destroy_inline(void* target) {
70 auto callable_ptr = inline_ptr(target);
71 (*callable_ptr)();
72 callable_ptr->~callable_type();
73 }
74
75 static void execute_destroy_allocated(void* target) {
76 auto callable_ptr = allocated_ptr(target);
77 (*callable_ptr)();
78 delete callable_ptr;
79 }
80
81 static void destroy_inline(void* target) noexcept {
82 auto callable_ptr = inline_ptr(target);
83 callable_ptr->~callable_type();
84 }
85
86 static void destroy_allocated(void* target) noexcept {
87 auto callable_ptr = allocated_ptr(target);
88 delete callable_ptr;
89 }
90
91 static constexpr vtable make_vtable() noexcept {
92 void (*move_destroy_fn)(void* src, void* dst) noexcept = nullptr;
93 void (*destroy_fn)(void* target) noexcept = nullptr;
94
95 if constexpr (std::is_trivially_copy_constructible_v<callable_type> && std::is_trivially_destructible_v<callable_type> &&
96 is_inlinable()) {
97 move_destroy_fn = nullptr;
98 } else {
99 move_destroy_fn = move_destroy;
100 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected