Mercurial > octave
changeset 27589:12cfa32dc29e
use QMutexLocker to manage locks in qt_interpreter_events methods
* qt-interpreter-events.cc (qt_interpreter_events::confirm_shutdown,
qt_interpreter_events::gui_preference,
qt_interpreter_events::file_remove): Use QMutexLocker object to
automatically unlock mutex.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 25 Oct 2019 14:50:09 -0400 |
parents | f0e3f3e28a8e |
children | f6b729077ebd |
files | libgui/src/qt-interpreter-events.cc |
diffstat | 1 files changed, 5 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/qt-interpreter-events.cc Sat Oct 26 12:20:29 2019 -0400 +++ b/libgui/src/qt-interpreter-events.cc Fri Oct 25 14:50:09 2019 -0400 @@ -248,18 +248,13 @@ bool qt_interpreter_events::confirm_shutdown (void) { - // Lock the mutex before emitting signal. - lock (); + QMutexLocker autolock (&m_mutex); emit confirm_shutdown_signal (); // Wait for result. wait (); - // The GUI has sent a signal and the thread has been awakened. - - unlock (); - return m_shutdown_confirm_result; } @@ -364,16 +359,14 @@ { QString pref_value; - // Lock the mutex before signaling - lock (); + QMutexLocker autolock (&m_mutex); // Emit the signal for changing or getting a preference emit gui_preference_signal (QString::fromStdString (key), QString::fromStdString (value), &pref_value); - // Wait for the GUI and unlock when resumed + // Wait for response (pref_value). wait (); - unlock (); return pref_value.toStdString (); } @@ -409,16 +402,14 @@ void qt_interpreter_events::file_remove (const std::string& old_name, const std::string& new_name) { - // Lock the mutex before signaling - lock (); + QMutexLocker autolock (&m_mutex); // Emit the signal for the editor for closing the file if it is open emit file_remove_signal (QString::fromStdString (old_name), QString::fromStdString (new_name)); - // Wait for the GUI and unlock when resumed + // Wait for file removal to complete before continuing. wait (); - unlock (); } void qt_interpreter_events::file_renamed (bool load_new)