summaryrefslogtreecommitdiffstats
path: root/core/script_debugger_remote.cpp
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2020-02-26 11:28:13 +0100
committerPedro J. Estébanez <pedrojrulez@gmail.com>2020-02-26 20:40:10 +0100
commit18fbdbb456c07a56b358bea2e392765fbcbb3283 (patch)
tree737363d20493afe45e75d932e0c1957dd9a79589 /core/script_debugger_remote.cpp
parent1e57b558f215dd4920768e9567b6f55825877c89 (diff)
downloadredot-engine-18fbdbb456c07a56b358bea2e392765fbcbb3283.tar.gz
Reimplement Mutex with C++'s <mutex>
Main: - It's now implemented thanks to `<mutex>`. No more platform-specific implementations. - `BinaryMutex` (non-recursive) is added, as an alternative for special cases. - Doesn't need allocation/deallocation anymore. It can live in the stack and be part of other classes. - Because of that, it's methods are now `const` and the inner mutex is `mutable` so it can be easily used in `const` contexts. - A no-op implementation is provided if `NO_THREADS` is defined. No more need to add `#ifdef NO_THREADS` just for this. - `MutexLock` now takes a reference. At this point the cases of null `Mutex`es are rare. If you ever need that, just don't use `MutexLock`. - Thread-safe utilities are therefore simpler now. Misc.: - `ScopedMutexLock` is dropped and replaced by `MutexLock`, because they were pretty much the same. - Every case of lock, do-something, unlock is replaced by `MutexLock` (complex cases where it's not straightfoward are kept as as explicit lock and unlock). - `ShaderRD` contained an `std::mutex`, which has been replaced by `Mutex`.
Diffstat (limited to 'core/script_debugger_remote.cpp')
-rw-r--r--core/script_debugger_remote.cpp32
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);
}