MEDIUM: threads/tasks: Add lock around notifications
This patch add lock around some notification calls
diff --git a/include/common/hathreads.h b/include/common/hathreads.h
index a5a25b4..774fe7b 100644
--- a/include/common/hathreads.h
+++ b/include/common/hathreads.h
@@ -166,6 +166,7 @@
VARS_LOCK,
COMP_POOL_LOCK,
LUA_LOCK,
+ NOTIF_LOCK,
LOCK_LABELS
};
struct lock_stat {
@@ -253,7 +254,8 @@
"LISTENER", "LISTENER_QUEUE", "PROXY", "SERVER",
"UPDATED_SERVERS", "LBPRM", "SIGNALS", "STK_TABLE", "STK_SESS",
"APPLETS", "PEER", "BUF_WQ", "STREAMS", "SSL", "SSL_GEN_CERTS",
- "PATREF", "PATEXP", "PATLRU", "VARS", "COMP_POOL", "LUA" };
+ "PATREF", "PATEXP", "PATLRU", "VARS", "COMP_POOL", "LUA",
+ "NOTIF" };
int lbl;
for (lbl = 0; lbl < LOCK_LABELS; lbl++) {
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);
}
}
diff --git a/include/types/task.h b/include/types/task.h
index da7c929..799e6c5 100644
--- a/include/types/task.h
+++ b/include/types/task.h
@@ -56,6 +56,9 @@
struct list wake_me; /* Part of list of signals to be targeted if an
event occurs. */
struct task *task; /* The task to be wake if an event occurs. */
+#ifdef USE_THREAD
+ HA_SPINLOCK_T lock;
+#endif
};
/* The base for all tasks */