Showing the changes to src (5 of 5 files). Show all
Unified · Split
| @@ -89,14 +89,16 @@ namespace disvm · 88 unmodified lines | |||
| 89 | // All fields on the output structure will be set. | 89 | // All fields on the output structure will be set. |
| 90 | vm_version_t get_version() const; | 90 | vm_version_t get_version() const; |
| 91 | 91 | ||
| 92 | // Begin execution of the module at the supplied path | 92 | // Begin execution of the module at the supplied path and return the ID of |
| 93 | const runtime::vm_thread_t& exec(const char *path); | 93 | // the executing thread. |
| 94 | uint32_t exec(const char *path); | ||
| 94 | 95 | ||
| 95 | // Begin execution of the supplied module | 96 | // Begin execution of the supplied module and return the ID of the executing thread. |
| 96 | const runtime::vm_thread_t& exec(std::unique_ptr<runtime::vm_module_t> entry_module); | 97 | uint32_t exec(std::unique_ptr<runtime::vm_module_t> entry_module); |
| 97 | 98 | ||
| 98 | // Begin execution of a child thread in the supplied module at the indicated program counter | 99 | // Begin execution of a child thread in the supplied module at the indicated |
| 99 | const runtime::vm_thread_t& fork( | 100 | // program counter and return the ID of the executing thread. |
| 101 | uint32_t fork( | ||
| 100 | const uint32_t parent_tid, | 102 | const uint32_t parent_tid, |
| 101 | runtime::vm_module_ref_t &module_ref, | 103 | runtime::vm_module_ref_t &module_ref, |
| 102 | const runtime::vm_frame_t &initial_frame, | 104 | const runtime::vm_frame_t &initial_frame, |
| @@ -128,7 +130,7 @@ namespace disvm · 25 unmodified lines | |||
| 128 | void unload_tool(std::size_t tool_id); | 130 | void unload_tool(std::size_t tool_id); |
| 129 | 131 | ||
| 130 | private: | 132 | private: |
| 131 | const runtime::vm_thread_t &schedule_thread(std::unique_ptr<runtime::vm_thread_t> thread); | 133 | void schedule_thread(std::unique_ptr<runtime::vm_thread_t> thread); |
| 132 | 134 | ||
| 133 | using loaded_modules_t = std::forward_list<loaded_vm_module_t>; | 135 | using loaded_modules_t = std::forward_list<loaded_vm_module_t>; |
| 134 | mutable std::mutex _modules_lock; | 136 | mutable std::mutex _modules_lock; |
| @@ -865,7 +865,7 @@ namespace disvm · 864 unmodified lines | |||
| 865 | virtual vm_scheduler_control_t &get_controller() const = 0; | 865 | virtual vm_scheduler_control_t &get_controller() const = 0; |
| 866 | 866 | ||
| 867 | // Schedule the supplied thread for execution | 867 | // Schedule the supplied thread for execution |
| 868 | virtual const vm_thread_t& schedule_thread(std::unique_ptr<vm_thread_t> thread) = 0; | 868 | virtual void schedule_thread(std::unique_ptr<vm_thread_t> thread) = 0; |
| 869 | 869 | ||
| 870 | // Set tool dispatch on all threads. | 870 | // Set tool dispatch on all threads. |
| 871 | // This is a blocking function and will not return until all current threads have been updated. | 871 | // This is a blocking function and will not return until all current threads have been updated. |
| @@ -139,7 +139,7 @@ vm_scheduler_control_t &default_scheduler_t::get_controller() const · 138 unmodified lines | |||
| 139 | return const_cast<default_scheduler_t&>(*this); | 139 | return const_cast<default_scheduler_t&>(*this); |
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | const vm_thread_t& default_scheduler_t::schedule_thread(std::unique_ptr<vm_thread_t> thread) | 142 | void default_scheduler_t::schedule_thread(std::unique_ptr<vm_thread_t> thread) |
| 143 | { | 143 | { |
| 144 | assert(thread != nullptr); | 144 | assert(thread != nullptr); |
| 145 | if (thread->get_registers().current_thread_state != vm_thread_state_t::ready) | 145 | if (thread->get_registers().current_thread_state != vm_thread_state_t::ready) |
| @@ -160,18 +160,14 @@ const vm_thread_t& default_scheduler_t::schedule_thread(std::unique_ptr<vm_threa · 14 unmodified lines | |||
| 160 | const auto new_thread_id = thread->get_thread_id(); | 160 | const auto new_thread_id = thread->get_thread_id(); |
| 161 | assert(_all_vm_threads.find(new_thread_id) == _all_vm_threads.cend()); | 161 | assert(_all_vm_threads.find(new_thread_id) == _all_vm_threads.cend()); |
| 162 | 162 | ||
| 163 | auto new_thread = std::make_shared<thread_instance_t>(std::move(thread)); | ||
| 164 | |||
| 165 | // Allocate a new container and set the thread entry | 163 | // Allocate a new container and set the thread entry |
| 166 | _all_vm_threads[new_thread_id] = new_thread; | 164 | _all_vm_threads[new_thread_id] = std::make_shared<thread_instance_t>(std::move(thread)); |
| 167 | 165 | ||
| 168 | _runnable_vm_thread_ids.push_back(new_thread_id); | 166 | _runnable_vm_thread_ids.push_back(new_thread_id); |
| 169 | 167 | ||
| 170 | // Notify the worker a thread has been enqueued. | 168 | // Notify the worker a thread has been enqueued. |
| 171 | lock.unlock(); | 169 | lock.unlock(); |
| 172 | _worker_event.notify_one(); | 170 | _worker_event.notify_one(); |
| 173 | |||
| 174 | return *(new_thread->vm_thread); | ||
| 175 | } | 171 | } |
| 176 | 172 | ||
| 177 | void default_scheduler_t::set_tool_dispatch_on_all_threads(vm_tool_dispatch_t *dispatch) | 173 | void default_scheduler_t::set_tool_dispatch_on_all_threads(vm_tool_dispatch_t *dispatch) |
| @@ -38,7 +38,7 @@ namespace disvm · 37 unmodified lines | |||
| 38 | 38 | ||
| 39 | vm_scheduler_control_t &get_controller() const override; | 39 | vm_scheduler_control_t &get_controller() const override; |
| 40 | 40 | ||
| 41 | const vm_thread_t& schedule_thread(std::unique_ptr<vm_thread_t> thread) override; | 41 | void schedule_thread(std::unique_ptr<vm_thread_t> thread) override; |
| 42 | 42 | ||
| 43 | void set_tool_dispatch_on_all_threads(vm_tool_dispatch_t *dispatch) override; | 43 | void set_tool_dispatch_on_all_threads(vm_tool_dispatch_t *dispatch) override; |
| 44 | 44 | ||
| @@ -226,26 +226,32 @@ namespace · 225 unmodified lines | |||
| 226 | } | 226 | } |
| 227 | } | 227 | } |
| 228 | 228 | ||
| 229 | const vm_thread_t& vm_t::exec(const char *path) | 229 | uint32_t vm_t::exec(const char *path) |
| 230 | { | 230 | { |
| 231 | assert(path != nullptr); | 231 | assert(path != nullptr); |
| 232 | auto entry_module = load_module(path); | 232 | auto entry_module = load_module(path); |
| 233 | 233 | ||
| 234 | auto entry_module_ref = std::make_unique<vm_module_ref_t>(entry_module); | 234 | auto entry_module_ref = std::make_unique<vm_module_ref_t>(entry_module); |
| 235 | auto thread = _create_thread_safe(std::move(entry_module_ref)); | 235 | auto thread = _create_thread_safe(std::move(entry_module_ref)); |
| 236 | return schedule_thread(std::move(thread)); | 236 | |
| 237 | const auto thread_id = thread->get_thread_id(); | ||
| 238 | schedule_thread(std::move(thread)); | ||
| 239 | return thread_id; | ||
| 237 | } | 240 | } |
| 238 | 241 | ||
| 239 | const vm_thread_t& vm_t::exec(std::unique_ptr<vm_module_t> entry_module) | 242 | uint32_t vm_t::exec(std::unique_ptr<vm_module_t> entry_module) |
| 240 | { | 243 | { |
| 241 | assert(entry_module != nullptr); | 244 | assert(entry_module != nullptr); |
| 242 | 245 | ||
| 243 | auto entry_module_ref = std::make_unique<vm_module_ref_t>(std::move(entry_module)); | 246 | auto entry_module_ref = std::make_unique<vm_module_ref_t>(std::move(entry_module)); |
| 244 | auto thread = _create_thread_safe(std::move(entry_module_ref)); | 247 | auto thread = _create_thread_safe(std::move(entry_module_ref)); |
| 245 | return schedule_thread(std::move(thread)); | 248 | |
| 249 | const auto thread_id = thread->get_thread_id(); | ||
| 250 | schedule_thread(std::move(thread)); | ||
| 251 | return thread_id; | ||
| 246 | } | 252 | } |
| 247 | 253 | ||
| 248 | const vm_thread_t& vm_t::fork( | 254 | uint32_t vm_t::fork( |
| 249 | const uint32_t parent_tid, | 255 | const uint32_t parent_tid, |
| 250 | vm_module_ref_t &module_ref, | 256 | vm_module_ref_t &module_ref, |
| 251 | const vm_frame_t &initial_frame, | 257 | const vm_frame_t &initial_frame, |
| @@ -255,7 +261,10 @@ const vm_thread_t& vm_t::fork( · 3 unmodified lines | |||
| 255 | throw vm_user_exception{ "Invalid entry program counter" }; | 261 | throw vm_user_exception{ "Invalid entry program counter" }; |
| 256 | 262 | ||
| 257 | auto thread = std::make_unique<vm_thread_t>(module_ref, parent_tid, initial_frame, initial_pc); | 263 | auto thread = std::make_unique<vm_thread_t>(module_ref, parent_tid, initial_frame, initial_pc); |
| 258 | return schedule_thread(std::move(thread)); | 264 | |
| 265 | const auto thread_id = thread->get_thread_id(); | ||
| 266 | schedule_thread(std::move(thread)); | ||
| 267 | return thread_id; | ||
| 259 | } | 268 | } |
| 260 | 269 | ||
| 261 | namespace | 270 | namespace |
| @@ -445,7 +454,7 @@ void vm_t::unload_tool(std::size_t tool_id) · 183 unmodified lines | |||
| 445 | } | 454 | } |
| 446 | } | 455 | } |
| 447 | 456 | ||
| 448 | const vm_thread_t &vm_t::schedule_thread(std::unique_ptr<vm_thread_t> thread) | 457 | void vm_t::schedule_thread(std::unique_ptr<vm_thread_t> thread) |
| 449 | { | 458 | { |
| 450 | assert(thread != nullptr); | 459 | assert(thread != nullptr); |
| 451 | 460 | ||
| @@ -459,5 +468,5 @@ const vm_thread_t &vm_t::schedule_thread(std::unique_ptr<vm_thread_t> thread) · 7 unmodified lines | |||
| 459 | } | 468 | } |
| 460 | } | 469 | } |
| 461 | 470 | ||
| 462 | return _scheduler->schedule_thread(std::move(thread)); | 471 | _scheduler->schedule_thread(std::move(thread)); |
| 463 | } | 472 | } |