diff --git a/CMakeLists.txt b/CMakeLists.txt index 19e208c..6cae0cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,12 +7,15 @@ project(mimir) set(PUBLIC_HEADERS include/mimir.h + include/arena.h include/block.h include/util.h ) set(SRCS + src/arena.cpp src/block.cpp + src/mimir.cpp src/util.cpp ) diff --git a/include/block.h b/include/block.h index 9ab4bc4..0865b6e 100644 --- a/include/block.h +++ b/include/block.h @@ -39,7 +39,6 @@ #endif namespace mimir { -void init(); class Block { public: @@ -127,6 +126,7 @@ private: // Assert if not locked void assertLocked(); -}; +}; // class Block + } // namespace mimir diff --git a/include/mimir.h b/include/mimir.h index c92330b..c924040 100644 --- a/include/mimir.h +++ b/include/mimir.h @@ -32,4 +32,9 @@ #pragma once #include "block.h" +#include "arena.h" #include "util.h" + +namespace mimir { +void init(); +} \ No newline at end of file diff --git a/include/util.h b/include/util.h index 44fd513..6cae46e 100644 --- a/include/util.h +++ b/include/util.h @@ -40,5 +40,5 @@ std::string GetFileExtension(const std::string& name); std::string GetFileBase(const std::string& name); std::string GetFilePath(const std::string& name); -} // namespace mimir } // namespace util +} // namespace mimir diff --git a/src/block.cpp b/src/block.cpp index f9a9ea0..b64128d 100644 --- a/src/block.cpp +++ b/src/block.cpp @@ -30,6 +30,7 @@ // #include "../include/mimir.h" +#include "mimir_impl.h" #if defined(__unix__) || defined(__APPLE__) || defined(ANDROID) #include @@ -43,8 +44,6 @@ #include #define KRENGINE_MIN_MMAP 32768 -#define KRAKEN_MEM_ROUND_DOWN_PAGE(x) ((x) & ~(KRENGINE_SYS_ALLOCATION_GRANULARITY - 1)) -#define KRAKEN_MEM_ROUND_UP_PAGE(x) ((((x) - 1) & ~(KRENGINE_SYS_ALLOCATION_GRANULARITY - 1)) + KRENGINE_SYS_ALLOCATION_GRANULARITY) namespace mimir { @@ -52,28 +51,6 @@ int m_mapCount = 0; size_t m_mapSize = 0; size_t m_mapOverhead = 0; -int KRENGINE_SYS_ALLOCATION_GRANULARITY; -int KRENGINE_SYS_PAGE_SIZE; - -void init() -{ -#if defined(_WIN32) || defined(_WIN64) - - SYSTEM_INFO winSysInfo; - GetSystemInfo(&winSysInfo); - KRENGINE_SYS_ALLOCATION_GRANULARITY = winSysInfo.dwAllocationGranularity; - KRENGINE_SYS_PAGE_SIZE = winSysInfo.dwPageSize; - -#elif defined(__APPLE__) || __linux__ || defined(ANDROID) - - KRENGINE_SYS_PAGE_SIZE = getpagesize(); - KRENGINE_SYS_ALLOCATION_GRANULARITY = KRENGINE_SYS_PAGE_SIZE; - -#else -#error Unsupported -#endif -} - Block::Block() { m_data = NULL; @@ -467,36 +444,6 @@ std::string Block::getString() return ret; } -#if defined(_WIN32) || defined(_WIN64) -void ReportWindowsLastError(LPCTSTR lpszFunction) -{ - LPVOID lpMsgBuf; - LPVOID lpDisplayBuf; - DWORD dw = GetLastError(); - - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - dw, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&lpMsgBuf, - 0, NULL); - - // Display the error message and exit the process - - lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, - (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR)); - fprintf(stderr, - TEXT("%s failed with error %d: %s\n"), - lpszFunction, dw, (LPCTSTR)lpMsgBuf); - - LocalFree(lpMsgBuf); - LocalFree(lpDisplayBuf); -} -#endif - // Lock the memory, forcing it to be loaded into a contiguous block of address space void Block::lock() {