Skip to content

Commit

Permalink
don't use thread_local for gc_enabled on Mac
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenmeker committed Oct 30, 2024
1 parent 826694f commit 8834f60
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
8 changes: 7 additions & 1 deletion include/runtime/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ size_t hash_k(block *);
void k_hash(block *, void *);
bool hash_enter(void);
void hash_exit(void);

#ifdef __MACH__
//
// thread_local disabled for Apple
//
extern bool gc_enabled;
#else
extern thread_local bool gc_enabled;
#endif
}

class k_elem {
Expand Down
16 changes: 14 additions & 2 deletions lib/codegen/CreateTerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,11 +782,17 @@ llvm::Value *create_term::disable_gc() {
llvm::Constant *global
= module_->getOrInsertGlobal("gc_enabled", llvm::Type::getInt1Ty(ctx_));
auto *global_var = llvm::cast<llvm::GlobalVariable>(global);
global_var->setThreadLocal(true);
#ifdef __MACH__
//
// thread_local disabled for Apple
//
/*
global_var->setThreadLocal(true);
llvm::IRBuilder b(current_block_);
auto *global_var_address = b.CreateThreadLocalAddress(global_var);
*/
#else
global_var->setThreadLocal(true);
auto *global_var_address = global_var;
#endif
auto *old_val = new llvm::LoadInst(
Expand All @@ -801,11 +807,17 @@ void create_term::enable_gc(llvm::Value *was_enabled) {
llvm::Constant *global
= module_->getOrInsertGlobal("gc_enabled", llvm::Type::getInt1Ty(ctx_));
auto *global_var = llvm::cast<llvm::GlobalVariable>(global);
global_var->setThreadLocal(true);
#ifdef __MACH__
//
// thread_local disabled for Apple
//
/*
global_var->setThreadLocal(true);
llvm::IRBuilder b(current_block_);
auto *global_var_address = b.CreateThreadLocalAddress(global_var);
*/
#else
global_var->setThreadLocal(true);
auto *global_var_address = global_var;
#endif
new llvm::StoreInst(was_enabled, global_var_address, current_block_);
Expand Down
7 changes: 7 additions & 0 deletions runtime/alloc/arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,14 @@ static void fresh_block(struct arena *arena) {
BLOCK_SIZE - sizeof(memory_block_header));
}

#ifdef __MACH__
//
// thread_local disabled for Apple
//
bool gc_enabled = true;
#else
thread_local bool gc_enabled = true;
#endif

__attribute__((noinline)) void *
do_alloc_slow(size_t requested, struct arena *arena) {
Expand Down
8 changes: 8 additions & 0 deletions unittests/runtime-collections/lists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ block D1 = {{1}};
block *DUMMY1 = &D1;
}

#ifdef __MACH__
//
// thread_local disabled for Apple
//
bool gc_enabled;
#else
thread_local bool gc_enabled;
#endif

size_t get_gc_threshold() {
return SIZE_MAX;
}
Expand Down

0 comments on commit 8834f60

Please sign in to comment.