Showing the changes to src/include (1 of 4 files). Show all
Unified · Split
| @@ -35,6 +35,19 @@ namespace disvm · 34 unmodified lines | |||
| 35 | const char * const label; // Optional | 35 | const char * const label; // Optional |
| 36 | }; | 36 | }; |
| 37 | 37 | ||
| 38 | // Loaded module reference | ||
| 39 | class loaded_vm_module_t final | ||
| 40 | { | ||
| 41 | public: | ||
| 42 | // Origin of module | ||
| 43 | std::unique_ptr<runtime::vm_string_t> origin; | ||
| 44 | |||
| 45 | // Weak reference to a loaded module | ||
| 46 | std::weak_ptr<runtime::vm_module_t> module; | ||
| 47 | }; | ||
| 48 | |||
| 49 | using loaded_vm_module_callback_t = std::function<void(const loaded_vm_module_t&)>; | ||
| 50 | |||
| 38 | // Virtual machine | 51 | // Virtual machine |
| 39 | class vm_t final | 52 | class vm_t final |
| 40 | { | 53 | { |
| @@ -71,9 +84,11 @@ namespace disvm · 30 unmodified lines | |||
| 71 | // Load the module at the supplied path into the virtual machine | 84 | // Load the module at the supplied path into the virtual machine |
| 72 | std::shared_ptr<runtime::vm_module_t> load_module(const char *path); | 85 | std::shared_ptr<runtime::vm_module_t> load_module(const char *path); |
| 73 | 86 | ||
| 74 | // Get a collection of all currently loaded modules. | 87 | // Enumerate all loaded modules - this can include references to modules that |
| 75 | // Note this will only include modules that have been loaded by a call to vm_t::load_module. | 88 | // have been unloaded due to no longer being used. If the module instance is null, the |
| 76 | std::vector<std::shared_ptr<runtime::vm_module_t>> get_loaded_modules() const; | 89 | // module is no longer loaded. |
| 90 | // Note this will only enumerate modules that have been loaded by a call to vm_t::load_module. | ||
| 91 | void enum_loaded_modules(loaded_vm_module_callback_t callback) const; | ||
| 77 | 92 | ||
| 78 | // Access the scheduler control for this VM. | 93 | // Access the scheduler control for this VM. |
| 79 | runtime::vm_scheduler_control_t &get_scheduler_control() const; | 94 | runtime::vm_scheduler_control_t &get_scheduler_control() const; |
| @@ -94,25 +109,7 @@ namespace disvm · 14 unmodified lines | |||
| 94 | private: | 109 | private: |
| 95 | const runtime::vm_thread_t &schedule_thread(std::unique_ptr<runtime::vm_thread_t> thread); | 110 | const runtime::vm_thread_t &schedule_thread(std::unique_ptr<runtime::vm_thread_t> thread); |
| 96 | 111 | ||
| 97 | // Loaded module reference | 112 | using loaded_modules_t = std::forward_list<loaded_vm_module_t>; |
| 98 | class loaded_module_t final | ||
| 99 | { | ||
| 100 | public: | ||
| 101 | loaded_module_t(std::unique_ptr<runtime::vm_string_t> origin, std::shared_ptr<runtime::vm_module_t> module); | ||
| 102 | loaded_module_t(const loaded_module_t &) = delete; | ||
| 103 | loaded_module_t &operator=(const loaded_module_t &) = delete; | ||
| 104 | |||
| 105 | loaded_module_t(loaded_module_t &&); | ||
| 106 | ~loaded_module_t(); | ||
| 107 | |||
| 108 | // Origin of module | ||
| 109 | std::unique_ptr<runtime::vm_string_t> origin; | ||
| 110 | |||
| 111 | // Weak reference to a loaded module | ||
| 112 | std::weak_ptr<runtime::vm_module_t> module; | ||
| 113 | }; | ||
| 114 | |||
| 115 | using loaded_modules_t = std::forward_list<loaded_module_t>; | ||
| 116 | mutable std::mutex _modules_lock; | 113 | mutable std::mutex _modules_lock; |
| 117 | loaded_modules_t _modules; | 114 | loaded_modules_t _modules; |
| 118 | 115 | ||