fixes for windows
parent
e81f590f5e
commit
ea16aa3847
|
@ -546,6 +546,7 @@ namespace blt
|
|||
template<typename T, bool WARN_ON_FAIL = false>
|
||||
static inline T* allocate_huge_page(blt::size_t BLOCK_SIZE, blt::size_t HUGE_PAGE_SIZE = BLT_2MB_SIZE)
|
||||
{
|
||||
#ifdef __unix__
|
||||
BLT_ASSERT((BLOCK_SIZE & (HUGE_PAGE_SIZE - 1)) == 0 && "Must be multiple of the huge page size!");
|
||||
T* buffer = static_cast<T*>(mmap(nullptr, BLOCK_SIZE, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, -1, 0));
|
||||
|
@ -578,6 +579,8 @@ namespace blt
|
|||
BLT_ERROR("Offset by %ld pages, resulting: %p", (reinterpret_cast<blt::size_t>(buffer) - ptr_size) / 4096, buffer);
|
||||
}
|
||||
return buffer;
|
||||
#endif
|
||||
return malloc(BLOCK_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -701,7 +704,7 @@ namespace blt
|
|||
} else
|
||||
buffer = reinterpret_cast<block*>(std::aligned_alloc(BLOCK_SIZE, BLOCK_SIZE));
|
||||
#else
|
||||
buffer = reinterpret_cast<block*>(std::aligned_alloc(BLOCK_SIZE, BLOCK_SIZE));
|
||||
buffer = static_cast<block*>(_aligned_malloc(BLOCK_SIZE, BLOCK_SIZE));
|
||||
#endif
|
||||
construct(buffer);
|
||||
#ifndef BLT_DISABLE_STATS
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
#if defined(__clang__) || defined(__llvm__) || defined(__GNUC__) || defined(__GNUG__)
|
||||
|
||||
#if defined(__GNUC__) || defined(__GNUG__)
|
||||
#if (defined(__GNUC__) || defined(__GNUG__)) && !defined(WIN32)
|
||||
|
||||
#include <byteswap.h>
|
||||
|
||||
|
|
|
@ -95,7 +95,11 @@ namespace blt
|
|||
public:
|
||||
void* allocate(blt::size_t bytes) // NOLINT
|
||||
{
|
||||
#ifdef WIN32
|
||||
return _aligned_malloc(bytes, BLT_2MB_SIZE);
|
||||
#else
|
||||
return std::aligned_alloc(BLT_2MB_SIZE, bytes);
|
||||
#endif
|
||||
}
|
||||
|
||||
void deallocate(void* ptr, blt::size_t) // NOLINT
|
||||
|
|
|
@ -146,7 +146,7 @@ namespace blt::system
|
|||
std::uint64_t dt;
|
||||
};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
using suseconds_t = std::size_t;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 4817a6d3b8407063cf0328eb92dbb27ee2f55528
|
||||
Subproject commit 2d0b499273ea02f7211ae2af705418c9509691fb
|
|
@ -13,7 +13,7 @@
|
|||
#include <exception>
|
||||
#include <cstring>
|
||||
|
||||
struct abort_exception : public std::exception
|
||||
struct abort_exception final : public std::exception
|
||||
{
|
||||
public:
|
||||
explicit abort_exception(const char* what)
|
||||
|
@ -42,14 +42,18 @@ struct abort_exception : public std::exception
|
|||
char* error{nullptr};
|
||||
};
|
||||
|
||||
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__)
|
||||
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) && !defined(WIN32)
|
||||
#define IS_GNU_BACKTRACE
|
||||
#endif
|
||||
|
||||
#ifdef IS_GNU_BACKTRACE
|
||||
|
||||
#include <execinfo.h>
|
||||
#include <cstdlib>
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__)
|
||||
#if IS_GNU_BACKTRACE
|
||||
#define BLT_STACK_TRACE(number) void* ptrs[number]; \
|
||||
int size = backtrace(ptrs, number); \
|
||||
char** messages = backtrace_symbols(ptrs, size);
|
||||
|
@ -64,7 +68,7 @@ struct abort_exception : public std::exception
|
|||
namespace blt
|
||||
{
|
||||
|
||||
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__)
|
||||
#if IS_GNU_BACKTRACE
|
||||
|
||||
static inline std::string _macro_filename(const std::string& path)
|
||||
{
|
||||
|
@ -79,7 +83,7 @@ namespace blt
|
|||
|
||||
void b_throw(const char* what, const char* path, int line)
|
||||
{
|
||||
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__)
|
||||
#if IS_GNU_BACKTRACE
|
||||
BLT_STACK_TRACE(50);
|
||||
|
||||
BLT_ERROR("An exception '%s' has occurred in file '%s:%d'", what, path, line);
|
||||
|
@ -96,7 +100,7 @@ namespace blt
|
|||
|
||||
void b_assert_failed(const char* expression, const char* msg, const char* path, int line)
|
||||
{
|
||||
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__)
|
||||
#if IS_GNU_BACKTRACE
|
||||
BLT_STACK_TRACE(50);
|
||||
|
||||
BLT_ERROR("The assertion '%s' has failed in file '%s:%d'", expression, path, line);
|
||||
|
@ -122,7 +126,7 @@ namespace blt
|
|||
{
|
||||
if (messages == nullptr)
|
||||
return;
|
||||
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__)
|
||||
#if IS_GNU_BACKTRACE
|
||||
for (int i = 1; i < size; i++)
|
||||
{
|
||||
int tabs = i - 1;
|
||||
|
@ -167,13 +171,13 @@ namespace blt
|
|||
|
||||
void b_abort(const char* what, const char* path, int line)
|
||||
{
|
||||
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__)
|
||||
#if IS_GNU_BACKTRACE
|
||||
BLT_STACK_TRACE(50);
|
||||
#endif
|
||||
BLT_FATAL("----{BLT ABORT}----");
|
||||
BLT_FATAL("\tWhat: %s", what);
|
||||
BLT_FATAL("\tcalled from %s:%d", path, line);
|
||||
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__)
|
||||
BLT_FATAL("\tCalled from %s:%d", path, line);
|
||||
#if IS_GNU_BACKTRACE
|
||||
printStacktrace(messages, size, path, line);
|
||||
|
||||
BLT_FREE_STACK_TRACE();
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include <sys/mman.h>
|
||||
|
||||
#else
|
||||
#include <blt/std/assert.h>
|
||||
#endif
|
||||
|
||||
namespace blt
|
||||
|
@ -99,16 +101,23 @@ namespace blt
|
|||
}
|
||||
return buffer;
|
||||
#else
|
||||
(void)page_type;
|
||||
(void)bytes;
|
||||
BLT_ABORT("Platform not supported for huge page allocation!");
|
||||
#endif
|
||||
}
|
||||
|
||||
void mmap_free(void* ptr, blt::size_t bytes)
|
||||
{
|
||||
#ifdef __unix__
|
||||
if (munmap(ptr, bytes))
|
||||
{
|
||||
BLT_ERROR_STREAM << "Failed to deallocate\n";
|
||||
throw bad_alloc_t(handle_mmap_error());
|
||||
}
|
||||
#else
|
||||
(void)ptr;
|
||||
(void)bytes;
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
#include <blt/std/system.h>
|
||||
#include <blt/std/logging.h>
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#if !defined(_MSC_VER) && !defined(WIN32)
|
||||
#include <sys/time.h> /* for struct timeval */
|
||||
#include <sys/resource.h>
|
||||
#else
|
||||
|
|
Loading…
Reference in New Issue