Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
belle-sip
Commits
7b81a1dd
Commit
7b81a1dd
authored
Dec 02, 2016
by
jehan
Browse files
improve mainloop thread safety
parent
912c1257
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
5 deletions
+40
-5
include/belle-sip/mainloop.h
include/belle-sip/mainloop.h
+20
-0
src/belle_sip_loop.c
src/belle_sip_loop.c
+20
-5
No files found.
include/belle-sip/mainloop.h
View file @
7b81a1dd
...
...
@@ -90,6 +90,26 @@ BELLESIP_EXPORT belle_sip_source_t* belle_sip_main_loop_create_timeout(belle_sip
,
unsigned
int
timeout_value_ms
,
const
char
*
timer_name
);
/**
* Adds a timeout into the main loop
* The caller of this function is responsible for freeing (with belle_sip_object_unref()) the returned belle_sip_source_t object when it is no longer
* needed.
* @param ml
* @param func a callback function to be called to notify timeout expiration
* @param data a pointer to be passed to the callback
* @param timeout_value_ms duration of the timeout.
* @param timer_name name of the timer, can be null
* @param function called when source is removed, can be null
* @returns timeout belle_sip_source_t with ref count = 1
**/
BELLESIP_EXPORT
belle_sip_source_t
*
belle_sip_main_loop_create_timeout_with_remove_cb
(
belle_sip_main_loop_t
*
ml
,
belle_sip_source_func_t
func
,
void
*
data
,
unsigned
int
timeout_value_ms
,
const
char
*
timer_name
,
belle_sip_source_remove_callback_t
remove_func
);
/**
* Schedule an arbitrary task at next main loop iteration.
**/
...
...
src/belle_sip_loop.c
View file @
7b81a1dd
...
...
@@ -338,16 +338,28 @@ void belle_sip_main_loop_add_source(belle_sip_main_loop_t *ml, belle_sip_source_
ml
->
nsources
++
;
}
belle_sip_source_t
*
belle_sip_main_loop_create_timeout
(
belle_sip_main_loop_t
*
ml
,
belle_sip_source_func_t
func
,
void
*
data
,
unsigned
int
timeout_value_ms
,
const
char
*
timer_name
)
{
belle_sip_source_t
*
belle_sip_main_loop_create_timeout_with_remove_cb
(
belle_sip_main_loop_t
*
ml
,
belle_sip_source_func_t
func
,
void
*
data
,
unsigned
int
timeout_value_ms
,
const
char
*
timer_name
,
belle_sip_source_remove_callback_t
remove_func
)
{
belle_sip_source_t
*
s
=
belle_sip_timeout_source_new
(
func
,
data
,
timeout_value_ms
);
belle_sip_object_set_name
((
belle_sip_object_t
*
)
s
,
timer_name
);
if
(
remove_func
)
{
belle_sip_source_set_remove_cb
(
s
,
remove_func
);
}
belle_sip_main_loop_add_source
(
ml
,
s
);
return
s
;
}
belle_sip_source_t
*
belle_sip_main_loop_create_timeout
(
belle_sip_main_loop_t
*
ml
,
belle_sip_source_func_t
func
,
void
*
data
,
unsigned
int
timeout_value_ms
,
const
char
*
timer_name
)
{
return
belle_sip_main_loop_create_timeout_with_remove_cb
(
ml
,
func
,
data
,
timeout_value_ms
,
timer_name
,
NULL
);
}
unsigned
long
belle_sip_main_loop_add_timeout
(
belle_sip_main_loop_t
*
ml
,
belle_sip_source_func_t
func
,
void
*
data
,
unsigned
int
timeout_value_ms
){
belle_sip_source_t
*
s
=
belle_sip_main_loop_create_timeout
(
ml
,
func
,
data
,
timeout_value_ms
,
"Timer"
);
...
...
@@ -506,6 +518,8 @@ static void belle_sip_main_loop_iterate(belle_sip_main_loop_t *ml){
}
/* Step 3: find timeouted sources */
bctbx_mutex_lock
(
&
ml
->
timer_sources_mutex
);
/*iterator chain might be alterated by element insertion*/
it
=
bctbx_map_begin
(
ml
->
timer_sources
);
end
=
bctbx_map_end
(
ml
->
timer_sources
);
while
(
!
bctbx_iterator_equals
(
it
,
end
))
{
...
...
@@ -527,6 +541,7 @@ static void belle_sip_main_loop_iterate(belle_sip_main_loop_t *ml){
}
bctbx_iterator_delete
(
it
);
bctbx_iterator_delete
(
end
);
bctbx_mutex_unlock
(
&
ml
->
timer_sources_mutex
);
/* Step 4: notify those to be notified */
for
(
elem
=
to_be_notified
;
elem
!=
NULL
;){
...
...
Write
Preview
Markdown
is supported
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