Showing the changes to src/vm/vm.cpp (1 of 14 files). Show all
Unified · Split
| @@ -126,53 +126,63 @@ std::shared_ptr<runtime::vm_module_t> vm_t::load_module(const char *path) · 125 unmodified lines | ||
| 126 | 126 | if (path == nullptr) |
| 127 | 127 | throw vm_user_exception{ "Invalid module path" }; |
| 128 | 128 | |
| 129 | − std::lock_guard<std::mutex> lock{ _modules_lock }; | |
| 130 | − | |
| 131 | − // Check if the module is already loaded. | |
| 132 | − auto iter = std::begin(_modules); | |
| 133 | − while (iter != std::end(_modules)) | |
| 129 | + auto new_module_iter = loaded_modules_t::const_iterator{}; | |
| 130 | + auto new_module = std::shared_ptr<vm_module_t>{}; | |
| 134 | 131 | { |
| 135 | − if (0 == ::strcmp(iter->origin->str(), path)) | |
| 136 | − { | |
| 137 | − auto module = iter->module.lock(); | |
| 132 | + std::lock_guard<std::mutex> lock{ _modules_lock }; | |
| 138 | 133 | |
| 139 | − // If an entry exists but is null, the module was loaded before. Read the module again and return. | |
| 140 | − if (module == nullptr) | |
| 134 | + // Check if the module is already loaded. | |
| 135 | + auto iter = std::begin(_modules); | |
| 136 | + while (iter != std::end(_modules)) | |
| 137 | + { | |
| 138 | + if (0 == ::strcmp(iter->origin->str(), path)) | |
| 141 | 139 | { |
| 142 | − module = std::shared_ptr<vm_module_t>{ std::move(read_module(path)) }; | |
| 143 | − iter->module = module; | |
| 140 | + auto module = iter->module.lock(); | |
| 141 | + | |
| 142 | + // If an entry exists but is null, the module was loaded before. Read the module again and return. | |
| 143 | + if (module == nullptr) | |
| 144 | + { | |
| 145 | + module = std::shared_ptr<vm_module_t>{ std::move(read_module(path)) }; | |
| 146 | + iter->module = module; | |
| 144 | 147 | |
| 145 | − debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "reload: vm module: >>%s<<\n", path); | |
| 148 | + debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "reload: vm module: >>%s<<\n", path); | |
| 149 | + } | |
| 150 | + | |
| 151 | + return module; | |
| 146 | 152 | } |
| 147 | 153 | |
| 148 | − return module; | |
| 154 | + ++iter; | |
| 149 | 155 | } |
| 150 | 156 | |
| 151 | − ++iter; | |
| 152 | − } | |
| 157 | + if (path[0] == BUILTIN_MODULE_PREFIX_CHAR) | |
| 158 | + { | |
| 159 | + new_module = std::move(builtin::get_builtin_module(path)); | |
| 160 | + } | |
| 161 | + else | |
| 162 | + { | |
| 163 | + // Read in the module | |
| 164 | + new_module = std::move(read_module(path)); | |
| 165 | + } | |
| 153 | 166 | |
| 154 | − auto new_module = std::shared_ptr<vm_module_t>{}; | |
| 155 | − if (path[0] == BUILTIN_MODULE_PREFIX_CHAR) | |
| 156 | − { | |
| 157 | − new_module = std::move(builtin::get_builtin_module(path)); | |
| 158 | − } | |
| 159 | − else | |
| 160 | − { | |
| 161 | − // Read in the module | |
| 162 | − new_module = std::move(read_module(path)); | |
| 167 | + auto path_local = std::make_unique<vm_string_t>(std::strlen(path), reinterpret_cast<const uint8_t *>(path)); | |
| 168 | + | |
| 169 | + auto load_id_next = std::size_t{ 0 }; | |
| 170 | + if (!_modules.empty()) | |
| 171 | + load_id_next = (_modules.front().load_id + 1); | |
| 172 | + | |
| 173 | + _modules.push_front(std::move(loaded_vm_module_t{ load_id_next, std::move(path_local), new_module })); | |
| 174 | + new_module_iter = _modules.begin(); | |
| 163 | 175 | } |
| 164 | 176 | |
| 165 | − auto path_local = std::make_unique<vm_string_t>(std::strlen(path), reinterpret_cast<const uint8_t *>(path)); | |
| 166 | 177 | if (_tool_dispatch != nullptr) |
| 167 | 178 | { |
| 168 | 179 | std::lock_guard<std::mutex> lock{ _tool_dispatch_lock }; |
| 169 | 180 | if (_tool_dispatch != nullptr) |
| 170 | − _tool_dispatch->on_module_load(new_module, *path_local); | |
| 181 | + _tool_dispatch->on_module_vm_load(new_module, *new_module_iter->origin); | |
| 171 | 182 | } |
| 172 | 183 | |
| 173 | − _modules.push_front(std::move(loaded_vm_module_t{ std::move(path_local), new_module })); | |
| 174 | − | |
| 175 | − debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "load: vm module: >>%s<<\n", path); | |
| 184 | + if (debug::is_component_tracing_enabled<debug::component_trace_t::module>()) | |
| 185 | + debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "load: vm module: >>%s<<\n", path); | |
| 176 | 186 | |
| 177 | 187 | return new_module; |
| 178 | 188 | } |
| @@ -184,7 +194,10 @@ void vm_t::enum_loaded_modules(loaded_vm_module_callback_t callback) const · 5 unmodified lines | ||
| 184 | 194 | |
| 185 | 195 | std::lock_guard<std::mutex> lock{ _modules_lock }; |
| 186 | 196 | for (auto &m : _modules) |
| 187 | − callback(m); | |
| 197 | + { | |
| 198 | + if (!callback(m)) | |
| 199 | + return; | |
| 200 | + } | |
| 188 | 201 | } |
| 189 | 202 | |
| 190 | 203 | runtime::vm_scheduler_control_t &vm_t::get_scheduler_control() const |