Skip to content

Commit a257b99

Browse files
committed
fix(aot): make loaded-modules-in-order thread safe
1 parent c8e8fcd commit a257b99

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

compiler+runtime/include/cpp/jank/runtime/context.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ namespace jank::runtime
140140
/* TODO: This needs to be a dynamic var. */
141141
native_unordered_map<jtl::immutable_string, native_vector<jtl::immutable_string>>
142142
module_dependencies;
143-
native_deque<jtl::immutable_string> loaded_modules_in_order;
143+
folly::Synchronized<native_deque<jtl::immutable_string>> loaded_modules_in_order;
144144
jtl::immutable_string binary_cache_dir;
145145
module::loader module_loader;
146146

compiler+runtime/src/cpp/jank/aot/processor.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ extern "C" jank_object_ref jank_call2(jank_object_ref, jank_object_ref, jank_obj
7676
extern "C" jank_object_ref jank_parse_command_line_args(int, char const **);
7777
)");
7878

79-
for(auto const &m : __rt_ctx->loaded_modules_in_order)
79+
/* TODO: Is there a better way to do this then copying? */
80+
auto const ordered_modules{ __rt_ctx->loaded_modules_in_order.copy() };
81+
for(auto const &m : ordered_modules)
8082
{
8183
util::format_to(sb,
8284
R"(extern "C" jank_object_ref {}();)",
@@ -95,7 +97,7 @@ int main(int argc, const char** argv)
9597
9698
)");
9799

98-
for(auto const &m : __rt_ctx->loaded_modules_in_order)
100+
for(auto const &m : ordered_modules)
99101
{
100102
util::format_to(sb, "{}();\n", module::module_to_load_function(m));
101103
}
@@ -167,7 +169,8 @@ int main(int argc, const char** argv)
167169

168170
std::vector<char const *> Args = { strdup(clang_inferred_path.get().c_str()) };
169171

170-
for(auto const &module : __rt_ctx->loaded_modules_in_order)
172+
/* TODO: Can we avoid copying? */
173+
for(auto const &module : __rt_ctx->loaded_modules_in_order.copy())
171174
{
172175
auto const &module_path{
173176
util::format("{}.o", relative_to_cache_dir(module::module_to_path(module)))

compiler+runtime/src/cpp/jank/runtime/module/loader.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,10 @@ namespace jank::runtime::module
654654
}
655655

656656
loader::set_is_loaded(module);
657-
__rt_ctx->loaded_modules_in_order.push_back(module);
657+
{
658+
auto const locked_ordered_modules{ __rt_ctx->loaded_modules_in_order.wlock() };
659+
locked_ordered_modules->push_back(module);
660+
}
658661
return ok();
659662
}
660663

compiler+runtime/test/bash/ahead-of-time/pass-test

100644100755
File mode changed.

0 commit comments

Comments
 (0)