Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
eval-gc.hh
Go to the documentation of this file.
1#pragma once
3
4#include <cstddef>
5#include <cstring>
6
7// For `NIX_USE_BOEHMGC`
8#include "nix/expr/config.hh"
9
10#if NIX_USE_BOEHMGC
11
12# define GC_INCLUDE_NEW
13# define GC_THREADS 1
14
15# include <gc/gc.h>
16# include <gc/gc_cpp.h>
17# include <gc/gc_allocator.h>
18
28template<typename T>
29struct gc_root_allocator : traceable_allocator<T>
30{
31 using traceable_allocator<T>::traceable_allocator;
32
33 template<typename U>
34 struct rebind
35 {
36 using other = gc_root_allocator<U>;
37 };
38
39 template<typename U>
40 void destroy(U * p)
41 {
42 p->~U();
43 std::memset(static_cast<void *>(p), 0, sizeof(U));
44 }
45};
46
47#else
48
49# include <memory>
50
51/* Some dummy aliases for Boehm GC definitions to reduce the number of
52 #ifdefs. */
53
54template<typename T>
55using traceable_allocator = std::allocator<T>;
56
57template<typename T>
58using gc_allocator = std::allocator<T>;
59
60template<typename T>
61using gc_root_allocator = std::allocator<T>;
62
63# define GC_MALLOC_ATOMIC std::malloc
64
65struct gc
66{};
67
69{};
70
71#endif
72
73namespace nix {
74
78void initGC();
79
83void assertGCInitialized();
84
85#if NIX_USE_BOEHMGC
89size_t getGCCycles();
90#endif
91
92} // namespace nix
Definition eval-gc.hh:69
Definition eval-gc.hh:66