Restore compatibility with earlier versions of glib

Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
Sebastian Ramacher 2013-02-09 14:50:43 +01:00
parent b0d5cdd7c0
commit edde1bf00f
3 changed files with 38 additions and 10 deletions

23
glib-compat.h Normal file
View file

@ -0,0 +1,23 @@
/* See LICENSE file for license and copyright information */
#ifndef GLIB_COMPAT_H
#define GLIB_COMPAT_H
#include <glib.h>
/* 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

View file

@ -7,6 +7,7 @@
#include <string.h>
#include <glib/gi18n.h>
#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);
}

View file

@ -6,6 +6,7 @@
#include <girara/session.h>
#include <girara/settings.h>
#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);
}