mirror of
https://github.com/NixOS/nix
synced 2025-06-28 09:31:16 +02:00
Disable GC inside coroutines on mac OS
This commit is contained in:
parent
0fd8f542a8
commit
eaeb994d8b
4 changed files with 74 additions and 5 deletions
|
@ -326,6 +326,20 @@ static Symbol getName(const AttrName & name, EvalState & state, Env & env)
|
|||
}
|
||||
|
||||
|
||||
class BoehmDisableGC : public DisableGC {
|
||||
public:
|
||||
BoehmDisableGC() {
|
||||
#if HAVE_BOEHMGC
|
||||
GC_disable();
|
||||
#endif
|
||||
};
|
||||
virtual ~BoehmDisableGC() override {
|
||||
#if HAVE_BOEHMGC
|
||||
GC_enable();
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
static bool gcInitialised = false;
|
||||
|
||||
void initGC()
|
||||
|
@ -349,6 +363,12 @@ void initGC()
|
|||
|
||||
StackAllocator::defaultAllocator = &boehmGCStackAllocator;
|
||||
|
||||
|
||||
/* Used to disable GC when entering coroutines on macOS */
|
||||
DisableGC::create = []() {
|
||||
return std::dynamic_pointer_cast<DisableGC>(std::make_shared<BoehmDisableGC>());
|
||||
};
|
||||
|
||||
/* Set the initial heap size to something fairly big (25% of
|
||||
physical RAM, up to a maximum of 384 MiB) so that in most cases
|
||||
we don't need to garbage collect at all. (Collection has a
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace nix {
|
|||
|
||||
// Generate 2 objects, discard one, run gc,
|
||||
// see if one got collected and the other didn't
|
||||
// GC is disabled inside coroutines on __APPLE__
|
||||
static void testFinalizerCalls() {
|
||||
bool* do_collect_collected = uncollectable_bool();
|
||||
bool* dont_collect_collected = uncollectable_bool();
|
||||
|
@ -37,7 +38,9 @@ namespace nix {
|
|||
GC_gcollect();
|
||||
GC_invoke_finalizers();
|
||||
|
||||
#if !__APPLE__
|
||||
ASSERT_TRUE(*do_collect_collected);
|
||||
#endif
|
||||
ASSERT_FALSE(*dont_collect_collected);
|
||||
ASSERT_NE(nullptr, dont_collect);
|
||||
}
|
||||
|
@ -58,6 +61,10 @@ namespace nix {
|
|||
}
|
||||
|
||||
auto source = sinkToSource([&](Sink& sink) {
|
||||
|
||||
#if __APPLE__
|
||||
ASSERT_TRUE(GC_is_disabled());
|
||||
#endif
|
||||
testFinalizerCalls();
|
||||
|
||||
bool* dont_collect_inner_collected = uncollectable_bool();
|
||||
|
@ -71,6 +78,9 @@ namespace nix {
|
|||
}
|
||||
// pass control to main
|
||||
writeString("foo", sink);
|
||||
#if __APPLE__
|
||||
ASSERT_TRUE(GC_is_disabled());
|
||||
#endif
|
||||
|
||||
ASSERT_TRUE(*do_collect_inner_collected);
|
||||
ASSERT_FALSE(*dont_collect_inner_collected);
|
||||
|
@ -84,6 +94,7 @@ namespace nix {
|
|||
std::string foo = readString(*source);
|
||||
ASSERT_EQ(foo, "foo");
|
||||
|
||||
ASSERT_FALSE(GC_is_disabled());
|
||||
GC_gcollect();
|
||||
GC_invoke_finalizers();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue