mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 06:38:47 +00:00
Add mutexes to string buffer allocator uses
This commit is contained in:
+24
-16
@@ -69,8 +69,11 @@ String odin_root_dir(void) {
|
|||||||
}
|
}
|
||||||
len += 1; // NOTE(bill): It needs an extra 1 for some reason
|
len += 1; // NOTE(bill): It needs an extra 1 for some reason
|
||||||
|
|
||||||
|
gb_mutex_lock(&string_buffer_mutex);
|
||||||
|
defer (gb_mutex_unlock(&string_buffer_mutex));
|
||||||
|
|
||||||
tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
|
tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
|
||||||
|
defer (gb_temp_arena_memory_end(tmp));
|
||||||
|
|
||||||
text = gb_alloc_array(string_buffer_allocator, wchar_t, len+1);
|
text = gb_alloc_array(string_buffer_allocator, wchar_t, len+1);
|
||||||
|
|
||||||
@@ -88,7 +91,6 @@ String odin_root_dir(void) {
|
|||||||
global_module_path = path;
|
global_module_path = path;
|
||||||
global_module_path_set = true;
|
global_module_path_set = true;
|
||||||
|
|
||||||
gb_temp_arena_memory_end(tmp);
|
|
||||||
|
|
||||||
array_free(&path_buf);
|
array_free(&path_buf);
|
||||||
|
|
||||||
@@ -124,8 +126,12 @@ String odin_root_dir(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gb_mutex_lock(&string_buffer_mutex);
|
||||||
|
defer (gb_mutex_unlock(&string_buffer_mutex));
|
||||||
|
|
||||||
tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
|
tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
|
||||||
|
defer (gb_temp_arena_memory_end(tmp));
|
||||||
|
|
||||||
text = gb_alloc_array(string_buffer_allocator, u8, len + 1);
|
text = gb_alloc_array(string_buffer_allocator, u8, len + 1);
|
||||||
gb_memmove(text, &path_buf[0], len);
|
gb_memmove(text, &path_buf[0], len);
|
||||||
|
|
||||||
@@ -141,7 +147,6 @@ String odin_root_dir(void) {
|
|||||||
global_module_path = path;
|
global_module_path = path;
|
||||||
global_module_path_set = true;
|
global_module_path_set = true;
|
||||||
|
|
||||||
gb_temp_arena_memory_end(tmp);
|
|
||||||
|
|
||||||
// array_free(&path_buf);
|
// array_free(&path_buf);
|
||||||
|
|
||||||
@@ -182,6 +187,8 @@ String odin_root_dir(void) {
|
|||||||
array_resize(&path_buf, 2*path_buf.count + 300);
|
array_resize(&path_buf, 2*path_buf.count + 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gb_mutex_lock(&string_buffer_mutex);
|
||||||
|
defer (gb_mutex_unlock(&string_buffer_mutex));
|
||||||
|
|
||||||
tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
|
tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
|
||||||
defer (gb_temp_arena_memory_end(tmp));
|
defer (gb_temp_arena_memory_end(tmp));
|
||||||
@@ -211,27 +218,28 @@ String odin_root_dir(void) {
|
|||||||
String path_to_fullpath(gbAllocator a, String s) {
|
String path_to_fullpath(gbAllocator a, String s) {
|
||||||
String result = {};
|
String result = {};
|
||||||
gb_mutex_lock(&string_buffer_mutex);
|
gb_mutex_lock(&string_buffer_mutex);
|
||||||
{
|
defer (gb_mutex_unlock(&string_buffer_mutex));
|
||||||
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
|
|
||||||
String16 string16 = string_to_string16(string_buffer_allocator, s);
|
|
||||||
|
|
||||||
DWORD len = GetFullPathNameW(&string16[0], 0, nullptr, nullptr);
|
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
|
||||||
if (len != 0) {
|
String16 string16 = string_to_string16(string_buffer_allocator, s);
|
||||||
wchar_t *text = gb_alloc_array(string_buffer_allocator, wchar_t, len+1);
|
|
||||||
GetFullPathNameW(&string16[0], len, text, nullptr);
|
DWORD len = GetFullPathNameW(&string16[0], 0, nullptr, nullptr);
|
||||||
text[len] = 0;
|
if (len != 0) {
|
||||||
result = string16_to_string(a, make_string16(text, len));
|
wchar_t *text = gb_alloc_array(string_buffer_allocator, wchar_t, len+1);
|
||||||
}
|
GetFullPathNameW(&string16[0], len, text, nullptr);
|
||||||
gb_temp_arena_memory_end(tmp);
|
text[len] = 0;
|
||||||
|
result = string16_to_string(a, make_string16(text, len));
|
||||||
}
|
}
|
||||||
gb_mutex_unlock(&string_buffer_mutex);
|
gb_temp_arena_memory_end(tmp);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#elif defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_UNIX)
|
#elif defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_UNIX)
|
||||||
String path_to_fullpath(gbAllocator a, String s) {
|
String path_to_fullpath(gbAllocator a, String s) {
|
||||||
char *p = realpath(cast(char *)&s[0], 0);
|
char *p;
|
||||||
|
gb_mutex_lock(&string_buffer_mutex);
|
||||||
|
p = realpath(cast(char *)s.data, 0);
|
||||||
|
gb_mutex_unlock(&string_buffer_mutex);
|
||||||
if(p == nullptr) return make_string_c("");
|
if(p == nullptr) return make_string_c("");
|
||||||
|
|
||||||
return make_string_c(p);
|
return make_string_c(p);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|||||||
+11
-13
@@ -79,8 +79,6 @@ struct Parser {
|
|||||||
String init_fullpath;
|
String init_fullpath;
|
||||||
Array<AstFile> files;
|
Array<AstFile> files;
|
||||||
Array<ImportedFile> imports;
|
Array<ImportedFile> imports;
|
||||||
isize curr_import_index;
|
|
||||||
gbAtomic32 import_index;
|
|
||||||
isize total_token_count;
|
isize total_token_count;
|
||||||
isize total_line_count;
|
isize total_line_count;
|
||||||
gbMutex file_add_mutex;
|
gbMutex file_add_mutex;
|
||||||
@@ -4921,7 +4919,7 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Array<AstNod
|
|||||||
String collection_name = {};
|
String collection_name = {};
|
||||||
String oirignal_string = id->relpath.string;
|
String oirignal_string = id->relpath.string;
|
||||||
String file_str = id->relpath.string;
|
String file_str = id->relpath.string;
|
||||||
gbAllocator allocator = heap_allocator(); // TODO(bill): Change this allocator
|
gbAllocator a = heap_allocator(); // TODO(bill): Change this allocator
|
||||||
String import_file = {};
|
String import_file = {};
|
||||||
String rel_path = {};
|
String rel_path = {};
|
||||||
|
|
||||||
@@ -4936,15 +4934,13 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Array<AstNod
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
gb_mutex_lock(&p->file_decl_mutex);
|
gb_mutex_lock(&p->file_decl_mutex);
|
||||||
defer (gb_mutex_unlock(&p->file_decl_mutex));
|
defer (gb_mutex_unlock(&p->file_decl_mutex));
|
||||||
|
|
||||||
rel_path = get_fullpath_relative(allocator, base_dir, file_str);
|
rel_path = get_fullpath_relative(a, base_dir, file_str);
|
||||||
import_file = rel_path;
|
import_file = rel_path;
|
||||||
if (!gb_file_exists(cast(char *)rel_path.text)) { // NOTE(bill): This should be null terminated
|
if (!gb_file_exists(cast(char *)rel_path.text)) { // NOTE(bill): This should be null terminated
|
||||||
String abs_path = get_fullpath_core(allocator, file_str);
|
String abs_path = get_fullpath_core(a, file_str);
|
||||||
if (gb_file_exists(cast(char *)abs_path.text)) {
|
if (gb_file_exists(cast(char *)abs_path.text)) {
|
||||||
import_file = abs_path;
|
import_file = abs_path;
|
||||||
}
|
}
|
||||||
@@ -5105,6 +5101,7 @@ ParseFileError parse_files(Parser *p, String init_filename) {
|
|||||||
gbThread *t = &worker_threads[i];
|
gbThread *t = &worker_threads[i];
|
||||||
gb_thread_init(t);
|
gb_thread_init(t);
|
||||||
}
|
}
|
||||||
|
isize curr_import_index = 0;
|
||||||
|
|
||||||
// NOTE(bill): Make sure that these are in parsed in this order
|
// NOTE(bill): Make sure that these are in parsed in this order
|
||||||
for (isize i = 0; i < shared_file_count; i++) {
|
for (isize i = 0; i < shared_file_count; i++) {
|
||||||
@@ -5112,7 +5109,7 @@ ParseFileError parse_files(Parser *p, String init_filename) {
|
|||||||
if (err != ParseFile_None) {
|
if (err != ParseFile_None) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
p->curr_import_index++;
|
curr_import_index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@@ -5121,19 +5118,20 @@ ParseFileError parse_files(Parser *p, String init_filename) {
|
|||||||
gbThread *t = &worker_threads[i];
|
gbThread *t = &worker_threads[i];
|
||||||
if (gb_thread_is_running(t)) {
|
if (gb_thread_is_running(t)) {
|
||||||
are_any_alive = true;
|
are_any_alive = true;
|
||||||
} else if (p->curr_import_index < p->imports.count) {
|
} else if (curr_import_index < p->imports.count) {
|
||||||
if (t->return_value != 0) {
|
auto err = cast(ParseFileError)t->return_value;
|
||||||
|
if (err != ParseFile_None) {
|
||||||
for_array(i, worker_threads) {
|
for_array(i, worker_threads) {
|
||||||
gb_thread_destroy(&worker_threads[i]);
|
gb_thread_destroy(&worker_threads[i]);
|
||||||
}
|
}
|
||||||
return cast(ParseFileError)t->return_value;
|
return err;
|
||||||
}
|
}
|
||||||
t->user_index = p->curr_import_index++;
|
t->user_index = curr_import_index++;
|
||||||
gb_thread_start(t, parse_worker_file_proc, p);
|
gb_thread_start(t, parse_worker_file_proc, p);
|
||||||
are_any_alive = true;
|
are_any_alive = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!are_any_alive && p->curr_import_index >= p->imports.count) {
|
if (!are_any_alive && curr_import_index >= p->imports.count) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user