Skip to content

Commit 4d815ec

Browse files
Merge pull request #64 from blueskythlikesclouds/master
Handle ALLOCATOR_FLAG_SINGLETHREADED flag in AllocationObjectAllocator.
2 parents 8991a63 + b901f4d commit 4d815ec

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/D3D12MemAlloc.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,29 +2790,30 @@ class AllocationObjectAllocator
27902790
{
27912791
D3D12MA_CLASS_NO_COPY(AllocationObjectAllocator);
27922792
public:
2793-
AllocationObjectAllocator(const ALLOCATION_CALLBACKS& allocationCallbacks)
2794-
: m_Allocator(allocationCallbacks, 1024) {}
2793+
AllocationObjectAllocator(const ALLOCATION_CALLBACKS& allocationCallbacks, bool useMutex)
2794+
: m_Allocator(allocationCallbacks, 1024), m_UseMutex(useMutex) {}
27952795

27962796
template<typename... Types>
27972797
Allocation* Allocate(Types... args);
27982798
void Free(Allocation* alloc);
27992799

28002800
private:
28012801
D3D12MA_MUTEX m_Mutex;
2802+
bool m_UseMutex;
28022803
PoolAllocator<Allocation> m_Allocator;
28032804
};
28042805

28052806
#ifndef _D3D12MA_ALLOCATION_OBJECT_ALLOCATOR_FUNCTIONS
28062807
template<typename... Types>
28072808
Allocation* AllocationObjectAllocator::Allocate(Types... args)
28082809
{
2809-
MutexLock mutexLock(m_Mutex);
2810+
MutexLock mutexLock(m_Mutex, m_UseMutex);
28102811
return m_Allocator.Alloc(std::forward<Types>(args)...);
28112812
}
28122813

28132814
void AllocationObjectAllocator::Free(Allocation* alloc)
28142815
{
2815-
MutexLock mutexLock(m_Mutex);
2816+
MutexLock mutexLock(m_Mutex, m_UseMutex);
28162817
m_Allocator.Free(alloc);
28172818
}
28182819
#endif // _D3D12MA_ALLOCATION_OBJECT_ALLOCATOR_FUNCTIONS
@@ -6094,7 +6095,7 @@ AllocatorPimpl::AllocatorPimpl(const ALLOCATION_CALLBACKS& allocationCallbacks,
60946095
m_AllocationCallbacks(allocationCallbacks),
60956096
m_CurrentFrameIndex(0),
60966097
// Below this line don't use allocationCallbacks but m_AllocationCallbacks!!!
6097-
m_AllocationObjectAllocator(m_AllocationCallbacks)
6098+
m_AllocationObjectAllocator(m_AllocationCallbacks, m_UseMutex)
60986099
{
60996100
// desc.pAllocationCallbacks intentionally ignored here, preprocessed by CreateAllocator.
61006101
ZeroMemory(&m_D3D12Options, sizeof(m_D3D12Options));

0 commit comments

Comments
 (0)