Switch from GMutex to std::mutex. (#3382)

Modified all instances where GMutex is used to use std::mutex instead.
upstream-master
Nikolaos Chatzikonstantinou 5 years ago committed by GitHub
parent 412fc8e188
commit c8d690c2d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      src/control/PdfCache.cpp
  2. 3
      src/control/PdfCache.h
  3. 15
      src/control/jobs/Job.cpp
  4. 6
      src/control/jobs/Job.h
  5. 4
      src/control/jobs/PreviewJob.cpp
  6. 12
      src/control/jobs/RenderJob.cpp
  7. 3
      src/control/jobs/Scheduler.h
  8. 10
      src/control/settings/MetadataManager.cpp
  9. 3
      src/control/settings/MetadataManager.h
  10. 2
      src/gui/Layout.h
  11. 22
      src/gui/PageView.cpp
  12. 7
      src/gui/PageView.h
  13. 6
      src/gui/sidebar/previews/base/SidebarPreviewBaseEntry.cpp
  14. 3
      src/gui/sidebar/previews/base/SidebarPreviewBaseEntry.h
  15. 11
      src/model/Document.cpp
  16. 3
      src/model/Document.h
  17. 13
      src/model/eraser/EraseableStroke.cpp
  18. 3
      src/model/eraser/EraseableStroke.h

@ -34,11 +34,7 @@ public:
cairo_surface_t* rendered;
};
PdfCache::PdfCache(int size) {
this->size = size;
g_mutex_init(&this->renderMutex);
}
PdfCache::PdfCache(int size) { this->size = size; }
PdfCache::~PdfCache() {
clearCache();
@ -81,7 +77,7 @@ PdfCacheEntry* PdfCache::cache(XojPdfPageSPtr popplerPage, cairo_surface_t* img,
}
void PdfCache::render(cairo_t* cr, const XojPdfPageSPtr& popplerPage, double zoom) {
g_mutex_lock(&this->renderMutex);
this->renderMutex.lock();
this->setZoom(zoom);
@ -127,5 +123,5 @@ void PdfCache::render(cairo_t* cr, const XojPdfPageSPtr& popplerPage, double zoo
cairo_paint(cr);
cairo_set_matrix(cr, &mOriginal);
g_mutex_unlock(&this->renderMutex);
this->renderMutex.unlock();
}

@ -12,6 +12,7 @@
#pragma once
#include <list>
#include <mutex>
#include <string>
#include <vector>
@ -58,7 +59,7 @@ private:
PdfCacheEntry* cache(XojPdfPageSPtr popplerPage, cairo_surface_t* img, double zoom);
private:
GMutex renderMutex{};
std::mutex renderMutex;
std::list<PdfCacheEntry*> data;
std::list<PdfCacheEntry*>::size_type size = 0;

@ -1,27 +1,30 @@
#include "Job.h"
#include <mutex>
#include <glib.h>
#include <gtk/gtk.h>
Job::Job() { g_mutex_init(&this->refMutex); }
Job::Job() {}
Job::~Job() = default;
void Job::unref() {
g_mutex_lock(&this->refMutex);
this->refMutex.lock();
this->refCount--;
if (this->refCount == 0) {
g_mutex_unlock(&this->refMutex);
this->refMutex.unlock();
delete this;
} else {
g_mutex_unlock(&this->refMutex);
this->refMutex.unlock();
}
}
void Job::ref() {
g_mutex_lock(&this->refMutex);
this->refMutex.lock();
this->refCount++;
g_mutex_unlock(&this->refMutex);
this->refMutex.unlock();
}
void Job::deleteJob() {

@ -11,12 +11,10 @@
#pragma once
#include <mutex>
#include <string>
#include <vector>
#include <glib.h>
enum JobType { JOB_TYPE_BLOCKING, JOB_TYPE_PREVIEW, JOB_TYPE_RENDER, JOB_TYPE_AUTOSAVE };
class Job {
@ -86,5 +84,5 @@ private:
int afterRunId = 0;
int refCount = 1;
GMutex refMutex{};
std::mutex refMutex;
};

@ -33,7 +33,7 @@ void PreviewJob::drawBorder() {
}
void PreviewJob::finishPaint() {
g_mutex_lock(&this->sidebarPreview->drawingMutex);
this->sidebarPreview->drawingMutex.lock();
if (this->sidebarPreview->crBuffer) {
cairo_surface_destroy(this->sidebarPreview->crBuffer);
@ -50,7 +50,7 @@ void PreviewJob::finishPaint() {
g_object_unref(previewWidget);
});
g_mutex_unlock(&this->sidebarPreview->drawingMutex);
this->sidebarPreview->drawingMutex.unlock();
}
void PreviewJob::drawBackgroundPdf(Document* doc) {

@ -54,7 +54,7 @@ void RenderJob::rerenderRectangle(Rectangle<double> const& rect) {
cairo_destroy(crRect);
g_mutex_lock(&view->drawingMutex);
view->drawingMutex.lock();
cairo_t* crPageBuffer = cairo_create(view->crBuffer);
@ -67,20 +67,20 @@ void RenderJob::rerenderRectangle(Rectangle<double> const& rect) {
cairo_surface_destroy(rectBuffer);
g_mutex_unlock(&view->drawingMutex);
view->drawingMutex.unlock();
}
void RenderJob::run() {
double zoom = this->view->xournal->getZoom();
g_mutex_lock(&this->view->repaintRectMutex);
this->view->repaintRectMutex.lock();
bool rerenderComplete = this->view->rerenderComplete;
auto rerenderRects = std::move(this->view->rerenderRects);
this->view->rerenderComplete = false;
g_mutex_unlock(&this->view->repaintRectMutex);
this->view->repaintRectMutex.unlock();
int dpiScaleFactor = this->view->xournal->getDpiScaleFactor();
@ -121,14 +121,14 @@ void RenderJob::run() {
cairo_destroy(cr2);
g_mutex_lock(&this->view->drawingMutex);
this->view->drawingMutex.lock();
if (this->view->crBuffer) {
cairo_surface_destroy(this->view->crBuffer);
}
this->view->crBuffer = crBuffer;
g_mutex_unlock(&this->view->drawingMutex);
this->view->drawingMutex.unlock();
doc->unlock();
} else {
for (Rectangle<double> const& rect: rerenderRects) {

@ -19,8 +19,9 @@
#include <mutex>
#include <string>
#include "Job.h"
#include <gtk/gtk.h>
#include "Job.h"
/**
* @file Scheduler.h

@ -18,7 +18,7 @@ using namespace std;
MetadataEntry::MetadataEntry(): valid(false), zoom(1), page(0), time(0) {}
MetadataManager::MetadataManager(): metadata(nullptr) { g_mutex_init(&this->mutex); }
MetadataManager::MetadataManager(): metadata(nullptr) {}
MetadataManager::~MetadataManager() { documentChanged(); }
@ -43,10 +43,10 @@ void MetadataManager::deleteMetadataFile(fs::path const& path) {
* Document was closed, a new document was opened etc.
*/
void MetadataManager::documentChanged() {
g_mutex_lock(&this->mutex);
this->mutex.lock();
MetadataEntry* m = metadata;
metadata = nullptr;
g_mutex_unlock(&this->mutex);
this->mutex.unlock();
if (m == nullptr) {
return;
@ -185,7 +185,7 @@ void MetadataManager::storeMetadata(fs::path const& file, int page, double zoom)
return;
}
g_mutex_lock(&this->mutex);
this->mutex.lock();
if (metadata == nullptr) {
metadata = new MetadataEntry();
}
@ -195,5 +195,5 @@ void MetadataManager::storeMetadata(fs::path const& file, int page, double zoom)
metadata->zoom = zoom;
metadata->page = page;
metadata->time = g_get_real_time();
g_mutex_unlock(&this->mutex);
this->mutex.unlock();
}

@ -11,6 +11,7 @@
#pragma once
#include <mutex>
#include <string>
#include <vector>
@ -77,6 +78,6 @@ private:
private:
GMutex mutex{};
std::mutex mutex;
MetadataEntry* metadata;
};

@ -37,7 +37,7 @@ class Layout final {
public:
Layout(XournalView* view, ScrollHandling* scrollHandling);
struct PreCalculated {
std::mutex m{};
std::mutex m;
// The width and height of all our pages
size_t minWidth = 0;

@ -57,10 +57,6 @@ XojPageView::XojPageView(XournalView* xournal, const PageRef& page) {
this->xournal = xournal;
this->settings = xournal->getControl()->getSettings();
g_mutex_init(&this->drawingMutex);
g_mutex_init(&this->repaintRectMutex);
// this does not have to be deleted afterwards:
// (we need it for undo commands)
this->oldtext = nullptr;
@ -100,12 +96,12 @@ auto XojPageView::getLastVisibleTime() -> int {
}
void XojPageView::deleteViewBuffer() {
g_mutex_lock(&this->drawingMutex);
this->drawingMutex.lock();
if (this->crBuffer) {
cairo_surface_destroy(this->crBuffer);
this->crBuffer = nullptr;
}
g_mutex_unlock(&this->drawingMutex);
this->drawingMutex.unlock();
}
auto XojPageView::containsPoint(int x, int y, bool local) const -> bool {
@ -639,7 +635,7 @@ void XojPageView::addRerenderRect(double x, double y, double width, double heigh
auto rect = Rectangle<double>{x, y, width, height};
g_mutex_lock(&this->repaintRectMutex);
this->repaintRectMutex.lock();
for (auto&& r: this->rerenderRects) {
// its faster to redraw only one rect than repaint twice the same area
@ -647,13 +643,13 @@ void XojPageView::addRerenderRect(double x, double y, double width, double heigh
// intersects any of them, replace it by the union with the new one
if (r.intersects(rect)) {
r.unite(rect);
g_mutex_unlock(&this->repaintRectMutex);
this->repaintRectMutex.unlock();
return;
}
}
this->rerenderRects.push_back(rect);
g_mutex_unlock(&this->repaintRectMutex);
this->repaintRectMutex.unlock();
this->xournal->getControl()->getScheduler()->addRerenderPage(this);
}
@ -808,11 +804,11 @@ void XojPageView::paintPageSync(cairo_t* cr, GdkRectangle* rect) {
}
auto XojPageView::paintPage(cairo_t* cr, GdkRectangle* rect) -> bool {
g_mutex_lock(&this->drawingMutex);
this->drawingMutex.lock();
paintPageSync(cr, rect);
g_mutex_unlock(&this->drawingMutex);
this->drawingMutex.unlock();
return true;
}
@ -915,7 +911,7 @@ void XojPageView::pageChanged() { rerenderPage(); }
void XojPageView::elementChanged(Element* elem) {
if (this->inputHandler && elem == this->inputHandler->getStroke()) {
g_mutex_lock(&this->drawingMutex);
this->drawingMutex.lock();
cairo_t* cr = cairo_create(this->crBuffer);
@ -923,7 +919,7 @@ void XojPageView::elementChanged(Element* elem) {
cairo_destroy(cr);
g_mutex_unlock(&this->drawingMutex);
this->drawingMutex.unlock();
} else {
rerenderElement(elem);
}

@ -11,6 +11,9 @@
#pragma once
#include <mutex>
#include <vector>
#include "gui/inputdevices/PositionInputData.h"
#include "model/PageListener.h"
#include "model/PageRef.h"
@ -227,11 +230,11 @@ private:
*/
int lastVisibleTime = -1;
GMutex repaintRectMutex{};
std::mutex repaintRectMutex;
std::vector<Rectangle<double>> rerenderRects;
bool rerenderComplete = false;
GMutex drawingMutex{};
std::mutex drawingMutex;
int dispX{}; // position on display - set in Layout::layoutPages
int dispY{};

@ -13,8 +13,6 @@ SidebarPreviewBaseEntry::SidebarPreviewBaseEntry(SidebarPreviewBase* sidebar, co
gtk_widget_show(this->widget);
g_object_ref(this->widget);
g_mutex_init(&this->drawingMutex);
updateSize();
gtk_widget_set_events(widget, GDK_EXPOSURE_MASK);
@ -90,7 +88,7 @@ void SidebarPreviewBaseEntry::drawLoadingPage() {
void SidebarPreviewBaseEntry::paint(cairo_t* cr) {
bool doRepaint = false;
g_mutex_lock(&this->drawingMutex);
this->drawingMutex.lock();
if (this->crBuffer == nullptr) {
drawLoadingPage();
@ -122,7 +120,7 @@ void SidebarPreviewBaseEntry::paint(cairo_t* cr) {
Shadow::drawShadow(cr, Shadow::getShadowTopLeftSize() + 2, Shadow::getShadowTopLeftSize() + 2, width, height);
}
g_mutex_unlock(&this->drawingMutex);
this->drawingMutex.unlock();
if (doRepaint) {
repaint();

@ -11,6 +11,7 @@
#pragma once
#include <mutex>
#include <string>
#include <vector>
@ -93,7 +94,7 @@ protected:
/**
* Mutex
*/
GMutex drawingMutex{};
std::mutex drawingMutex{};
/**
* The Widget which is used for drawing

@ -15,7 +15,7 @@
#include "filesystem.h"
#include "i18n.h"
Document::Document(DocumentHandler* handler): handler(handler) { g_mutex_init(&this->documentLock); }
Document::Document(DocumentHandler* handler): handler(handler) {}
Document::~Document() {
clearDocument(true);
@ -49,7 +49,7 @@ auto Document::freeTreeContentEntry(GtkTreeModel* treeModel, GtkTreePath* path,
}
void Document::lock() {
g_mutex_lock(&this->documentLock);
this->documentLock.lock();
// if(tryLock()) {
// fprintf(stderr, "Locked by\n");
@ -61,14 +61,17 @@ void Document::lock() {
}
void Document::unlock() {
g_mutex_unlock(&this->documentLock);
this->documentLock.unlock();
// fprintf(stderr, "Unlocked by\n");
// Stacktrace::printStracktrace();
// fprintf(stderr, "\n\n\n\n");
}
auto Document::tryLock() -> bool { return g_mutex_trylock(&this->documentLock); }
/*
** Returns true when successfully acquiring lock.
*/
auto Document::tryLock() -> bool { return this->documentLock.try_lock(); }
void Document::clearDocument(bool destroy) {
if (this->preview) {

@ -14,6 +14,7 @@
#pragma once
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
#include <vector>
@ -154,7 +155,7 @@ private:
/**
* The lock of the document
*/
GMutex documentLock{};
std::mutex documentLock;
};
template <class InputIter>

@ -10,7 +10,6 @@
EraseableStroke::EraseableStroke(Stroke* stroke): stroke(stroke) {
this->parts = new PartList();
g_mutex_init(&this->partLock);
for (int i = 1; i < stroke->getPointCount(); i++) {
this->parts->add(new EraseableStrokePart(stroke->getPoint(i - 1), stroke->getPoint(i)));
@ -27,9 +26,9 @@ EraseableStroke::~EraseableStroke() {
////////////////////////////////////////////////////////////////////////////////
void EraseableStroke::draw(cairo_t* cr) {
g_mutex_lock(&this->partLock);
this->partLock.lock();
PartList* tmpCopy = this->parts->clone();
g_mutex_unlock(&this->partLock);
this->partLock.unlock();
double w = this->stroke->getWidth();
@ -66,9 +65,9 @@ void EraseableStroke::draw(cairo_t* cr) {
auto EraseableStroke::erase(double x, double y, double halfEraserSize, Range* range) -> Range* {
this->repaintRect = range;
g_mutex_lock(&this->partLock);
this->partLock.lock();
PartList* tmpCopy = this->parts->clone();
g_mutex_unlock(&this->partLock);
this->partLock.unlock();
for (GList* l = tmpCopy->data; l != nullptr;) {
auto* p = static_cast<EraseableStrokePart*>(l->data);
@ -76,10 +75,10 @@ auto EraseableStroke::erase(double x, double y, double halfEraserSize, Range* ra
erase(x, y, halfEraserSize, p, tmpCopy);
}
g_mutex_lock(&this->partLock);
this->partLock.lock();
PartList* old = this->parts;
this->parts = tmpCopy;
g_mutex_unlock(&this->partLock);
this->partLock.unlock();
delete old;

@ -11,6 +11,7 @@
#pragma once
#include <mutex>
#include <string>
#include <vector>
@ -47,7 +48,7 @@ private:
void addRepaintRect(double x, double y, double width, double height);
private:
GMutex partLock{};
std::mutex partLock;
PartList* parts = nullptr;
Range* repaintRect = nullptr;

Loading…
Cancel
Save