History

Debugger supports breakpoints (set/clear/list) Clean up usage of final and override on various classes Distinguish tool events for vm loading module and thread loading module

arr committed 10 years ago

Commit e2f8e251 parent d8c9a3314 files · +382 −177Browse files

Showing the changes to src/vm/vm.cpp (1 of 14 files). Show all

Unified · Split

src/vm/vm.cpp+44−31
@@ -126,53 +126,63 @@ std::shared_ptr<runtime::vm_module_t> vm_t::load_module(const char *path) · 125 unmodified lines
126126 if (path == nullptr)
127127 throw vm_user_exception{ "Invalid module path" };
128128
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>{};
134131 {
135− if (0 == ::strcmp(iter->origin->str(), path))
136− {
137− auto module = iter->module.lock();
132+ std::lock_guard<std::mutex> lock{ _modules_lock };
138133
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))
141139 {
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;
144147
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;
146152 }
147153
148− return module;
154+ ++iter;
149155 }
150156
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+ }
153166
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();
163175 }
164176
165− auto path_local = std::make_unique<vm_string_t>(std::strlen(path), reinterpret_cast<const uint8_t *>(path));
166177 if (_tool_dispatch != nullptr)
167178 {
168179 std::lock_guard<std::mutex> lock{ _tool_dispatch_lock };
169180 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);
171182 }
172183
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);
176186
177187 return new_module;
178188 }
@@ -184,7 +194,10 @@ void vm_t::enum_loaded_modules(loaded_vm_module_callback_t callback) const · 5 unmodified lines
184194
185195 std::lock_guard<std::mutex> lock{ _modules_lock };
186196 for (auto &m : _modules)
187− callback(m);
197+ {
198+ if (!callback(m))
199+ return;
200+ }
188201 }
189202
190203 runtime::vm_scheduler_control_t &vm_t::get_scheduler_control() const