MEDIUM: threads/tasks: Add lock around notifications
This patch add lock around some notification calls
diff --git a/include/proto/task.h b/include/proto/task.h
index bc3a173..cb98fef 100644
--- a/include/proto/task.h
+++ b/include/proto/task.h
@@ -294,6 +294,7 @@
return NULL;
LIST_ADDQ(purge, &com->purge_me);
LIST_ADDQ(event, &com->wake_me);
+ SPIN_INIT(&com->lock);
com->task = wakeup;
return com;
}
@@ -308,9 +309,15 @@
/* Delete all pending communication signals. */
list_for_each_entry_safe(com, back, purge, purge_me) {
+ SPIN_LOCK(NOTIF_LOCK, &com->lock);
LIST_DEL(&com->purge_me);
- LIST_DEL(&com->wake_me);
- pool_free2(pool2_notification, com);
+ if (!com->task) {
+ SPIN_UNLOCK(NOTIF_LOCK, &com->lock);
+ pool_free2(pool2_notification, com);
+ continue;
+ }
+ com->task = NULL;
+ SPIN_UNLOCK(NOTIF_LOCK, &com->lock);
}
}
@@ -324,10 +331,16 @@
/* Wake task and delete all pending communication signals. */
list_for_each_entry_safe(com, back, wake, wake_me) {
- LIST_DEL(&com->purge_me);
+ SPIN_LOCK(NOTIF_LOCK, &com->lock);
LIST_DEL(&com->wake_me);
+ if (!com->task) {
+ SPIN_UNLOCK(NOTIF_LOCK, &com->lock);
+ pool_free2(pool2_notification, com);
+ continue;
+ }
task_wakeup(com->task, TASK_WOKEN_MSG);
- pool_free2(pool2_notification, com);
+ com->task = NULL;
+ SPIN_UNLOCK(NOTIF_LOCK, &com->lock);
}
}