MEDIUM: buffer: remove the buffer_wq lock
This lock was only needed to protect the buffer_wq list, but now we have
the mt_list for this. This patch simply turns the buffer_wq list to an
mt_list and gets rid of the lock.
It's worth noting that the whole buffer_wait thing still looks totally
wrong especially in a threaded context: the wakeup_cb() callback is
called synchronously from any thread and may end up calling some
connection code that was not expected to run on a given thread. The
whole thing should probably be reworked to use tasklets instead and be
a bit more centralized.
diff --git a/include/proto/applet.h b/include/proto/applet.h
index b4e9396..31b4d90 100644
--- a/include/proto/applet.h
+++ b/include/proto/applet.h
@@ -75,7 +75,7 @@
}
appctx->t->process = task_run_applet;
appctx->t->context = appctx;
- LIST_INIT(&appctx->buffer_wait.list);
+ MT_LIST_INIT(&appctx->buffer_wait.list);
appctx->buffer_wait.target = appctx;
appctx->buffer_wait.wakeup_cb = appctx_buf_available;
_HA_ATOMIC_ADD(&nb_applets, 1);
@@ -87,12 +87,8 @@
static inline void __appctx_free(struct appctx *appctx)
{
task_destroy(appctx->t);
- if (!LIST_ISEMPTY(&appctx->buffer_wait.list)) {
- HA_SPIN_LOCK(BUF_WQ_LOCK, &buffer_wq_lock);
- LIST_DEL(&appctx->buffer_wait.list);
- LIST_INIT(&appctx->buffer_wait.list);
- HA_SPIN_UNLOCK(BUF_WQ_LOCK, &buffer_wq_lock);
- }
+ if (MT_LIST_ADDED(&appctx->buffer_wait.list))
+ MT_LIST_DEL(&appctx->buffer_wait.list);
pool_free(pool_head_appctx, appctx);
_HA_ATOMIC_SUB(&nb_applets, 1);
diff --git a/include/proto/channel.h b/include/proto/channel.h
index 5411a74..88f4f25 100644
--- a/include/proto/channel.h
+++ b/include/proto/channel.h
@@ -855,11 +855,8 @@
if (b_alloc_margin(&chn->buf, margin) != NULL)
return 1;
- if (LIST_ISEMPTY(&wait->list)) {
- HA_SPIN_LOCK(BUF_WQ_LOCK, &buffer_wq_lock);
- LIST_ADDQ(&buffer_wq, &wait->list);
- HA_SPIN_UNLOCK(BUF_WQ_LOCK, &buffer_wq_lock);
- }
+ if (!MT_LIST_ADDED(&wait->list))
+ MT_LIST_ADDQ(&buffer_wq, &wait->list);
return 0;
}