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
ace043f4
Commit
ace043f4
authored
9 years ago
by
Joshua Colp
Committed by
Gerrit Code Review
9 years ago
Browse files
Options
Downloads
Plain Diff
Merge "res_sorcery_memory_cache.c: Fix deadlock with scheduler."
parents
45bba81f
1b80dbeb
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
res/res_sorcery_memory_cache.c
+22
-13
22 additions, 13 deletions
res/res_sorcery_memory_cache.c
with
22 additions
and
13 deletions
res/res_sorcery_memory_cache.c
+
22
−
13
View file @
ace043f4
...
...
@@ -124,6 +124,8 @@ struct sorcery_memory_cache {
struct
ast_heap
*
object_heap
;
/*! \brief Scheduler item for expiring oldest object. */
int
expire_id
;
/*! TRUE if trying to stop the oldest object expiration scheduler item. */
unsigned
int
del_expire
:
1
;
#ifdef TEST_FRAMEWORK
/*! \brief Variable used to indicate we should notify a test when we reach empty */
unsigned
int
cache_notify
;
...
...
@@ -443,7 +445,21 @@ static int expire_objects_from_cache(const void *data)
struct
sorcery_memory_cache
*
cache
=
(
struct
sorcery_memory_cache
*
)
data
;
struct
sorcery_memory_cached_object
*
cached
;
ao2_wrlock
(
cache
->
objects
);
/*
* We need to do deadlock avoidance between a non-scheduler thread
* blocking when trying to delete the scheduled entry for this
* callback because the scheduler thread is running this callback
* and this callback waiting for the cache->objects container lock
* that the blocked non-scheduler thread already holds.
*/
while
(
ao2_trywrlock
(
cache
->
objects
))
{
if
(
cache
->
del_expire
)
{
cache
->
expire_id
=
-
1
;
ao2_ref
(
cache
,
-
1
);
return
0
;
}
sched_yield
();
}
cache
->
expire_id
=
-
1
;
...
...
@@ -488,7 +504,9 @@ static void remove_all_from_cache(struct sorcery_memory_cache *cache)
ao2_callback
(
cache
->
objects
,
OBJ_UNLINK
|
OBJ_NOLOCK
|
OBJ_NODATA
|
OBJ_MULTIPLE
,
NULL
,
NULL
);
cache
->
del_expire
=
1
;
AST_SCHED_DEL_UNREF
(
sched
,
cache
->
expire_id
,
ao2_ref
(
cache
,
-
1
));
cache
->
del_expire
=
0
;
}
/*!
...
...
@@ -581,18 +599,9 @@ static int schedule_cache_expiration(struct sorcery_memory_cache *cache)
return
0
;
}
if
(
cache
->
expire_id
!=
-
1
)
{
/* If we can't unschedule this expiration then it is currently attempting to run,
* so let it run - it just means that it'll be the one scheduling instead of us.
*/
if
(
ast_sched_del
(
sched
,
cache
->
expire_id
))
{
return
0
;
}
/* Since it successfully cancelled we need to drop the ref to the cache it had */
ao2_ref
(
cache
,
-
1
);
cache
->
expire_id
=
-
1
;
}
cache
->
del_expire
=
1
;
AST_SCHED_DEL_UNREF
(
sched
,
cache
->
expire_id
,
ao2_ref
(
cache
,
-
1
));
cache
->
del_expire
=
0
;
cached
=
ast_heap_peek
(
cache
->
object_heap
,
1
);
if
(
!
cached
)
{
...
...
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