From ba6ecf35cf7480606b3eaa7bae823191e26584d4 Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Tue, 1 Aug 2017 15:09:43 +0100 Subject: [PATCH] Disable threading on *nix for the time being --- src/common.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++++- src/parser.cpp | 3 ++- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/common.cpp b/src/common.cpp index ec8d3049b..74fbbb019 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -12,9 +12,78 @@ #include +GB_ALLOCATOR_PROC(heap_allocator_proc); gbAllocator heap_allocator(void) { - return gb_heap_allocator(); + gbAllocator a; + a.proc = heap_allocator_proc; + a.data = NULL; + return a; +} + + +GB_ALLOCATOR_PROC(heap_allocator_proc) { + void *ptr = NULL; + gb_unused(allocator_data); + gb_unused(old_size); +// TODO(bill): Throughly test! + switch (type) { +#if defined(GB_COMPILER_MSVC) + case gbAllocation_Alloc: + ptr = _aligned_malloc(size, alignment); + if (flags & gbAllocatorFlag_ClearToZero) + gb_zero_size(ptr, size); + break; + case gbAllocation_Free: + _aligned_free(old_memory); + break; + case gbAllocation_Resize: + ptr = _aligned_realloc(old_memory, size, alignment); + break; + +#elif defined(GB_SYSTEM_LINUX) + // TODO(bill): *nix version that's decent + case gbAllocation_Alloc: { + ptr = aligned_alloc(alignment, size); + // ptr = malloc(size+alignment); + + if (flags & gbAllocatorFlag_ClearToZero) { + gb_zero_size(ptr, size); + } + } break; + + case gbAllocation_Free: { + free(old_memory); + } break; + + case gbAllocation_Resize: { + // ptr = realloc(old_memory, size); + ptr = gb_default_resize_align(heap_allocator(), old_memory, old_size, size, alignment); + } break; +#else + // TODO(bill): *nix version that's decent + case gbAllocation_Alloc: { + posix_memalign(&ptr, alignment, size); + + if (flags & gbAllocatorFlag_ClearToZero) { + gb_zero_size(ptr, size); + } + } break; + + case gbAllocation_Free: { + free(old_memory); + } break; + + case gbAllocation_Resize: { + ptr = gb_default_resize_align(heap_allocator(), old_memory, old_size, size, alignment); + } break; +#endif + + case gbAllocation_FreeAll: + break; + } + + return ptr; } #include "unicode.cpp" diff --git a/src/parser.cpp b/src/parser.cpp index 470bee3d0..fc4c40079 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -5090,7 +5090,8 @@ ParseFileError parse_files(Parser *p, String init_filename) { p->init_fullpath = init_fullpath; -#if USE_THREADED_PARSER + // IMPORTANT TODO(bill): Figure out why this doesn't work on *nix sometimes +#if USE_THREADED_PARSER && defined(GB_SYSTEM_WINDOWS) isize thread_count = gb_max(build_context.thread_count, 1); if (thread_count > 1) { Array worker_threads = {};