Commit e043e55b authored by Moritz Lipp's avatar Moritz Lipp

Use GCond for rendering thread

parent 056269fc
......@@ -10,17 +10,15 @@ render_job(void* data)
render_thread_t* render_thread = (render_thread_t*) data;
while(true) {
g_static_mutex_lock(&(render_thread->lock));
g_mutex_lock(render_thread->lock);
if(girara_list_size(render_thread->list) <= 0) {
g_static_mutex_unlock(&(render_thread->lock));
g_thread_yield();
continue;
g_cond_wait(render_thread->cond, render_thread->lock);
}
zathura_page_t* page = (zathura_page_t*) girara_list_nth(render_thread->list, 0);
girara_list_remove(render_thread->list, page);
g_static_mutex_unlock(&(render_thread->lock));
g_mutex_unlock(render_thread->lock);
printf("Rendered %d\n", page->number);
......@@ -39,6 +37,12 @@ render_init(void)
goto error_ret;
}
/* init */
render_thread->list = NULL;
render_thread->thread = NULL;
render_thread->cond = NULL;
/* setup */
render_thread->list = girara_list_new();
if(!render_thread->list) {
......@@ -51,12 +55,34 @@ render_init(void)
goto error_free;
}
g_static_mutex_init(&(render_thread->lock));
render_thread->cond = g_cond_new();
if(!render_thread->cond) {
goto error_free;
}
render_thread->lock = g_mutex_new();
if(!render_thread->lock) {
goto error_free;
}
return render_thread;
error_free:
if(render_thread->list) {
girara_list_free(render_thread->list);
}
if(render_thread->cond) {
g_cond_free(render_thread->cond);
}
if(render_thread->lock) {
g_mutex_free(render_thread->lock);
}
free(render_thread);
error_ret:
......@@ -71,8 +97,17 @@ render_free(render_thread_t* render_thread)
return;
}
girara_list_free(render_thread->list);
g_static_mutex_free(&(render_thread->lock));
if(render_thread->list) {
girara_list_free(render_thread->list);
}
if(render_thread->cond) {
g_cond_free(render_thread->cond);
}
if(render_thread->lock) {
g_mutex_free(render_thread->lock);
}
}
bool
......@@ -82,11 +117,12 @@ render_page(render_thread_t* render_thread, zathura_page_t* page)
return false;
}
g_static_mutex_lock(&(render_thread->lock));
g_mutex_lock(render_thread->lock);
if(!girara_list_contains(render_thread->list, page)) {
girara_list_append(render_thread->list, page);
}
g_static_mutex_unlock(&(render_thread->lock));
g_cond_signal(render_thread->cond);
g_mutex_unlock(render_thread->lock);
return true;
}
......
......@@ -13,7 +13,8 @@ typedef struct render_thread_s
{
girara_list_t* list;
GThread* thread;
GStaticMutex lock;
GMutex* lock;
GCond* cond;
} render_thread_t;
render_thread_t* render_init(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment