diff --git a/src/jitlayers.cpp b/src/jitlayers.cpp index 92a911273d2fa..4cc1f9a2aa830 100644 --- a/src/jitlayers.cpp +++ b/src/jitlayers.cpp @@ -936,6 +936,7 @@ JuliaOJIT::JuliaOJIT() #endif GlobalJD(ES.createBareJITDylib("JuliaGlobals")), JD(ES.createBareJITDylib("JuliaOJIT")), + ContextPool([](){ return orc::ThreadSafeContext(std::make_unique()); }), #ifdef JL_USE_JITLINK // TODO: Port our memory management optimisations to JITLink instead of using the // default InProcessMemoryManager. diff --git a/src/jitlayers.h b/src/jitlayers.h index 56699c50d78ec..6bd4605acef65 100644 --- a/src/jitlayers.h +++ b/src/jitlayers.h @@ -197,7 +197,7 @@ class JuliaOJIT { template struct ResourcePool { public: - ResourcePool(function_ref creator) : creator(std::move(creator)) {} + ResourcePool(function_ref creator) : creator(std::move(creator)), mutex(std::make_unique()) {} class OwningResource { public: OwningResource(ResourcePool &pool, ResourceT resource) : pool(pool), resource(std::move(resource)) {} @@ -247,7 +247,7 @@ class JuliaOJIT { } ResourceT acquire_() { - std::unique_lock lock(mutex); + std::unique_lock lock(mutex->mutex); if (!pool.empty()) { return pool.pop_back_val(); } @@ -255,21 +255,25 @@ class JuliaOJIT { created++; return creator(); } - empty.wait(lock, [&](){ return !pool.empty(); }); + mutex->empty.wait(lock, [&](){ return !pool.empty(); }); assert(!pool.empty() && "Expected resource pool to have a value!"); return pool.pop_back_val(); } void release_(ResourceT &&resource) { - std::lock_guard lock(mutex); + std::lock_guard lock(mutex->mutex); pool.push_back(std::move(resource)); - empty.notify_one(); + mutex->empty.notify_one(); } private: llvm::function_ref creator; size_t created = 0; llvm::SmallVector pool; - std::mutex mutex; - std::condition_variable empty; + struct WNMutex { + std::mutex mutex; + std::condition_variable empty; + }; + + std::unique_ptr mutex; }; struct OptimizerT { OptimizerT(legacy::PassManager &PM, std::mutex &mutex, int optlevel) : optlevel(optlevel), PM(PM), mutex(mutex) {} @@ -349,7 +353,7 @@ class JuliaOJIT { orc::JITDylib &GlobalJD; orc::JITDylib &JD; - ResourcePool ContextPool{[](){ return orc::ThreadSafeContext(std::make_unique()); }}; + ResourcePool ContextPool; #ifndef JL_USE_JITLINK std::shared_ptr MemMgr;