Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
gc.hh
Go to the documentation of this file.
1#pragma once
3
4#include "nix/expr/eval-gc.hh"
5#include "nix/util/finally.hh"
6
7#include <gtest/gtest.h>
8
9#include <thread>
10#include <exception>
11
12#if NIX_USE_BOEHMGC
13
14namespace nix {
15
23inline void runOnGCThread(auto fn)
24{
25 std::exception_ptr exception;
26 std::thread([&] {
27 try {
28 GC_stack_base base;
29 ASSERT_EQ(GC_SUCCESS, GC_get_stack_base(&base));
30 auto registered = GC_register_my_thread(&base);
31 ASSERT_TRUE(registered == GC_SUCCESS || registered == GC_DUPLICATE);
32 Finally unregister([&] {
33 if (registered == GC_SUCCESS)
34 GC_unregister_my_thread();
35 });
36 fn();
37 } catch (...) {
38 exception = std::current_exception();
39 }
40 }).join();
41 if (exception)
42 std::rethrow_exception(exception);
43}
44
45} // namespace nix
46
47#endif
Definition finally.hh:15