From 22fea7d28185f465fa230b0f4691d028de9b4115 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 11 Jan 2011 10:57:59 +0100 Subject: [PATCH] Began to set locks for rendering thread --- ft/document.c | 17 +++++++++++------ ft/document.h | 5 +++-- render.c | 6 ++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ft/document.c b/ft/document.c index fc340e6..040d0bf 100644 --- a/ft/document.c +++ b/ft/document.c @@ -110,10 +110,7 @@ zathura_document_open(const char* path, const char* password) goto error_free; } - page->offset = offset; - page->number = page_id; - page->rendered = false; - + page->offset = offset; offset += page->height; document->pages[page_id] = page; @@ -246,7 +243,7 @@ zathura_document_attachments_free(zathura_list_t* list) } zathura_page_t* -zathura_page_get(zathura_document_t* document, unsigned int page) +zathura_page_get(zathura_document_t* document, unsigned int page_id) { if(!document) { return NULL; @@ -257,7 +254,15 @@ zathura_page_get(zathura_document_t* document, unsigned int page) return NULL; } - return document->functions.page_get(document, page); + zathura_page_t* page = document->functions.page_get(document, page_id); + + if(page) { + page->number = page_id; + page->rendered = false; + g_static_mutex_init(&(page->lock)); + } + + return page; } bool diff --git a/ft/document.h b/ft/document.h index 45aba4d..52b09f7 100644 --- a/ft/document.h +++ b/ft/document.h @@ -82,6 +82,7 @@ typedef struct zathura_page_s zathura_document_t* document; void* data; bool rendered; + GStaticMutex lock; } zathura_page_t; struct zathura_document_s @@ -101,7 +102,7 @@ struct zathura_document_s bool (*document_save_as)(zathura_document_t* document, const char* path); zathura_list_t* (*document_attachments_get)(zathura_document_t* document); - zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page); + zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page_id); zathura_list_t* (*page_search_text)(zathura_page_t* page, const char* text); zathura_list_t* (*page_links_get)(zathura_page_t* page); zathura_list_t* (*page_form_fields_get)(zathura_page_t* page); @@ -120,7 +121,7 @@ bool zathura_document_index_free(zathura_list_t* list); zathura_list_t* zathura_document_attachments_get(zathura_document_t* document); bool zathura_document_attachments_free(zathura_list_t* list); -zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page); +zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page_id); bool zathura_page_free(zathura_page_t* page); zathura_list_t* zathura_page_search_text(zathura_page_t* page, const char* text); zathura_list_t* zathura_page_links_get(zathura_page_t* page); diff --git a/render.c b/render.c index 1e067fd..2597251 100644 --- a/render.c +++ b/render.c @@ -3,13 +3,17 @@ bool page_render(zathura_page_t* page) { + g_static_mutex_lock(&(page->lock)); GtkWidget* image = zathura_page_render(page); + g_static_mutex_unlock(&(page->lock)); + if(!image) { printf("error: rendering failed\n"); return false; } /* add new page */ + g_static_mutex_lock(&(page->lock)); GList* list = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.page_view)); GtkWidget* widget = (GtkWidget*) g_list_nth_data(list, page->number); g_list_free(list); @@ -17,6 +21,7 @@ bool page_render(zathura_page_t* page) if(!widget) { printf("error: page container does not exist\n"); g_object_unref(image); + g_static_mutex_unlock(&(page->lock)); return false; } @@ -39,6 +44,7 @@ bool page_render(zathura_page_t* page) /* reorder child */ gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page->number); + g_static_mutex_unlock(&(page->lock)); return true; }