Cppgres
Build Postgres extensions in C++
Loading...
Searching...
No Matches
backend.hpp
1#pragma once
2
3#include "imports.h"
4#include "memory.hpp"
5
6namespace cppgres {
7
8enum q { backend };
9
10namespace backend_type {
11
17enum type {
18 invalid = B_INVALID,
19 backend = B_BACKEND,
20 autovac_launcher = B_AUTOVAC_LAUNCHER,
21 autovac_worker = B_AUTOVAC_WORKER,
22 bg_worker = B_BG_WORKER,
23 wal_sender = B_WAL_SENDER,
24#if PG_MAJORVERSION_NUM >= 17
25 slotsync_worker = B_SLOTSYNC_WORKER,
26 standalone_backend = B_STANDALONE_BACKEND,
27#endif
28 archiver = B_ARCHIVER,
29 bg_writer = B_BG_WRITER,
30 checkpointer = B_CHECKPOINTER,
31 startup = B_STARTUP,
32 wal_receiver = B_WAL_RECEIVER,
33#if PG_MAJORVERSION_NUM >= 17
34 wal_summarizer = B_WAL_SUMMARIZER,
35#endif
36 wal_writer = B_WAL_WRITER,
37 logger = B_LOGGER
38};
39}
40
44struct backend {
49 static backend_type::type type() { return static_cast<backend_type::type>(::MyBackendType); };
50
57 template <typename T> requires requires(T t, int code) {
58 { t(code) };
59 }
60 static void atexit(T &&func) {
61 T *raw_mem = top_memory_context().alloc<T>();
62 T *allocation = new (raw_mem) T(std::forward<T>(func));
63
64 ffi_guard{::on_proc_exit}(
65 [](int code, ::Datum datum) {
66 T *func = reinterpret_cast<T *>(DatumGetPointer(datum));
67 (*func)(code);
68 },
69 PointerGetDatum(allocation));
70 }
71};
72
73} // namespace cppgres
Backend management.
Definition: backend.hpp:44
static void atexit(T &&func)
Register a callback for when Postgres will be exiting.
Definition: backend.hpp:60
static backend_type::type type()
get current backend type
Definition: backend.hpp:49
Definition: datum.hpp:35
Definition: guard.hpp:19