mirror of
https://github.com/odin-lang/Odin.git
synced 2026-07-21 07:01:09 +00:00
Use mutex striping for add_type_and_value
This commit is contained in:
@@ -1792,7 +1792,22 @@ gb_internal void add_untyped(CheckerContext *c, Ast *expr, AddressingMode mode,
|
||||
check_set_expr_info(c, expr, mode, type, value);
|
||||
}
|
||||
|
||||
gb_internal void add_type_and_value(CheckerContext *ctx, Ast *expr, AddressingMode mode, Type *type, ExactValue const &value, bool use_mutex) {
|
||||
struct TypeAndValueMutexStripes alignas(GB_CACHE_LINE_SIZE) {
|
||||
BlockingMutex mutex;
|
||||
u8 padding[GB_CACHE_LINE_SIZE - gb_size_of(BlockingMutex)];
|
||||
};
|
||||
|
||||
enum { TypeAndValueMutexStripes_COUNT = 128 };
|
||||
gb_global TypeAndValueMutexStripes tav_mutex_stripes[TypeAndValueMutexStripes_COUNT];
|
||||
|
||||
gb_internal BlockingMutex *tav_mutex_for_node(Ast *node) {
|
||||
GB_ASSERT(node != nullptr);
|
||||
uintptr h = cast(uintptr)node;
|
||||
h ^= h >> 6;
|
||||
return &tav_mutex_stripes[h % TypeAndValueMutexStripes_COUNT].mutex;
|
||||
}
|
||||
|
||||
gb_internal void add_type_and_value(CheckerContext *ctx, Ast *expr, AddressingMode mode, Type *type, ExactValue const &value) {
|
||||
if (expr == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -1803,14 +1818,18 @@ gb_internal void add_type_and_value(CheckerContext *ctx, Ast *expr, AddressingMo
|
||||
return;
|
||||
}
|
||||
|
||||
BlockingMutex *mutex = &ctx->info->type_and_value_mutex;
|
||||
if (ctx->decl) {
|
||||
mutex = &ctx->decl->type_and_value_mutex;
|
||||
} else if (ctx->pkg) {
|
||||
mutex = &ctx->pkg->type_and_value_mutex;
|
||||
}
|
||||
BlockingMutex *mutex = tav_mutex_for_node(expr);
|
||||
|
||||
if (use_mutex) mutex_lock(mutex);
|
||||
/* Previous logic:
|
||||
BlockingMutex *mutex = &ctx->info->type_and_value_mutex;
|
||||
if (ctx->decl) {
|
||||
mutex = &ctx->decl->type_and_value_mutex;
|
||||
} else if (ctx->pkg) {
|
||||
mutex = &ctx->pkg->type_and_value_mutex;
|
||||
}
|
||||
*/
|
||||
|
||||
mutex_lock(mutex);
|
||||
Ast *prev_expr = nullptr;
|
||||
while (prev_expr != expr) {
|
||||
prev_expr = expr;
|
||||
@@ -1835,7 +1854,7 @@ gb_internal void add_type_and_value(CheckerContext *ctx, Ast *expr, AddressingMo
|
||||
break;
|
||||
};
|
||||
}
|
||||
if (use_mutex) mutex_unlock(mutex);
|
||||
mutex_unlock(mutex);
|
||||
}
|
||||
|
||||
gb_internal void add_entity_definition(CheckerInfo *i, Ast *identifier, Entity *entity) {
|
||||
|
||||
@@ -631,7 +631,7 @@ gb_internal void scope_lookup_parent (Scope *s, String const &name, Scope **s
|
||||
gb_internal Entity *scope_insert (Scope *s, Entity *entity);
|
||||
|
||||
|
||||
gb_internal void add_type_and_value (CheckerContext *c, Ast *expression, AddressingMode mode, Type *type, ExactValue const &value, bool use_mutex=true);
|
||||
gb_internal void add_type_and_value (CheckerContext *c, Ast *expression, AddressingMode mode, Type *type, ExactValue const &value);
|
||||
gb_internal ExprInfo *check_get_expr_info (CheckerContext *c, Ast *expr);
|
||||
gb_internal void add_untyped (CheckerContext *c, Ast *expression, AddressingMode mode, Type *basic_type, ExactValue const &value);
|
||||
gb_internal void add_entity_use (CheckerContext *c, Ast *identifier, Entity *entity);
|
||||
|
||||
Reference in New Issue
Block a user