1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 23:11:16 +02:00

Disable GC inside coroutines on mac OS

This commit is contained in:
Yorick van Pelt 2023-02-03 17:50:01 +01:00 committed by Théophane Hufschmitt
parent 81dfc2b012
commit 2c53ef1bfe
3 changed files with 63 additions and 5 deletions

View file

@ -345,6 +345,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()
@ -368,6 +382,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