utilities: Simplify _aligned_malloc wrapper

Windows doesn't actually use it at all, so let's exclude it from the
VS build. Also include ScopedAlloc.h into the VS project file.
This commit is contained in:
Jonathan Li 2015-09-11 18:28:17 +01:00
parent 8312e21f00
commit 5c6915f633
4 changed files with 22 additions and 33 deletions

View File

@ -99,7 +99,11 @@
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\src\Utilities\AlignedMalloc.cpp" />
<ClCompile Include="..\..\src\Utilities\AlignedMalloc.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Devel|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\Utilities\CheckedStaticBox.cpp" />
<ClCompile Include="..\..\src\Utilities\Console.cpp" />
<ClCompile Include="..\..\src\Utilities\Exceptions.cpp" />
@ -154,6 +158,7 @@
<None Include="..\..\include\Utilities\TlsVariable.inl" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\Utilities\ScopedAlloc.h" />
<ClInclude Include="..\..\src\Utilities\ThreadingInternal.h" />
<ClInclude Include="..\..\include\Utilities\Assertions.h" />
<ClInclude Include="..\..\include\Utilities\CheckedStaticBox.h" />

View File

@ -23,9 +23,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\Utilities\AlignedMalloc.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Utilities\CheckedStaticBox.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -122,6 +119,9 @@
<ClCompile Include="..\..\src\Utilities\pxWindowTextWriter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Utilities\AlignedMalloc.cpp">
<Filter>Source Files\Linux</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\..\include\Utilities\EventSource.inl">
@ -225,5 +225,8 @@
<ClInclude Include="..\..\include\Utilities\RwMutex.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\include\Utilities\ScopedAlloc.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -48,16 +48,11 @@
#define safe_aligned_free( ptr ) \
((void) ( _aligned_free( ptr ), (ptr) = NULL ))
extern void* __fastcall pcsx2_aligned_malloc(size_t size, size_t align);
extern void* __fastcall pcsx2_aligned_realloc(void* handle, size_t size, size_t align);
extern void pcsx2_aligned_free(void* pmem);
// aligned_malloc: Implement/declare linux equivalents here!
#if !defined(_MSC_VER) && !defined(HAVE_ALIGNED_MALLOC)
# define _aligned_malloc pcsx2_aligned_malloc
# define _aligned_free pcsx2_aligned_free
# define _aligned_realloc pcsx2_aligned_realloc
#if !defined(_MSC_VER)
extern void* __fastcall _aligned_malloc(size_t size, size_t align);
extern void* __fastcall _aligned_realloc(void* handle, size_t size, size_t align);
extern void _aligned_free(void* pmem);
#endif
// --------------------------------------------------------------------------------------

View File

@ -18,20 +18,10 @@
#include "PrecompiledHeader.h"
struct AlignedMallocHeader
{
size_t size; // size of the allocated buffer (minus alignment and header)
void* baseptr; // offset of the original allocated pointer
};
static const uint headsize = sizeof(AlignedMallocHeader);
void* __fastcall pcsx2_aligned_malloc(size_t size, size_t align)
void* __fastcall _aligned_malloc(size_t size, size_t align)
{
pxAssert( align < 0x10000 );
#ifdef _WIN32
return _aligned_malloc(size, align);
#elif defined(__USE_ISOC11) && !defined(ASAN_WORKAROUND) // not supported yet on gcc 4.9
#if defined(__USE_ISOC11) && !defined(ASAN_WORKAROUND) // not supported yet on gcc 4.9
return aligned_alloc(align, size);
#else
void *result = 0;
@ -40,25 +30,21 @@ void* __fastcall pcsx2_aligned_malloc(size_t size, size_t align)
#endif
}
void* __fastcall pcsx2_aligned_realloc(void* handle, size_t size, size_t align)
void* __fastcall _aligned_realloc(void* handle, size_t size, size_t align)
{
pxAssert( align < 0x10000 );
void* newbuf = pcsx2_aligned_malloc( size, align );
void* newbuf = _aligned_malloc( size, align );
if( handle != NULL )
{
memcpy( newbuf, handle, size );
pcsx2_aligned_free(handle);
_aligned_free(handle);
}
return newbuf;
}
__fi void pcsx2_aligned_free(void* pmem)
__fi void _aligned_free(void* pmem)
{
#ifdef _WIN32
_aligned_free(pmem);
#else
free(pmem);
#endif
}