Skip to content

Commit

Permalink
Use queue instead of stack to reduce memory usage, lock around shared…
Browse files Browse the repository at this point in the history
… data structure
  • Loading branch information
pchintalapudi committed Apr 14, 2022
1 parent 61a065f commit ee35c40
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,11 +673,12 @@ struct IndependentMemoryManager {
// A simple forwarding class, since OrcJIT v2 needs a unique_ptr, while we have a shared_ptr
class ForwardingMemoryManager : public RuntimeDyld::MemoryManager {
private:
JuliaOJIT::ResourcePool<IndependentMemoryManager> memmgrs{[](){ return IndependentMemoryManager{false, std::unique_ptr<RTDyldMemoryManager>(createRTDyldMemoryManager())}; }};
JuliaOJIT::ResourcePool<IndependentMemoryManager, 0, std::queue<IndependentMemoryManager>> memmgrs{[](){ return IndependentMemoryManager{false, std::unique_ptr<RTDyldMemoryManager>(createRTDyldMemoryManager())}; }};
std::map<std::thread::id, SmallVector<IndependentMemoryManager>> local_stacks;
std::mutex mutex;

IndependentMemoryManager &getMemMgr(bool code = false) {
std::lock_guard<std::mutex> lock(mutex);
auto &stack = local_stacks[std::this_thread::get_id()];
if (stack.empty() || (stack.back().code_allocated && code)) {
stack.push_back(memmgrs.acquire());
Expand Down

0 comments on commit ee35c40

Please sign in to comment.