Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
asterisk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Voice
asterisk
Commits
430f97f5
Commit
430f97f5
authored
6 years ago
by
George Joseph
Committed by
Gerrit Code Review
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge "threadpool: Eliminate pointless AO2 usage."
parents
aae5bdc2
f06de690
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main/threadpool.c
+40
-16
40 additions, 16 deletions
main/threadpool.c
with
40 additions
and
16 deletions
main/threadpool.c
+
40
−
16
View file @
430f97f5
...
@@ -200,10 +200,10 @@ struct thread_worker_pair {
...
@@ -200,10 +200,10 @@ struct thread_worker_pair {
/*!
/*!
* \brief Destructor for thread_worker_pair
* \brief Destructor for thread_worker_pair
*/
*/
static
void
thread_worker_pair_
de
struct
or
(
void
*
obj
)
static
void
thread_worker_pair_
free
(
struct
thread_worker_pair
*
pair
)
{
{
struct
thread_worker_pair
*
pair
=
obj
;
ao2_ref
(
pair
->
worker
,
-
1
);
ao2_ref
(
pair
->
worker
,
-
1
);
ast_free
(
pair
);
}
}
/*!
/*!
...
@@ -214,13 +214,14 @@ static void thread_worker_pair_destructor(void *obj)
...
@@ -214,13 +214,14 @@ static void thread_worker_pair_destructor(void *obj)
static
struct
thread_worker_pair
*
thread_worker_pair_alloc
(
struct
ast_threadpool
*
pool
,
static
struct
thread_worker_pair
*
thread_worker_pair_alloc
(
struct
ast_threadpool
*
pool
,
struct
worker_thread
*
worker
)
struct
worker_thread
*
worker
)
{
{
struct
thread_worker_pair
*
pair
=
a
o2_
alloc
(
sizeof
(
*
pair
)
,
thread_worker_pair_destructor
);
struct
thread_worker_pair
*
pair
=
a
st_m
alloc
(
sizeof
(
*
pair
));
if
(
!
pair
)
{
if
(
!
pair
)
{
return
NULL
;
return
NULL
;
}
}
pair
->
pool
=
pool
;
pair
->
pool
=
pool
;
ao2_ref
(
worker
,
+
1
);
ao2_ref
(
worker
,
+
1
);
pair
->
worker
=
worker
;
pair
->
worker
=
worker
;
return
pair
;
return
pair
;
}
}
...
@@ -240,7 +241,7 @@ static int queued_active_thread_idle(void *data)
...
@@ -240,7 +241,7 @@ static int queued_active_thread_idle(void *data)
threadpool_send_state_changed
(
pair
->
pool
);
threadpool_send_state_changed
(
pair
->
pool
);
ao2_ref
(
pair
,
-
1
);
thread_worker_pair_free
(
pair
);
return
0
;
return
0
;
}
}
...
@@ -257,14 +258,19 @@ static void threadpool_active_thread_idle(struct ast_threadpool *pool,
...
@@ -257,14 +258,19 @@ static void threadpool_active_thread_idle(struct ast_threadpool *pool,
{
{
struct
thread_worker_pair
*
pair
;
struct
thread_worker_pair
*
pair
;
SCOPED_AO2LOCK
(
lock
,
pool
);
SCOPED_AO2LOCK
(
lock
,
pool
);
if
(
pool
->
shutting_down
)
{
if
(
pool
->
shutting_down
)
{
return
;
return
;
}
}
pair
=
thread_worker_pair_alloc
(
pool
,
worker
);
pair
=
thread_worker_pair_alloc
(
pool
,
worker
);
if
(
!
pair
)
{
if
(
!
pair
)
{
return
;
return
;
}
}
ast_taskprocessor_push
(
pool
->
control_tps
,
queued_active_thread_idle
,
pair
);
if
(
ast_taskprocessor_push
(
pool
->
control_tps
,
queued_active_thread_idle
,
pair
))
{
thread_worker_pair_free
(
pair
);
}
}
}
/*!
/*!
...
@@ -282,7 +288,7 @@ static int queued_zombie_thread_dead(void *data)
...
@@ -282,7 +288,7 @@ static int queued_zombie_thread_dead(void *data)
ao2_unlink
(
pair
->
pool
->
zombie_threads
,
pair
->
worker
);
ao2_unlink
(
pair
->
pool
->
zombie_threads
,
pair
->
worker
);
threadpool_send_state_changed
(
pair
->
pool
);
threadpool_send_state_changed
(
pair
->
pool
);
ao2_ref
(
pair
,
-
1
);
thread_worker_pair_free
(
pair
);
return
0
;
return
0
;
}
}
...
@@ -297,14 +303,19 @@ static void threadpool_zombie_thread_dead(struct ast_threadpool *pool,
...
@@ -297,14 +303,19 @@ static void threadpool_zombie_thread_dead(struct ast_threadpool *pool,
{
{
struct
thread_worker_pair
*
pair
;
struct
thread_worker_pair
*
pair
;
SCOPED_AO2LOCK
(
lock
,
pool
);
SCOPED_AO2LOCK
(
lock
,
pool
);
if
(
pool
->
shutting_down
)
{
if
(
pool
->
shutting_down
)
{
return
;
return
;
}
}
pair
=
thread_worker_pair_alloc
(
pool
,
worker
);
pair
=
thread_worker_pair_alloc
(
pool
,
worker
);
if
(
!
pair
)
{
if
(
!
pair
)
{
return
;
return
;
}
}
ast_taskprocessor_push
(
pool
->
control_tps
,
queued_zombie_thread_dead
,
pair
);
if
(
ast_taskprocessor_push
(
pool
->
control_tps
,
queued_zombie_thread_dead
,
pair
))
{
thread_worker_pair_free
(
pair
);
}
}
}
static
int
queued_idle_thread_dead
(
void
*
data
)
static
int
queued_idle_thread_dead
(
void
*
data
)
...
@@ -314,7 +325,7 @@ static int queued_idle_thread_dead(void *data)
...
@@ -314,7 +325,7 @@ static int queued_idle_thread_dead(void *data)
ao2_unlink
(
pair
->
pool
->
idle_threads
,
pair
->
worker
);
ao2_unlink
(
pair
->
pool
->
idle_threads
,
pair
->
worker
);
threadpool_send_state_changed
(
pair
->
pool
);
threadpool_send_state_changed
(
pair
->
pool
);
ao2_ref
(
pair
,
-
1
);
thread_worker_pair_free
(
pair
);
return
0
;
return
0
;
}
}
...
@@ -323,14 +334,19 @@ static void threadpool_idle_thread_dead(struct ast_threadpool *pool,
...
@@ -323,14 +334,19 @@ static void threadpool_idle_thread_dead(struct ast_threadpool *pool,
{
{
struct
thread_worker_pair
*
pair
;
struct
thread_worker_pair
*
pair
;
SCOPED_AO2LOCK
(
lock
,
pool
);
SCOPED_AO2LOCK
(
lock
,
pool
);
if
(
pool
->
shutting_down
)
{
if
(
pool
->
shutting_down
)
{
return
;
return
;
}
}
pair
=
thread_worker_pair_alloc
(
pool
,
worker
);
pair
=
thread_worker_pair_alloc
(
pool
,
worker
);
if
(
!
pair
)
{
if
(
!
pair
)
{
return
;
return
;
}
}
ast_taskprocessor_push
(
pool
->
control_tps
,
queued_idle_thread_dead
,
pair
);
if
(
ast_taskprocessor_push
(
pool
->
control_tps
,
queued_idle_thread_dead
,
pair
))
{
thread_worker_pair_free
(
pair
);
}
}
}
/*!
/*!
...
@@ -447,7 +463,7 @@ struct task_pushed_data {
...
@@ -447,7 +463,7 @@ struct task_pushed_data {
static
struct
task_pushed_data
*
task_pushed_data_alloc
(
struct
ast_threadpool
*
pool
,
static
struct
task_pushed_data
*
task_pushed_data_alloc
(
struct
ast_threadpool
*
pool
,
int
was_empty
)
int
was_empty
)
{
{
struct
task_pushed_data
*
tpd
=
a
o2_
alloc
(
sizeof
(
*
tpd
)
,
NULL
);
struct
task_pushed_data
*
tpd
=
a
st_m
alloc
(
sizeof
(
*
tpd
));
if
(
!
tpd
)
{
if
(
!
tpd
)
{
return
NULL
;
return
NULL
;
...
@@ -549,6 +565,8 @@ static int queued_task_pushed(void *data)
...
@@ -549,6 +565,8 @@ static int queued_task_pushed(void *data)
int
was_empty
=
tpd
->
was_empty
;
int
was_empty
=
tpd
->
was_empty
;
unsigned
int
existing_active
;
unsigned
int
existing_active
;
ast_free
(
tpd
);
if
(
pool
->
listener
&&
pool
->
listener
->
callbacks
->
task_pushed
)
{
if
(
pool
->
listener
&&
pool
->
listener
->
callbacks
->
task_pushed
)
{
pool
->
listener
->
callbacks
->
task_pushed
(
pool
,
pool
->
listener
,
was_empty
);
pool
->
listener
->
callbacks
->
task_pushed
(
pool
,
pool
->
listener
,
was_empty
);
}
}
...
@@ -565,7 +583,6 @@ static int queued_task_pushed(void *data)
...
@@ -565,7 +583,6 @@ static int queued_task_pushed(void *data)
/* If no idle threads could be transitioned to active grow the pool as permitted. */
/* If no idle threads could be transitioned to active grow the pool as permitted. */
if
(
ao2_container_count
(
pool
->
active_threads
)
==
existing_active
)
{
if
(
ao2_container_count
(
pool
->
active_threads
)
==
existing_active
)
{
if
(
!
pool
->
options
.
auto_increment
)
{
if
(
!
pool
->
options
.
auto_increment
)
{
ao2_ref
(
tpd
,
-
1
);
return
0
;
return
0
;
}
}
grow
(
pool
,
pool
->
options
.
auto_increment
);
grow
(
pool
,
pool
->
options
.
auto_increment
);
...
@@ -575,7 +592,6 @@ static int queued_task_pushed(void *data)
...
@@ -575,7 +592,6 @@ static int queued_task_pushed(void *data)
}
}
threadpool_send_state_changed
(
pool
);
threadpool_send_state_changed
(
pool
);
ao2_ref
(
tpd
,
-
1
);
return
0
;
return
0
;
}
}
...
@@ -598,12 +614,15 @@ static void threadpool_tps_task_pushed(struct ast_taskprocessor_listener *listen
...
@@ -598,12 +614,15 @@ static void threadpool_tps_task_pushed(struct ast_taskprocessor_listener *listen
if
(
pool
->
shutting_down
)
{
if
(
pool
->
shutting_down
)
{
return
;
return
;
}
}
tpd
=
task_pushed_data_alloc
(
pool
,
was_empty
);
tpd
=
task_pushed_data_alloc
(
pool
,
was_empty
);
if
(
!
tpd
)
{
if
(
!
tpd
)
{
return
;
return
;
}
}
ast_taskprocessor_push
(
pool
->
control_tps
,
queued_task_pushed
,
tpd
);
if
(
ast_taskprocessor_push
(
pool
->
control_tps
,
queued_task_pushed
,
tpd
))
{
ast_free
(
tpd
);
}
}
}
/*!
/*!
...
@@ -790,7 +809,7 @@ struct set_size_data {
...
@@ -790,7 +809,7 @@ struct set_size_data {
static
struct
set_size_data
*
set_size_data_alloc
(
struct
ast_threadpool
*
pool
,
static
struct
set_size_data
*
set_size_data_alloc
(
struct
ast_threadpool
*
pool
,
unsigned
int
size
)
unsigned
int
size
)
{
{
struct
set_size_data
*
ssd
=
a
o2_
alloc
(
sizeof
(
*
ssd
)
,
NULL
);
struct
set_size_data
*
ssd
=
a
st_m
alloc
(
sizeof
(
*
ssd
));
if
(
!
ssd
)
{
if
(
!
ssd
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -813,7 +832,7 @@ static struct set_size_data *set_size_data_alloc(struct ast_threadpool *pool,
...
@@ -813,7 +832,7 @@ static struct set_size_data *set_size_data_alloc(struct ast_threadpool *pool,
*/
*/
static
int
queued_set_size
(
void
*
data
)
static
int
queued_set_size
(
void
*
data
)
{
{
RAII_VAR
(
struct
set_size_data
*
,
ssd
,
data
,
ao2_cleanup
)
;
struct
set_size_data
*
ssd
=
data
;
struct
ast_threadpool
*
pool
=
ssd
->
pool
;
struct
ast_threadpool
*
pool
=
ssd
->
pool
;
unsigned
int
num_threads
=
ssd
->
size
;
unsigned
int
num_threads
=
ssd
->
size
;
...
@@ -821,6 +840,8 @@ static int queued_set_size(void *data)
...
@@ -821,6 +840,8 @@ static int queued_set_size(void *data)
unsigned
int
current_size
=
ao2_container_count
(
pool
->
active_threads
)
+
unsigned
int
current_size
=
ao2_container_count
(
pool
->
active_threads
)
+
ao2_container_count
(
pool
->
idle_threads
);
ao2_container_count
(
pool
->
idle_threads
);
ast_free
(
ssd
);
if
(
current_size
==
num_threads
)
{
if
(
current_size
==
num_threads
)
{
ast_debug
(
3
,
"Not changing threadpool size since new size %u is the same as current %u
\n
"
,
ast_debug
(
3
,
"Not changing threadpool size since new size %u is the same as current %u
\n
"
,
num_threads
,
current_size
);
num_threads
,
current_size
);
...
@@ -849,6 +870,7 @@ void ast_threadpool_set_size(struct ast_threadpool *pool, unsigned int size)
...
@@ -849,6 +870,7 @@ void ast_threadpool_set_size(struct ast_threadpool *pool, unsigned int size)
{
{
struct
set_size_data
*
ssd
;
struct
set_size_data
*
ssd
;
SCOPED_AO2LOCK
(
lock
,
pool
);
SCOPED_AO2LOCK
(
lock
,
pool
);
if
(
pool
->
shutting_down
)
{
if
(
pool
->
shutting_down
)
{
return
;
return
;
}
}
...
@@ -858,7 +880,9 @@ void ast_threadpool_set_size(struct ast_threadpool *pool, unsigned int size)
...
@@ -858,7 +880,9 @@ void ast_threadpool_set_size(struct ast_threadpool *pool, unsigned int size)
return
;
return
;
}
}
ast_taskprocessor_push
(
pool
->
control_tps
,
queued_set_size
,
ssd
);
if
(
ast_taskprocessor_push
(
pool
->
control_tps
,
queued_set_size
,
ssd
))
{
ast_free
(
ssd
);
}
}
}
struct
ast_threadpool_listener
*
ast_threadpool_listener_alloc
(
struct
ast_threadpool_listener
*
ast_threadpool_listener_alloc
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment