From edde1bf00f48d35a2b4fa435e20ccdb960320a32 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sat, 9 Feb 2013 14:50:43 +0100 Subject: [PATCH] Restore compatibility with earlier versions of glib Signed-off-by: Sebastian Ramacher --- glib-compat.h | 23 +++++++++++++++++++++++ page-widget.c | 15 +++++++++------ render.c | 10 ++++++---- 3 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 glib-compat.h diff --git a/glib-compat.h b/glib-compat.h new file mode 100644 index 0000000..c76ccca --- /dev/null +++ b/glib-compat.h @@ -0,0 +1,23 @@ +/* See LICENSE file for license and copyright information */ + +#ifndef GLIB_COMPAT_H +#define GLIB_COMPAT_H + +#include + +/* GStaticMutex is deprecated starting with glib 2.32 */ +#if !GLIB_CHECK_VERSION(2, 31, 0) +#define mutex GStaticMutex +#define mutex_init(m) g_static_mutex_init((m)) +#define mutex_lock(m) g_static_mutex_lock((m)) +#define mutex_unlock(m) g_static_mutex_unlock((m)) +#define mutex_free(m) g_static_mutex_free((m)) +#else +#define mutex GMutex +#define mutex_init(m) g_mutex_init((m)) +#define mutex_lock(m) g_mutex_lock((m)) +#define mutex_unlock(m) g_mutex_unlock((m)) +#define mutex_free(m) g_mutex_clear((m)) +#endif + +#endif diff --git a/page-widget.c b/page-widget.c index d3c34e7..529f3f0 100644 --- a/page-widget.c +++ b/page-widget.c @@ -7,6 +7,7 @@ #include #include +#include "glib-compat.h" #include "links.h" #include "page-widget.h" #include "page.h" @@ -22,7 +23,7 @@ typedef struct zathura_page_widget_private_s { zathura_t* zathura; /**< Zathura object */ cairo_surface_t* surface; /**< Cairo surface */ gint64 last_view; /**< Last time the page has been viewed */ - GMutex lock; /**< Lock */ + mutex lock; /**< Lock */ struct { girara_list_t* list; /**< List of links on the page */ @@ -162,7 +163,7 @@ zathura_page_widget_init(ZathuraPage* widget) priv->mouse.selection_basepoint.x = -1; priv->mouse.selection_basepoint.y = -1; - g_mutex_init(&(priv->lock)); + mutex_init(&(priv->lock)); /* we want mouse events */ gtk_widget_add_events(GTK_WIDGET(widget), @@ -195,6 +196,8 @@ zathura_page_widget_finalize(GObject* object) girara_list_free(priv->links.list); } + mutex_free(&(priv->lock)); + G_OBJECT_CLASS(zathura_page_widget_parent_class)->finalize(object); } @@ -323,7 +326,7 @@ static gboolean zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo) { zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(widget); - g_mutex_lock(&(priv->lock)); + mutex_lock(&(priv->lock)); zathura_document_t* document = zathura_page_get_document(priv->page); @@ -464,7 +467,7 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo) /* render real page */ render_page(priv->zathura->sync.render_thread, priv->page); } - g_mutex_unlock(&(priv->lock)); + mutex_unlock(&(priv->lock)); return FALSE; } @@ -479,13 +482,13 @@ void zathura_page_widget_update_surface(ZathuraPage* widget, cairo_surface_t* surface) { zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(widget); - g_mutex_lock(&(priv->lock)); + mutex_lock(&(priv->lock)); if (priv->surface != NULL) { cairo_surface_finish(priv->surface); cairo_surface_destroy(priv->surface); } priv->surface = surface; - g_mutex_unlock(&(priv->lock)); + mutex_unlock(&(priv->lock)); /* force a redraw here */ zathura_page_widget_redraw_canvas(widget); } diff --git a/render.c b/render.c index c410e66..502577b 100644 --- a/render.c +++ b/render.c @@ -6,6 +6,7 @@ #include #include +#include "glib-compat.h" #include "render.h" #include "zathura.h" #include "document.h" @@ -19,7 +20,7 @@ static gint render_thread_sort(gconstpointer a, gconstpointer b, gpointer data); struct render_thread_s { GThreadPool* pool; /**< Pool of threads */ - GMutex mutex; /**< Render lock */ + mutex mutex; /**< Render lock */ bool about_to_close; /**< Render thread is to be freed */ }; @@ -51,7 +52,7 @@ render_init(zathura_t* zathura) render_thread->about_to_close = false; g_thread_pool_set_sort_function(render_thread->pool, render_thread_sort, zathura); - g_mutex_init(&render_thread->mutex); + mutex_init(&render_thread->mutex); return render_thread; @@ -73,6 +74,7 @@ render_free(render_thread_t* render_thread) g_thread_pool_free(render_thread->pool, TRUE, TRUE); } + mutex_free(&(render_thread->mutex)); g_free(render_thread); } @@ -328,7 +330,7 @@ render_lock(render_thread_t* render_thread) return; } - g_mutex_lock(&render_thread->mutex); + mutex_lock(&render_thread->mutex); } void @@ -338,5 +340,5 @@ render_unlock(render_thread_t* render_thread) return; } - g_mutex_unlock(&render_thread->mutex); + mutex_unlock(&render_thread->mutex); }