Added more stuff like Logging, DynamicPointer, utilities for using STL allocators and NotNullable.
This commit is contained in:
@@ -5,11 +5,14 @@
|
||||
#include "../debug/assert.hpp"
|
||||
|
||||
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
||||
#include <bit>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <dlfcn.h>
|
||||
#include <pthread.h>
|
||||
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
||||
#include <array>
|
||||
#include <malloc.h>
|
||||
#include <windows.h>
|
||||
#include "../util/winundef.hpp"
|
||||
#endif
|
||||
@@ -139,4 +142,40 @@ std::string getExecutablePath() MIJIN_NOEXCEPT
|
||||
#endif
|
||||
}
|
||||
|
||||
void* alignedAlloc(std::size_t alignment, std::size_t size) MIJIN_NOEXCEPT
|
||||
{
|
||||
#if MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
||||
return _aligned_alloc(size, alignment);
|
||||
#else
|
||||
return std::aligned_alloc(alignment, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* alignedRealloc(void* ptr, std::size_t alignment, std::size_t size) MIJIN_NOEXCEPT
|
||||
{
|
||||
#if MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
||||
return _aligned_realloc(ptr, size, alignment);
|
||||
#else
|
||||
void* newPtr = std::realloc(ptr, size);
|
||||
if (newPtr == ptr || (std::bit_cast<std::uintptr_t>(newPtr) % alignment) == 0)
|
||||
{
|
||||
return newPtr;
|
||||
}
|
||||
// bad luck, have to copy a second time
|
||||
void* newPtr2 = std::aligned_alloc(alignment, size);
|
||||
std::memcpy(newPtr2, newPtr, size);
|
||||
std::free(newPtr);
|
||||
return newPtr2;
|
||||
#endif
|
||||
}
|
||||
|
||||
void alignedFree(void* ptr)
|
||||
{
|
||||
#if MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
||||
_aligned_free(ptr);
|
||||
#else
|
||||
std::free(ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace mijin
|
||||
|
||||
Reference in New Issue
Block a user