Fix deadlock caused by typo

This commit is contained in:
gingerBill
2021-08-19 11:40:26 +01:00
parent 54af47a138
commit 35026000bb
2 changed files with 14 additions and 17 deletions
+1 -1
View File
@@ -1136,7 +1136,7 @@ void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
if (unhandled.count > 0) { if (unhandled.count > 0) {
begin_error_block(); begin_error_block();
defer (begin_error_block()); defer (end_error_block());
if (unhandled.count == 1) { if (unhandled.count == 1) {
error_no_newline(node, "Unhandled switch case: %.*s", LIT(unhandled[0]->token.string)); error_no_newline(node, "Unhandled switch case: %.*s", LIT(unhandled[0]->token.string));
+13 -16
View File
@@ -262,13 +262,13 @@ bool token_is_newline(Token const &tok) {
struct ErrorCollector { struct ErrorCollector {
TokenPos prev; TokenPos prev;
i64 count; std::atomic<i64> count;
i64 warning_count; std::atomic<i64> warning_count;
bool in_block; std::atomic<bool> in_block;
BlockingMutex mutex; BlockingMutex mutex;
BlockingMutex error_out_mutex; BlockingMutex error_out_mutex;
BlockingMutex string_mutex; BlockingMutex string_mutex;
RecursiveMutex block_mutex; RecursiveMutex block_mutex;
Array<u8> error_buffer; Array<u8> error_buffer;
Array<String> errors; Array<String> errors;
@@ -280,11 +280,7 @@ gb_global ErrorCollector global_error_collector;
bool any_errors(void) { bool any_errors(void) {
bool any_errors = false; return global_error_collector.count.load() != 0;
mutex_lock(&global_error_collector.block_mutex);
any_errors = global_error_collector.error_buffer.count > 0;
mutex_unlock(&global_error_collector.block_mutex);
return any_errors;
} }
void init_global_error_collector(void) { void init_global_error_collector(void) {
@@ -365,7 +361,7 @@ AstFile *get_ast_file_from_id(i32 index) {
void begin_error_block(void) { void begin_error_block(void) {
mutex_lock(&global_error_collector.block_mutex); mutex_lock(&global_error_collector.block_mutex);
global_error_collector.in_block = true; global_error_collector.in_block.store(true);
} }
void end_error_block(void) { void end_error_block(void) {
@@ -379,7 +375,7 @@ void end_error_block(void) {
global_error_collector.error_buffer.count = 0; global_error_collector.error_buffer.count = 0;
} }
global_error_collector.in_block = false; global_error_collector.in_block.store(false);
mutex_unlock(&global_error_collector.block_mutex); mutex_unlock(&global_error_collector.block_mutex);
} }
@@ -498,8 +494,9 @@ bool show_error_on_line(TokenPos const &pos, TokenPos end) {
} }
void error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { void error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) {
global_error_collector.count.fetch_add(1);
mutex_lock(&global_error_collector.mutex); mutex_lock(&global_error_collector.mutex);
global_error_collector.count++;
// NOTE(bill): Duplicate error, skip it // NOTE(bill): Duplicate error, skip it
if (pos.line == 0) { if (pos.line == 0) {
error_out("Error: %s\n", gb_bprintf_va(fmt, va)); error_out("Error: %s\n", gb_bprintf_va(fmt, va));
@@ -521,8 +518,8 @@ void warning_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va)
error_va(pos, end, fmt, va); error_va(pos, end, fmt, va);
return; return;
} }
global_error_collector.warning_count.fetch_add(1);
mutex_lock(&global_error_collector.mutex); mutex_lock(&global_error_collector.mutex);
global_error_collector.warning_count++;
if (!global_ignore_warnings()) { if (!global_ignore_warnings()) {
// NOTE(bill): Duplicate error, skip it // NOTE(bill): Duplicate error, skip it
if (pos.line == 0) { if (pos.line == 0) {