Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
pwmt
zathura
Commits
e043e55b
Commit
e043e55b
authored
Jan 26, 2011
by
Moritz Lipp
Browse files
Use GCond for rendering thread
parent
056269fc
Changes
2
Hide whitespace changes
Inline
Side-by-side
render.c
View file @
e043e55b
...
...
@@ -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
;
}
...
...
render.h
View file @
e043e55b
...
...
@@ -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
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment