[Asterisk-code-review] sched: ast sched del may return prematurely due to spurious ... (asterisk[master])

Mark Michelson asteriskteam at digium.com
Sat Aug 29 07:54:35 CDT 2015


Mark Michelson has submitted this change and it was merged.

Change subject: sched: ast_sched_del may return prematurely due to spurious wakeup
......................................................................


sched: ast_sched_del may return prematurely due to spurious wakeup

When deleting a scheduled item if the item in question is currently
executing the ast_sched_del function waits until it has completed.
This is accomplished using ast_cond_wait. Unfortunately the
ast_cond_wait function can suffer from spurious wakeups so the
predicate needs to be checked after it returns to make sure it has
really woken up as a result of being signaled.

This change adds a loop around the ast_cond_wait to make sure that
it only exits when the executing task has really completed.

ASTERISK-25355 #close

Change-Id: I51198270eb0b637c956c61aa409f46283432be61
---
M main/sched.c
1 file changed, 3 insertions(+), 1 deletion(-)

Approvals:
  Mark Michelson: Looks good to me, approved
  Anonymous Coward #1000019: Verified
  Matt Jordan: Looks good to me, but someone else must approve



diff --git a/main/sched.c b/main/sched.c
index d50a31e..062b2fd 100644
--- a/main/sched.c
+++ b/main/sched.c
@@ -497,7 +497,9 @@
 		/* Wait for executing task to complete so that caller of ast_sched_del() does not
 		 * free memory out from under the task.
 		 */
-		ast_cond_wait(&s->cond, &con->lock);
+		while (con->currently_executing && (id == con->currently_executing->id)) {
+			ast_cond_wait(&s->cond, &con->lock);
+		}
 		/* Do not sched_release() here because ast_sched_runq() will do it */
 	}
 

-- 
To view, visit https://gerrit.asterisk.org/1159
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I51198270eb0b637c956c61aa409f46283432be61
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-code-review mailing list