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

Joshua Colp asteriskteam at digium.com
Fri Aug 28 20:02:59 CDT 2015


Joshua Colp has uploaded a new change for review.

  https://gerrit.asterisk.org/1157

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(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/57/1157/1

diff --git a/main/sched.c b/main/sched.c
index 4443497..033d238 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/1157
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I51198270eb0b637c956c61aa409f46283432be61
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list