[gnote] Replace Glib sync with std in GVFS sync service
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Replace Glib sync with std in GVFS sync service
- Date: Sun, 2 May 2021 18:46:47 +0000 (UTC)
commit 9edff38364941efb9ca650ca1dbbcafb86f27e87
Author: Aurimas Černius <aurisc4 gmail com>
Date: Sun May 2 21:45:36 2021 +0300
Replace Glib sync with std in GVFS sync service
src/synchronization/gvfssyncservice.cpp | 37 ++++++++++++++++-----------------
1 file changed, 18 insertions(+), 19 deletions(-)
---
diff --git a/src/synchronization/gvfssyncservice.cpp b/src/synchronization/gvfssyncservice.cpp
index 7dad12c2..06e96884 100644
--- a/src/synchronization/gvfssyncservice.cpp
+++ b/src/synchronization/gvfssyncservice.cpp
@@ -18,9 +18,10 @@
*/
+#include <condition_variable>
+
#include <glibmm/i18n.h>
#include <glibmm/miscutils.h>
-#include <glibmm/thread.h>
#include "debug.hpp"
#include "gvfssyncservice.hpp"
@@ -157,24 +158,21 @@ bool GvfsSyncService::mount_async(const Glib::RefPtr<Gio::File> & path, const st
bool GvfsSyncService::mount_sync(const Glib::RefPtr<Gio::File> & path, const
Glib::RefPtr<Gio::MountOperation> & op)
{
bool ret = true, done = false;
- Glib::Mutex mutex;
- Glib::Cond cond;
- mutex.lock();
+ std::mutex mutex;
+ std::condition_variable cond;
+ std::unique_lock<std::mutex> lock(mutex);
if(mount_async(path, [&ret, &mutex, &cond, &done](bool result, const Glib::ustring&) {
- mutex.lock();
+ std::unique_lock<std::mutex> lock(mutex);
ret = result;
done = true;
- cond.signal();
- mutex.unlock();
+ cond.notify_one();
}, op)) {
- mutex.unlock();
return true;
}
while(!done) {
- cond.wait(mutex);
+ cond.wait(lock);
}
- mutex.unlock();
return ret;
}
@@ -203,16 +201,17 @@ void GvfsSyncService::unmount_sync()
return;
}
- Glib::Mutex mutex;
- Glib::Cond cond;
- mutex.lock();
- unmount_async([&mutex, &cond]{
- mutex.lock();
- cond.signal();
- mutex.unlock();
+ std::mutex mutex;
+ std::condition_variable cond;
+ std::unique_lock<std::mutex> lock(mutex);
+ unmount_async([this, &mutex, &cond]{
+ std::unique_lock<std::mutex> lock(mutex);
+ cond.notify_one();
+ m_mount.reset();
});
- cond.wait(mutex);
- mutex.unlock();
+ while(m_mount) {
+ cond.wait(lock);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]