aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-08-01 15:09:43 +0100
committerGinger Bill <bill@gingerbill.org>2017-08-01 15:09:43 +0100
commitba6ecf35cf7480606b3eaa7bae823191e26584d4 (patch)
tree83330f2ecc89f4c2315b6286361184cb8706d757
parent10cc9cf6614c33072f26d0e1901ce2f8e5a2c91c (diff)
Disable threading on *nix for the time being
-rw-r--r--src/common.cpp71
-rw-r--r--src/parser.cpp3
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 <math.h>
+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<gbThread> worker_threads = {};