mirror of
https://github.com/vortexgpgpu/vortex.git
synced 2025-04-24 13:57:17 -04:00
replace local static allocator to global static
Ensure MemoryPool construct before SimPlatform, thus MemoryPool destruct after SimPlatform. Avoid use-after-free issue clearing events_ of SimPlatform after SimPortEvent's allocator is destructed.
This commit is contained in:
parent
2e7ab99d28
commit
b0d1b02859
1 changed files with 12 additions and 12 deletions
|
@ -176,23 +176,23 @@ public:
|
|||
{}
|
||||
|
||||
void* operator new(size_t /*size*/) {
|
||||
return allocator().allocate();
|
||||
return allocator_.allocate();
|
||||
}
|
||||
|
||||
void operator delete(void* ptr) {
|
||||
allocator().deallocate(ptr);
|
||||
allocator_.deallocate(ptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
Func func_;
|
||||
Pkt pkt_;
|
||||
|
||||
static MemoryPool<SimCallEvent<Pkt>>& allocator() {
|
||||
static MemoryPool<SimCallEvent<Pkt>> instance(64);
|
||||
return instance;
|
||||
}
|
||||
static MemoryPool<SimCallEvent<Pkt>> allocator_;
|
||||
};
|
||||
|
||||
template <typename Pkt>
|
||||
MemoryPool<SimCallEvent<Pkt>> SimCallEvent<Pkt>::allocator_(64);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <typename Pkt>
|
||||
|
@ -209,23 +209,23 @@ public:
|
|||
{}
|
||||
|
||||
void* operator new(size_t /*size*/) {
|
||||
return allocator().allocate();
|
||||
return allocator_.allocate();
|
||||
}
|
||||
|
||||
void operator delete(void* ptr) {
|
||||
allocator().deallocate(ptr);
|
||||
allocator_.deallocate(ptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
const SimPort<Pkt>* port_;
|
||||
Pkt pkt_;
|
||||
|
||||
static MemoryPool<SimPortEvent<Pkt>>& allocator() {
|
||||
static MemoryPool<SimPortEvent<Pkt>> instance(64);
|
||||
return instance;
|
||||
}
|
||||
static MemoryPool<SimPortEvent<Pkt>> allocator_;
|
||||
};
|
||||
|
||||
template <typename Pkt>
|
||||
MemoryPool<SimPortEvent<Pkt>> SimPortEvent<Pkt>::allocator_(64);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SimContext;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue