mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-10 21:44:20 +01:00
Use GCond for rendering thread
This commit is contained in:
parent
056269fcae
commit
e043e55b13
56
render.c
56
render.c
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user