Showing the changes to src/vm/thread.cpp (1 of 10 files). Show all
Unified · Split
| @@ -117,10 +117,9 @@ namespace · 116 unmodified lines | ||
| 117 | 117 | #endif |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | − std::atomic<uint32_t> thread_id_counter(1); | |
| 121 | − | |
| 122 | 120 | uint32_t get_unique_thread_id() |
| 123 | 121 | { |
| 122 | + static std::atomic<uint32_t> thread_id_counter{ 1 }; | |
| 124 | 123 | return thread_id_counter.fetch_add(1); |
| 125 | 124 | } |
| 126 | 125 | } |
| @@ -206,15 +205,17 @@ vm_thread_t::vm_thread_t( · 79 unmodified lines | ||
| 206 | 205 | // Copy over the frame into this thread - pass arguments to the thread |
| 207 | 206 | current_frame->copy_frame_contents(initial_frame); |
| 208 | 207 | |
| 209 | − debug::log_msg(debug::component_trace_t::thread, debug::log_level_t::debug, "init: vm thread: %d %d\n", _thread_id, _parent_thread_id); | |
| 208 | + if (debug::is_component_tracing_enabled<debug::component_trace_t::thread>()) | |
| 209 | + debug::log_msg(debug::component_trace_t::thread, debug::log_level_t::debug, "init: vm thread: %d %d\n", _thread_id, _parent_thread_id); | |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | vm_thread_t::~vm_thread_t() |
| 213 | 213 | { |
| 214 | − debug::log_msg(debug::component_trace_t::thread, debug::log_level_t::debug, "destroy: vm thread: %d %d\n", _thread_id, _parent_thread_id); | |
| 214 | + if (debug::is_component_tracing_enabled<debug::component_trace_t::thread>()) | |
| 215 | + debug::log_msg(debug::component_trace_t::thread, debug::log_level_t::debug, "destroy: vm thread: %d %d\n", _thread_id, _parent_thread_id); | |
| 215 | 216 | } |
| 216 | 217 | |
| 217 | −vm_thread_state_t vm_thread_t::execute(vm_t &virtual_machine, uint32_t quanta) | |
| 218 | +vm_thread_state_t vm_thread_t::execute(vm_t &virtual_machine, const uint32_t quanta) | |
| 218 | 219 | { |
| 219 | 220 | _registers.current_thread_state = vm_thread_state_t::running; |
| 220 | 221 | assert(_registers.pc != runtime_constants::invalid_program_counter); |
| @@ -236,9 +237,13 @@ vm_thread_state_t vm_thread_t::execute(vm_t &virtual_machine, uint32_t quanta) · 15 unmodified lines | ||
| 236 | 237 | assert(static_cast<std::size_t>(_registers.pc) < code_section.size()); |
| 237 | 238 | |
| 238 | 239 | const auto &inst = code_section[_registers.pc].op; |
| 240 | + const auto op_code = static_cast<std::size_t>(inst.opcode); | |
| 241 | + if (static_cast<std::size_t>(opcode_t::last_opcode) < op_code) | |
| 242 | + throw vm_system_exception{ "Unknown op-code" }; | |
| 243 | + | |
| 239 | 244 | decode_address(inst, _registers); |
| 240 | 245 | _registers.pc++; |
| 241 | − vm_exec_table[static_cast<std::size_t>(inst.opcode)](_registers, virtual_machine); | |
| 246 | + vm_exec_table[op_code](_registers, virtual_machine); | |
| 242 | 247 | |
| 243 | 248 | if (_registers.current_thread_state != vm_thread_state_t::running) |
| 244 | 249 | break; |
| @@ -247,13 +252,17 @@ vm_thread_state_t vm_thread_t::execute(vm_t &virtual_machine, uint32_t quanta) · 2 unmodified lines | ||
| 247 | 252 | catch (const unhandled_user_exception &uue) |
| 248 | 253 | { |
| 249 | 254 | // [TODO] Store the exception |
| 250 | − debug::log_msg(debug::component_trace_t::thread, debug::log_level_t::debug, "broken: vm thread: unhandled: >>%s<< %d >>%s<<\n", uue.exception_id, uue.program_counter, uue.module_name); | |
| 255 | + std::printf("%s - %s in %s at %d\n", uue.what(), uue.exception_id, uue.module_name, uue.program_counter); | |
| 256 | + _registers.current_thread_state = vm_thread_state_t::broken; | |
| 257 | + } | |
| 258 | + catch (const index_out_of_range_memory &ioor) | |
| 259 | + { | |
| 260 | + std::printf("%s - %d [%d,%d]\n", ioor.what(), ioor.invalid_value, ioor.valid_min, ioor.valid_max); | |
| 251 | 261 | _registers.current_thread_state = vm_thread_state_t::broken; |
| 252 | 262 | } |
| 253 | 263 | catch (const vm_user_exception &ue) |
| 254 | 264 | { |
| 255 | − // [TODO] Store the exception | |
| 256 | − debug::log_msg(debug::component_trace_t::thread, debug::log_level_t::debug, "broken: vm thread: >>%s<<\n", ue.what()); | |
| 265 | + std::printf("%s\n", ue.what()); | |
| 257 | 266 | _registers.current_thread_state = vm_thread_state_t::broken; |
| 258 | 267 | } |
| 259 | 268 | |