From df69d473d3ab389e915698b8c2c4bb8d22975976 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 22 Oct 2019 14:32:49 +0200 Subject: Implement loaded_modules state locking This would be necessary if someone runs two parallel top-level contexts. --- libbuild2/module.cxx | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'libbuild2/module.cxx') diff --git a/libbuild2/module.cxx b/libbuild2/module.cxx index c2fbc14..c6c6c3d 100644 --- a/libbuild2/module.cxx +++ b/libbuild2/module.cxx @@ -31,6 +31,8 @@ using namespace butl; namespace build2 { + mutex loaded_modules_lock::mutex_; + loaded_module_map loaded_modules; void @@ -195,6 +197,10 @@ namespace build2 ctx.module_context->current_operation (op_update); } + // Inherit loaded_modules lock from the outer context. + // + ctx.module_context->modules_lock = ctx.modules_lock; + // "Switch" to the module context. // context& ctx (*bs.ctx.module_context); @@ -270,6 +276,8 @@ namespace build2 l5 ([&]{trace << "updated " << lib;}); } + + ctx.modules_lock = nullptr; // For good measure. } else { @@ -364,6 +372,11 @@ namespace build2 { tracer trace ("find_module"); + // Note that we hold the lock for the entire time it takes to build a + // module. + // + loaded_modules_lock lock (bs.ctx); + // Optional modules and submodules sure make this logic convoluted. So we // divide it into two parts: (1) find or insert an entry (for submodule // or, failed that, for the main module, the latter potentially NULL) and -- cgit v1.1