[gnote] Replace Glib sync with std in utils
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Replace Glib sync with std in utils
- Date: Sun, 2 May 2021 18:46:47 +0000 (UTC)
commit 22eaa628e84cc6d7ccdcdaf3ed9ee902ae7da61e
Author: Aurimas Černius <aurisc4 gmail com>
Date: Sun May 2 21:42:58 2021 +0300
Replace Glib sync with std in utils
src/utils.cpp | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
---
diff --git a/src/utils.cpp b/src/utils.cpp
index 09570d60..6553b41c 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -25,6 +25,7 @@
#endif
#include <algorithm>
+#include <condition_variable>
#include <glibmm/i18n.h>
#include <glibmm/stringutils.h>
@@ -250,28 +251,26 @@ namespace gnote {
void main_context_call(const sigc::slot<void> & slot)
{
- Glib::Threads::Mutex mutex;
- Glib::Threads::Cond cond;
+ std::mutex mutex;
+ std::condition_variable cond;
bool executed = false;
std::exception_ptr ex;
- mutex.lock();
+ std::unique_lock<std::mutex> lock(mutex);
main_context_invoke([slot, &cond, &mutex, &executed, &ex]() {
+ std::unique_lock<std::mutex> lock(mutex);
try {
- mutex.lock();
slot();
}
catch(...) {
ex = std::current_exception();
}
executed = true;
- cond.signal();
- mutex.unlock();
+ cond.notify_one();
});
while(!executed) {
- cond.wait(mutex);
+ cond.wait(lock);
}
- mutex.unlock();
if(ex) {
std::rethrow_exception(ex);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]