Define which mutexes are blocking and recursive explicitly

This commit is contained in:
gingerBill
2021-07-27 23:14:01 +01:00
parent 4bc3796f9b
commit a5d6fda433
14 changed files with 151 additions and 133 deletions

View File

@@ -518,8 +518,8 @@ String internal_odin_root_dir(void) {
}
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));
mutex_lock(&string_buffer_mutex);
defer (mutex_unlock(&string_buffer_mutex));
tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
defer (gb_temp_arena_memory_end(tmp));
@@ -576,8 +576,8 @@ String internal_odin_root_dir(void) {
}
}
gb_mutex_lock(&string_buffer_mutex);
defer (gb_mutex_unlock(&string_buffer_mutex));
mutex_lock(&string_buffer_mutex);
defer (mutex_unlock(&string_buffer_mutex));
tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
defer (gb_temp_arena_memory_end(tmp));
@@ -653,8 +653,8 @@ String internal_odin_root_dir(void) {
array_resize(&path_buf, 2*path_buf.count + 300);
}
gb_mutex_lock(&string_buffer_mutex);
defer (gb_mutex_unlock(&string_buffer_mutex));
mutex_lock(&string_buffer_mutex);
defer (mutex_unlock(&string_buffer_mutex));
tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
defer (gb_temp_arena_memory_end(tmp));
@@ -683,8 +683,8 @@ String internal_odin_root_dir(void) {
#if defined(GB_SYSTEM_WINDOWS)
String path_to_fullpath(gbAllocator a, String s) {
String result = {};
gb_mutex_lock(&string_buffer_mutex);
defer (gb_mutex_unlock(&string_buffer_mutex));
mutex_lock(&string_buffer_mutex);
defer (mutex_unlock(&string_buffer_mutex));
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
defer (gb_temp_arena_memory_end(tmp));
@@ -711,9 +711,9 @@ String path_to_fullpath(gbAllocator a, String s) {
#elif defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_UNIX)
String path_to_fullpath(gbAllocator a, String s) {
char *p;
gb_mutex_lock(&string_buffer_mutex);
mutex_lock(&string_buffer_mutex);
p = realpath(cast(char *)s.text, 0);
gb_mutex_unlock(&string_buffer_mutex);
mutex_unlock(&string_buffer_mutex);
if(p == nullptr) return String{};
return make_string_c(p);
}

View File

@@ -242,7 +242,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
String original_string = o.value.value_string;
gbMutex *ignore_mutex = nullptr;
BlockingMutex *ignore_mutex = nullptr;
String path = {};
bool ok = determine_path_from_string(ignore_mutex, call, base_dir, original_string, &path);

View File

@@ -1116,7 +1116,7 @@ void check_entity_decl(CheckerContext *ctx, Entity *e, DeclInfo *d, Type *named_
return;
}
if (e->flags & EntityFlag_Lazy) {
gb_mutex_lock(&ctx->info->lazy_mutex);
mutex_lock(&ctx->info->lazy_mutex);
}
String name = e->token.string;
@@ -1173,7 +1173,7 @@ end:;
}
if (e->flags & EntityFlag_Lazy) {
gb_mutex_unlock(&ctx->info->lazy_mutex);
mutex_unlock(&ctx->info->lazy_mutex);
}
}

View File

@@ -240,8 +240,8 @@ bool find_or_generate_polymorphic_procedure(CheckerContext *c, Entity *base_enti
GB_ASSERT(dst == nullptr);
}
gb_mutex_lock(&info->gen_procs_mutex);
defer (gb_mutex_unlock(&info->gen_procs_mutex));
mutex_lock(&info->gen_procs_mutex);
defer (mutex_unlock(&info->gen_procs_mutex));
if (!src->Proc.is_polymorphic || src->Proc.is_poly_specialized) {
return false;

View File

@@ -236,8 +236,8 @@ bool check_custom_align(CheckerContext *ctx, Ast *node, i64 *align_) {
Entity *find_polymorphic_record_entity(CheckerContext *ctx, Type *original_type, isize param_count, Array<Operand> const &ordered_operands, bool *failure) {
gb_mutex_lock(&ctx->info->gen_types_mutex);
defer (gb_mutex_unlock(&ctx->info->gen_types_mutex));
mutex_lock(&ctx->info->gen_types_mutex);
defer (mutex_unlock(&ctx->info->gen_types_mutex));
auto *found_gen_types = map_get(&ctx->info->gen_types, hash_pointer(original_type));
if (found_gen_types != nullptr) {
@@ -318,7 +318,7 @@ void add_polymorphic_record_entity(CheckerContext *ctx, Ast *node, Type *named_t
named_type->Named.type_name = e;
gb_mutex_lock(&ctx->info->gen_types_mutex);
mutex_lock(&ctx->info->gen_types_mutex);
auto *found_gen_types = map_get(&ctx->info->gen_types, hash_pointer(original_type));
if (found_gen_types) {
array_add(found_gen_types, e);
@@ -327,7 +327,7 @@ void add_polymorphic_record_entity(CheckerContext *ctx, Ast *node, Type *named_t
array_add(&array, e);
map_set(&ctx->info->gen_types, hash_pointer(original_type), array);
}
gb_mutex_unlock(&ctx->info->gen_types_mutex);
mutex_unlock(&ctx->info->gen_types_mutex);
}
Type *check_record_polymorphic_params(CheckerContext *ctx, Ast *polymorphic_params,

View File

@@ -860,9 +860,9 @@ void init_checker_info(CheckerInfo *i) {
TIME_SECTION("checker info: mutexes");
gb_mutex_init(&i->gen_procs_mutex);
gb_mutex_init(&i->gen_types_mutex);
gb_mutex_init(&i->lazy_mutex);
mutex_init(&i->gen_procs_mutex);
mutex_init(&i->gen_types_mutex);
mutex_init(&i->lazy_mutex);
mutex_init(&i->type_info_mutex);
mutex_init(&i->deps_mutex);
@@ -895,9 +895,9 @@ void destroy_checker_info(CheckerInfo *i) {
mpmc_destroy(&i->required_global_variable_queue);
mpmc_destroy(&i->required_foreign_imports_through_force_queue);
gb_mutex_destroy(&i->gen_procs_mutex);
gb_mutex_destroy(&i->gen_types_mutex);
gb_mutex_destroy(&i->lazy_mutex);
mutex_destroy(&i->gen_procs_mutex);
mutex_destroy(&i->gen_types_mutex);
mutex_destroy(&i->lazy_mutex);
mutex_destroy(&i->type_info_mutex);
mutex_destroy(&i->deps_mutex);
mutex_destroy(&i->identifier_uses_mutex);

View File

@@ -300,10 +300,10 @@ struct CheckerInfo {
// too much of a problem in practice
BlockingMutex deps_mutex;
gbMutex lazy_mutex; // Mutex required for lazy type checking of specific files
RecursiveMutex lazy_mutex; // Mutex required for lazy type checking of specific files
gbMutex gen_procs_mutex; // Possibly recursive
gbMutex gen_types_mutex; // Possibly recursive
RecursiveMutex gen_procs_mutex;
RecursiveMutex gen_types_mutex;
Map<Array<Entity *> > gen_procs; // Key: Ast * | Identifier -> Entity
Map<Array<Entity *> > gen_types; // Key: Type *

View File

@@ -29,6 +29,64 @@
#include <string.h>
#include <atomic> // Because I wanted the C++11 memory order semantics, of which gb.h does not offer (because it was a C89 library)
#if defined(GB_SYSTEM_WINDOWS)
struct BlockingMutex {
SRWLOCK srwlock;
};
void mutex_init(BlockingMutex *m) {
}
void mutex_destroy(BlockingMutex *m) {
}
void mutex_lock(BlockingMutex *m) {
AcquireSRWLockExclusive(&m->srwlock);
}
bool mutex_try_lock(BlockingMutex *m) {
return !!TryAcquireSRWLockExclusive(&m->srwlock);
}
void mutex_unlock(BlockingMutex *m) {
ReleaseSRWLockExclusive(&m->srwlock);
}
#else
typedef gbMutex BlockingMutex;
void mutex_init(BlockingMutex *m) {
gb_mutex_init(m);
}
void mutex_destroy(BlockingMutex *m) {
gb_mutex_destroy(m);
}
void mutex_lock(BlockingMutex *m) {
gb_mutex_lock(m);
}
bool mutex_try_lock(BlockingMutex *m) {
return !!gb_mutex_try_lock(m);
}
void mutex_unlock(BlockingMutex *m) {
gb_mutex_unlock(m);
}
#endif
struct RecursiveMutex {
gbMutex mutex;
};
void mutex_init(RecursiveMutex *m) {
gb_mutex_init(&m->mutex);
}
void mutex_destroy(RecursiveMutex *m) {
gb_mutex_destroy(&m->mutex);
}
void mutex_lock(RecursiveMutex *m) {
gb_mutex_lock(&m->mutex);
}
bool mutex_try_lock(RecursiveMutex *m) {
return gb_mutex_try_lock(&m->mutex);
}
void mutex_unlock(RecursiveMutex *m) {
gb_mutex_unlock(&m->mutex);
}
gb_inline void zero_size(void *ptr, isize len) {
memset(ptr, 0, len);
}
@@ -1300,41 +1358,3 @@ Slice<DistanceAndTarget> did_you_mean_results(DidYouMeanAnswers *d) {
}
return slice_array(d->distances, 0, count);
}
#if defined(GB_SYSTEM_WINDOWS)
struct BlockingMutex {
SRWLOCK srwlock;
};
void mutex_init(BlockingMutex *m) {
}
void mutex_destroy(BlockingMutex *m) {
}
void mutex_lock(BlockingMutex *m) {
AcquireSRWLockExclusive(&m->srwlock);
}
bool mutex_try_lock(BlockingMutex *m) {
return !!TryAcquireSRWLockExclusive(&m->srwlock);
}
void mutex_unlock(BlockingMutex *m) {
ReleaseSRWLockExclusive(&m->srwlock);
}
#else
typedef gbMutex BlockingMutex;
void mutex_init(BlockingMutex *m) {
gb_mutex_init(m);
}
void mutex_destroy(BlockingMutex *m) {
gb_mutex_destroy(m);
}
void mutex_lock(BlockingMutex *m) {
gb_mutex_lock(m);
}
bool mutex_try_lock(BlockingMutex *m) {
return !!gb_mutex_try_lock(m);
}
void mutex_unlock(BlockingMutex *m) {
gb_mutex_unlock(m);
}
#endif

View File

@@ -4664,9 +4664,9 @@ bool init_parser(Parser *p) {
string_map_init(&p->package_map, heap_allocator());
array_init(&p->packages, heap_allocator());
array_init(&p->package_imports, heap_allocator());
gb_mutex_init(&p->import_mutex);
gb_mutex_init(&p->file_add_mutex);
gb_mutex_init(&p->file_decl_mutex);
mutex_init(&p->import_mutex);
mutex_init(&p->file_add_mutex);
mutex_init(&p->file_decl_mutex);
mpmc_init(&p->file_error_queue, heap_allocator(), 1024);
return true;
}
@@ -4691,9 +4691,9 @@ void destroy_parser(Parser *p) {
array_free(&p->package_imports);
string_set_destroy(&p->imported_files);
string_map_destroy(&p->package_map);
gb_mutex_destroy(&p->import_mutex);
gb_mutex_destroy(&p->file_add_mutex);
gb_mutex_destroy(&p->file_decl_mutex);
mutex_destroy(&p->import_mutex);
mutex_destroy(&p->file_add_mutex);
mutex_destroy(&p->file_decl_mutex);
mpmc_destroy(&p->file_error_queue);
}
@@ -4760,9 +4760,9 @@ WORKER_TASK_PROC(foreign_file_worker_proc) {
// TODO(bill): Actually do something with it
break;
}
gb_mutex_lock(&p->file_add_mutex);
mutex_lock(&p->file_add_mutex);
array_add(&pkg->foreign_files, foreign_file);
gb_mutex_unlock(&p->file_add_mutex);
mutex_unlock(&p->file_add_mutex);
return 0;
}
@@ -4782,8 +4782,8 @@ void parser_add_foreign_file_to_process(Parser *p, AstPackage *pkg, AstForeignFi
AstPackage *try_add_import_path(Parser *p, String const &path, String const &rel_path, TokenPos pos, PackageKind kind = Package_Normal) {
String const FILE_EXT = str_lit(".odin");
gb_mutex_lock(&p->import_mutex);
defer (gb_mutex_unlock(&p->import_mutex));
mutex_lock(&p->import_mutex);
defer (mutex_unlock(&p->import_mutex));
if (string_set_exists(&p->imported_files, path)) {
return nullptr;
@@ -4962,7 +4962,7 @@ bool is_package_name_reserved(String const &name) {
}
bool determine_path_from_string(gbMutex *file_mutex, Ast *node, String base_dir, String original_string, String *path) {
bool determine_path_from_string(BlockingMutex *file_mutex, Ast *node, String base_dir, String original_string, String *path) {
GB_ASSERT(path != nullptr);
// NOTE(bill): if file_mutex == nullptr, this means that the code is used within the semantics stage
@@ -5052,8 +5052,8 @@ bool determine_path_from_string(gbMutex *file_mutex, Ast *node, String base_dir,
return true;
}
if (file_mutex) gb_mutex_lock(file_mutex);
defer (if (file_mutex) gb_mutex_unlock(file_mutex));
if (file_mutex) mutex_lock(file_mutex);
defer (if (file_mutex) mutex_unlock(file_mutex));
if (node->kind == Ast_ForeignImportDecl) {
@@ -5452,8 +5452,8 @@ ParseFileError process_imported_file(Parser *p, ImportedFile const &imported_fil
}
if (parse_file(p, file)) {
gb_mutex_lock(&p->file_add_mutex);
defer (gb_mutex_unlock(&p->file_add_mutex));
mutex_lock(&p->file_add_mutex);
defer (mutex_unlock(&p->file_add_mutex));
array_add(&file->pkg->files, file);

View File

@@ -192,9 +192,9 @@ struct Parser {
isize file_to_process_count;
isize total_token_count;
isize total_line_count;
gbMutex import_mutex;
gbMutex file_add_mutex;
gbMutex file_decl_mutex;
BlockingMutex import_mutex;
BlockingMutex file_add_mutex;
BlockingMutex file_decl_mutex;
MPMCQueue<ParseFileError> file_error_queue;
};

View File

@@ -18,7 +18,7 @@ struct MPMCQueue {
CacheLinePad pad0;
isize mask;
Array<MPMCQueueNode<T>> buffer;
gbMutex mutex;
BlockingMutex mutex;
std::atomic<isize> count;
CacheLinePad pad1;
@@ -37,7 +37,7 @@ void mpmc_init(MPMCQueue<T> *q, gbAllocator a, isize size) {
size = next_pow2_isize(size);
GB_ASSERT(gb_is_power_of_two(size));
gb_mutex_init(&q->mutex);
mutex_init(&q->mutex);
q->mask = size-1;
array_init(&q->buffer, a, size);
@@ -57,7 +57,7 @@ void mpmc_init(MPMCQueue<T> *q, gbAllocator a, isize size) {
template <typename T>
void mpmc_destroy(MPMCQueue<T> *q) {
gb_mutex_destroy(&q->mutex);
mutex_destroy(&q->mutex);
gb_free(q->buffer.allocator, q->buffer.data);
}
@@ -83,13 +83,13 @@ isize mpmc_enqueue(MPMCQueue<T> *q, T const &data) {
return q->count.fetch_add(1, std::memory_order_release);
}
} else if (diff < 0) {
gb_mutex_lock(&q->mutex);
mutex_lock(&q->mutex);
isize old_size = q->buffer.count;
isize new_size = old_size*2;
array_resize(&q->buffer, new_size);
if (q->buffer.data == nullptr) {
GB_PANIC("Unable to resize enqueue: %td -> %td", old_size, new_size);
gb_mutex_unlock(&q->mutex);
mutex_unlock(&q->mutex);
return -1;
}
// NOTE(bill): pretend it's not atomic for performance
@@ -98,7 +98,7 @@ isize mpmc_enqueue(MPMCQueue<T> *q, T const &data) {
raw_data[i].idx = i;
}
q->mask = new_size-1;
gb_mutex_unlock(&q->mutex);
mutex_unlock(&q->mutex);
} else {
head_idx = q->head_idx.load(std::memory_order_relaxed);
}

View File

@@ -1,12 +1,12 @@
gb_global gbArena string_buffer_arena = {};
gb_global gbAllocator string_buffer_allocator = {};
gb_global gbMutex string_buffer_mutex = {};
gb_global gbArena string_buffer_arena = {};
gb_global gbAllocator string_buffer_allocator = {};
gb_global BlockingMutex string_buffer_mutex = {};
void init_string_buffer_memory(void) {
// NOTE(bill): This should be enough memory for file systems
gb_arena_init_from_allocator(&string_buffer_arena, heap_allocator(), gb_megabytes(1));
string_buffer_allocator = gb_arena_allocator(&string_buffer_arena);
gb_mutex_init(&string_buffer_mutex);
mutex_init(&string_buffer_mutex);
}

View File

@@ -264,8 +264,9 @@ struct ErrorCollector {
i64 count;
i64 warning_count;
bool in_block;
gbMutex mutex;
gbMutex string_mutex;
BlockingMutex mutex;
BlockingMutex error_out_mutex;
BlockingMutex string_mutex;
Array<u8> error_buffer;
Array<String> errors;
@@ -281,8 +282,9 @@ bool any_errors(void) {
}
void init_global_error_collector(void) {
gb_mutex_init(&global_error_collector.mutex);
gb_mutex_init(&global_error_collector.string_mutex);
mutex_init(&global_error_collector.mutex);
mutex_init(&global_error_collector.error_out_mutex);
mutex_init(&global_error_collector.string_mutex);
array_init(&global_error_collector.errors, heap_allocator());
array_init(&global_error_collector.error_buffer, heap_allocator());
array_init(&global_file_path_strings, heap_allocator(), 4096);
@@ -293,7 +295,7 @@ void init_global_error_collector(void) {
bool set_file_path_string(i32 index, String const &path) {
bool ok = false;
GB_ASSERT(index >= 0);
gb_mutex_lock(&global_error_collector.string_mutex);
mutex_lock(&global_error_collector.string_mutex);
if (index >= global_file_path_strings.count) {
array_resize(&global_file_path_strings, index);
@@ -304,14 +306,14 @@ bool set_file_path_string(i32 index, String const &path) {
ok = true;
}
gb_mutex_unlock(&global_error_collector.string_mutex);
mutex_unlock(&global_error_collector.string_mutex);
return ok;
}
bool set_ast_file_from_id(i32 index, AstFile *file) {
bool ok = false;
GB_ASSERT(index >= 0);
gb_mutex_lock(&global_error_collector.string_mutex);
mutex_lock(&global_error_collector.string_mutex);
if (index >= global_files.count) {
array_resize(&global_files, index);
@@ -322,39 +324,40 @@ bool set_ast_file_from_id(i32 index, AstFile *file) {
ok = true;
}
gb_mutex_unlock(&global_error_collector.string_mutex);
mutex_unlock(&global_error_collector.string_mutex);
return ok;
}
String get_file_path_string(i32 index) {
GB_ASSERT(index >= 0);
gb_mutex_lock(&global_error_collector.string_mutex);
mutex_lock(&global_error_collector.string_mutex);
String path = {};
if (index < global_file_path_strings.count) {
path = global_file_path_strings[index];
}
gb_mutex_unlock(&global_error_collector.string_mutex);
mutex_unlock(&global_error_collector.string_mutex);
return path;
}
AstFile *get_ast_file_from_id(i32 index) {
GB_ASSERT(index >= 0);
gb_mutex_lock(&global_error_collector.string_mutex);
mutex_lock(&global_error_collector.string_mutex);
AstFile *file = nullptr;
if (index < global_files.count) {
file = global_files[index];
}
gb_mutex_unlock(&global_error_collector.string_mutex);
mutex_unlock(&global_error_collector.string_mutex);
return file;
}
void begin_error_block(void) {
gb_mutex_lock(&global_error_collector.mutex);
mutex_lock(&global_error_collector.mutex);
global_error_collector.in_block = true;
}
@@ -367,13 +370,10 @@ void end_error_block(void) {
String s = {text, n};
array_add(&global_error_collector.errors, s);
global_error_collector.error_buffer.count = 0;
// gbFile *f = gb_file_get_standard(gbFileStandard_Error);
// gb_file_write(f, text, n);
}
global_error_collector.in_block = false;
gb_mutex_unlock(&global_error_collector.mutex);
mutex_unlock(&global_error_collector.mutex);
}
@@ -393,14 +393,14 @@ ERROR_OUT_PROC(default_error_out_va) {
gb_memmove(data, buf, n);
global_error_collector.error_buffer.count += n;
} else {
gb_mutex_lock(&global_error_collector.mutex);
mutex_lock(&global_error_collector.error_out_mutex);
{
u8 *text = gb_alloc_array(heap_allocator(), u8, n+1);
gb_memmove(text, buf, n);
text[n] = 0;
array_add(&global_error_collector.errors, make_string(text, n));
}
gb_mutex_unlock(&global_error_collector.mutex);
mutex_unlock(&global_error_collector.error_out_mutex);
}
gb_file_write(f, buf, n);
@@ -491,7 +491,7 @@ bool show_error_on_line(TokenPos const &pos, TokenPos end) {
}
void error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) {
gb_mutex_lock(&global_error_collector.mutex);
mutex_lock(&global_error_collector.mutex);
global_error_collector.count++;
// NOTE(bill): Duplicate error, skip it
if (pos.line == 0) {
@@ -503,7 +503,7 @@ void error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) {
gb_bprintf_va(fmt, va));
show_error_on_line(pos, end);
}
gb_mutex_unlock(&global_error_collector.mutex);
mutex_unlock(&global_error_collector.mutex);
if (global_error_collector.count > MAX_ERROR_COLLECTOR_COUNT) {
gb_exit(1);
}
@@ -514,7 +514,7 @@ void warning_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va)
error_va(pos, end, fmt, va);
return;
}
gb_mutex_lock(&global_error_collector.mutex);
mutex_lock(&global_error_collector.mutex);
global_error_collector.warning_count++;
if (!global_ignore_warnings()) {
// NOTE(bill): Duplicate error, skip it
@@ -528,18 +528,16 @@ void warning_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va)
show_error_on_line(pos, end);
}
}
gb_mutex_unlock(&global_error_collector.mutex);
mutex_unlock(&global_error_collector.mutex);
}
void error_line_va(char const *fmt, va_list va) {
gb_mutex_lock(&global_error_collector.mutex);
error_out_va(fmt, va);
gb_mutex_unlock(&global_error_collector.mutex);
}
void error_no_newline_va(TokenPos const &pos, char const *fmt, va_list va) {
gb_mutex_lock(&global_error_collector.mutex);
mutex_lock(&global_error_collector.mutex);
global_error_collector.count++;
// NOTE(bill): Duplicate error, skip it
if (pos.line == 0) {
@@ -550,7 +548,7 @@ void error_no_newline_va(TokenPos const &pos, char const *fmt, va_list va) {
token_pos_to_string(pos),
gb_bprintf_va(fmt, va));
}
gb_mutex_unlock(&global_error_collector.mutex);
mutex_unlock(&global_error_collector.mutex);
if (global_error_collector.count > MAX_ERROR_COLLECTOR_COUNT) {
gb_exit(1);
}
@@ -558,7 +556,7 @@ void error_no_newline_va(TokenPos const &pos, char const *fmt, va_list va) {
void syntax_error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) {
gb_mutex_lock(&global_error_collector.mutex);
mutex_lock(&global_error_collector.mutex);
global_error_collector.count++;
// NOTE(bill): Duplicate error, skip it
if (global_error_collector.prev != pos) {
@@ -571,7 +569,7 @@ void syntax_error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list
error_out("Syntax Error: %s\n", gb_bprintf_va(fmt, va));
}
gb_mutex_unlock(&global_error_collector.mutex);
mutex_unlock(&global_error_collector.mutex);
if (global_error_collector.count > MAX_ERROR_COLLECTOR_COUNT) {
gb_exit(1);
}
@@ -582,7 +580,7 @@ void syntax_warning_va(TokenPos const &pos, TokenPos end, char const *fmt, va_li
syntax_error_va(pos, end, fmt, va);
return;
}
gb_mutex_lock(&global_error_collector.mutex);
mutex_lock(&global_error_collector.mutex);
global_error_collector.warning_count++;
if (!global_ignore_warnings()) {
// NOTE(bill): Duplicate error, skip it
@@ -596,7 +594,7 @@ void syntax_warning_va(TokenPos const &pos, TokenPos end, char const *fmt, va_li
error_out("Warning: %s\n", gb_bprintf_va(fmt, va));
}
}
gb_mutex_unlock(&global_error_collector.mutex);
mutex_unlock(&global_error_collector.mutex);
}

View File

@@ -661,7 +661,7 @@ gb_global Type *t_map_header = nullptr;
gb_global Type *t_equal_proc = nullptr;
gb_global Type *t_hasher_proc = nullptr;
gb_global gbMutex g_type_mutex;
gb_global RecursiveMutex g_type_mutex;
i64 type_size_of (Type *t);
@@ -677,7 +677,7 @@ bool is_type_slice(Type *t);
bool is_type_integer(Type *t);
void init_type_mutex(void) {
gb_mutex_init(&g_type_mutex);
mutex_init(&g_type_mutex);
}
bool type_ptr_set_exists(PtrSet<Type *> *s, Type *t) {
@@ -2850,8 +2850,8 @@ i64 type_align_of_internal(Type *t, TypePath *path) {
if (t->failure) {
return FAILURE_ALIGNMENT;
}
gb_mutex_lock(&g_type_mutex);
defer (gb_mutex_unlock(&g_type_mutex));
mutex_lock(&g_type_mutex);
defer (mutex_unlock(&g_type_mutex));
t = base_type(t);
@@ -3046,8 +3046,8 @@ Array<i64> type_set_offsets_of(Array<Entity *> const &fields, bool is_packed, bo
}
bool type_set_offsets(Type *t) {
gb_mutex_lock(&g_type_mutex);
defer (gb_mutex_unlock(&g_type_mutex));
mutex_lock(&g_type_mutex);
defer (mutex_unlock(&g_type_mutex));
t = base_type(t);
if (t->kind == Type_Struct) {
@@ -3077,8 +3077,8 @@ i64 type_size_of_internal(Type *t, TypePath *path) {
if (t->failure) {
return FAILURE_SIZE;
}
gb_mutex_lock(&g_type_mutex);
defer (gb_mutex_unlock(&g_type_mutex));
mutex_lock(&g_type_mutex);
defer (mutex_unlock(&g_type_mutex));
switch (t->kind) {