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> </ClCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <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\CheckedStaticBox.cpp" />
<ClCompile Include="..\..\src\Utilities\Console.cpp" /> <ClCompile Include="..\..\src\Utilities\Console.cpp" />
<ClCompile Include="..\..\src\Utilities\Exceptions.cpp" /> <ClCompile Include="..\..\src\Utilities\Exceptions.cpp" />
@ -154,6 +158,7 @@
<None Include="..\..\include\Utilities\TlsVariable.inl" /> <None Include="..\..\include\Utilities\TlsVariable.inl" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\include\Utilities\ScopedAlloc.h" />
<ClInclude Include="..\..\src\Utilities\ThreadingInternal.h" /> <ClInclude Include="..\..\src\Utilities\ThreadingInternal.h" />
<ClInclude Include="..\..\include\Utilities\Assertions.h" /> <ClInclude Include="..\..\include\Utilities\Assertions.h" />
<ClInclude Include="..\..\include\Utilities\CheckedStaticBox.h" /> <ClInclude Include="..\..\include\Utilities\CheckedStaticBox.h" />

View File

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

View File

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

View File

@ -18,20 +18,10 @@
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
struct AlignedMallocHeader void* __fastcall _aligned_malloc(size_t size, size_t align)
{
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)
{ {
pxAssert( align < 0x10000 ); pxAssert( align < 0x10000 );
#ifdef _WIN32 #if defined(__USE_ISOC11) && !defined(ASAN_WORKAROUND) // not supported yet on gcc 4.9
return _aligned_malloc(size, align);
#elif defined(__USE_ISOC11) && !defined(ASAN_WORKAROUND) // not supported yet on gcc 4.9
return aligned_alloc(align, size); return aligned_alloc(align, size);
#else #else
void *result = 0; void *result = 0;
@ -40,25 +30,21 @@ void* __fastcall pcsx2_aligned_malloc(size_t size, size_t align)
#endif #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 ); pxAssert( align < 0x10000 );
void* newbuf = pcsx2_aligned_malloc( size, align ); void* newbuf = _aligned_malloc( size, align );
if( handle != NULL ) if( handle != NULL )
{ {
memcpy( newbuf, handle, size ); memcpy( newbuf, handle, size );
pcsx2_aligned_free(handle); _aligned_free(handle);
} }
return newbuf; return newbuf;
} }
__fi void pcsx2_aligned_free(void* pmem) __fi void _aligned_free(void* pmem)
{ {
#ifdef _WIN32
_aligned_free(pmem);
#else
free(pmem); free(pmem);
#endif
} }