diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2019-10-22 14:32:49 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2019-10-22 14:32:49 +0200 |
commit | df69d473d3ab389e915698b8c2c4bb8d22975976 (patch) | |
tree | 3f624b109e8a91bb99aa649489f9a548ba088ddf /libbuild2/module.cxx | |
parent | 5483f5f54146ef6486db93a9a1c45b967d59c384 (diff) |
Implement loaded_modules state locking
This would be necessary if someone runs two parallel top-level contexts.
Diffstat (limited to 'libbuild2/module.cxx')
-rw-r--r-- | libbuild2/module.cxx | 13 |
1 files changed, 13 insertions, 0 deletions
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 |