Success running on linux
This commit is contained in:
+19
-51
@@ -6,12 +6,9 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#define Assert(x) \
|
||||
if (!(x)) { \
|
||||
__debugbreak(); \
|
||||
}
|
||||
#define InvalidCodepath() Assert(!"invalid codepath")
|
||||
#define ElseInvalidCodepath() else {InvalidCodepath()}
|
||||
#include <signal.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#define OS_MAC 1
|
||||
@@ -62,6 +59,19 @@
|
||||
#define COMPILER_GCC 0
|
||||
#endif
|
||||
|
||||
#if OS_WINDOWS
|
||||
#define DebugBreak() __debugbreak()
|
||||
#elif OS_LINUX
|
||||
#define DebugBreak() raise(SIGTRAP)
|
||||
#endif
|
||||
|
||||
#define Assert(x) \
|
||||
if (!(x)) { \
|
||||
DebugBreak(); \
|
||||
}
|
||||
#define InvalidCodepath() Assert(!"invalid codepath")
|
||||
#define ElseInvalidCodepath() else {InvalidCodepath()}
|
||||
|
||||
#define KiB(x) ((x##ull) * 1024ull)
|
||||
#define MiB(x) (KiB(x) * 1024ull)
|
||||
#define GiB(x) (MiB(x) * 1024ull)
|
||||
@@ -710,48 +720,6 @@ ReverseIter<T> IterateInReverse(Slice<T> *slice) {
|
||||
return {slice->end() - 1, slice};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct CircularArray {
|
||||
Allocator allocator;
|
||||
T *data;
|
||||
int16_t cap;
|
||||
int16_t write;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
CircularArray<T> MakeCircularArray(Allocator allocator, int size) {
|
||||
CircularArray<T> arr = {allocator};
|
||||
arr.data = AllocArray(allocator, T, size);
|
||||
arr.cap = size;
|
||||
return arr;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void Add(CircularArray<T> *arr, T item) {
|
||||
if (arr->cap == 0) {
|
||||
arr->allocator = GetSystemAllocator();
|
||||
arr->cap = 128;
|
||||
arr->data = AllocArray(arr->allocator, T, arr->cap);
|
||||
}
|
||||
int16_t i = arr->write;
|
||||
arr->write = (arr->write + 1) % arr->cap;
|
||||
arr->data[i] = item;
|
||||
}
|
||||
|
||||
static int GetCircularIndex(int cap, int idx) {
|
||||
int result = idx % cap;
|
||||
if (result < 0) result = cap + result;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T Get(CircularArray<T> *arr, int idx, T default_value) {
|
||||
int idx = circ->write - 1 - i;
|
||||
idx = GetCircularIndex(circ->size, idx);
|
||||
int result = circ->data[idx];
|
||||
return result;
|
||||
}
|
||||
|
||||
struct UTF32Result {
|
||||
uint32_t out_str;
|
||||
int64_t advance;
|
||||
@@ -1063,7 +1031,7 @@ inline void Clear(Arena *arena) { SetLen(arena, 0); }
|
||||
|
||||
void *VReserve(size_t size);
|
||||
bool VCommit(void *p, size_t size);
|
||||
bool VRelease(void *p);
|
||||
bool VRelease(void *p, size_t size);
|
||||
bool VDecommit(void *p, size_t size);
|
||||
|
||||
void InitArena(Arena *arena, size_t reserve = GiB(4));
|
||||
@@ -1662,7 +1630,7 @@ Arena *AllocArena(size_t reserve) {
|
||||
|
||||
bool success = VCommit(data, PAGE_SIZE);
|
||||
if (!success) {
|
||||
VRelease(data);
|
||||
VRelease(data, reserve);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1711,7 +1679,7 @@ void *PushSize(Arena *arena, size_t size) {
|
||||
void Release(Arena *arena) {
|
||||
if (arena == NULL || arena->data == NULL) return;
|
||||
bool zero_memory = (uint8_t *)arena != arena->data;
|
||||
VRelease(arena->data);
|
||||
VRelease(arena->data, arena->reserve);
|
||||
if (zero_memory) MemoryZero(arena, sizeof(Arena));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user