diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-02-28 00:26:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-28 00:26:01 +0100 |
commit | b7b39786840a41a057f531ed13b64e26366befac (patch) | |
tree | b78a2e0bc0b3f49e82e148e8edb741930ff0ce55 /core/script_debugger_remote.cpp | |
parent | e66d519286693a03bf59eaba0a5f29c1c9b15d64 (diff) | |
parent | 18fbdbb456c07a56b358bea2e392765fbcbb3283 (diff) |
Merge pull request #36556 from RandomShaper/rework_mutex
Reimplement `Mutex` with C++'s `<mutex>` (plus more)
Diffstat (limited to 'core/script_debugger_remote.cpp')
-rw-r--r-- | core/script_debugger_remote.cpp | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp index fdb6135edd..67375da6e2 100644 --- a/core/script_debugger_remote.cpp +++ b/core/script_debugger_remote.cpp @@ -601,7 +601,8 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue, void ScriptDebuggerRemote::_get_output() { - mutex->lock(); + MutexLock lock(mutex); + if (output_strings.size()) { locking = true; @@ -666,7 +667,6 @@ void ScriptDebuggerRemote::_get_output() { errors.pop_front(); locking = false; } - mutex->unlock(); } void ScriptDebuggerRemote::line_poll() { @@ -914,7 +914,8 @@ void ScriptDebuggerRemote::_send_network_bandwidth_usage() { void ScriptDebuggerRemote::send_message(const String &p_message, const Array &p_args) { - mutex->lock(); + MutexLock lock(mutex); + if (!locking && is_peer_connected()) { if (messages.size() >= max_messages_per_frame) { @@ -926,7 +927,6 @@ void ScriptDebuggerRemote::send_message(const String &p_message, const Array &p_ messages.push_back(msg); } } - mutex->unlock(); } void ScriptDebuggerRemote::send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector<ScriptLanguage::StackInfo> &p_stack_info) { @@ -972,7 +972,7 @@ void ScriptDebuggerRemote::send_error(const String &p_func, const String &p_file err_count++; } - mutex->lock(); + MutexLock lock(mutex); if (!locking && is_peer_connected()) { @@ -990,8 +990,6 @@ void ScriptDebuggerRemote::send_error(const String &p_func, const String &p_file } } } - - mutex->unlock(); } void ScriptDebuggerRemote::_print_handler(void *p_this, const String &p_string, bool p_error) { @@ -1020,19 +1018,21 @@ void ScriptDebuggerRemote::_print_handler(void *p_this, const String &p_string, sdr->char_count += allowed_chars; bool overflowed = sdr->char_count >= sdr->max_cps; - sdr->mutex->lock(); - if (!sdr->locking && sdr->is_peer_connected()) { + { + MutexLock lock(sdr->mutex); - if (overflowed) - s += "[...]"; + if (!sdr->locking && sdr->is_peer_connected()) { - sdr->output_strings.push_back(s); + if (overflowed) + s += "[...]"; - if (overflowed) { - sdr->output_strings.push_back("[output overflow, print less text!]"); + sdr->output_strings.push_back(s); + + if (overflowed) { + sdr->output_strings.push_back("[output overflow, print less text!]"); + } } } - sdr->mutex->unlock(); } void ScriptDebuggerRemote::request_quit() { @@ -1106,7 +1106,6 @@ ScriptDebuggerRemote::ScriptDebuggerRemote() : last_net_bandwidth_time(0), performance(Engine::get_singleton()->get_singleton_object("Performance")), requested_quit(false), - mutex(Mutex::create()), max_messages_per_frame(GLOBAL_GET("network/limits/debugger_stdout/max_messages_per_frame")), n_messages_dropped(0), max_errors_per_second(GLOBAL_GET("network/limits/debugger_stdout/max_errors_per_second")), @@ -1141,5 +1140,4 @@ ScriptDebuggerRemote::~ScriptDebuggerRemote() { remove_print_handler(&phl); remove_error_handler(&eh); - memdelete(mutex); } |