]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stream: No longer use TASK_F_UEVT* to shut a stream down
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 27 Jan 2025 18:11:02 +0000 (19:11 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 28 Jan 2025 13:53:37 +0000 (14:53 +0100)
Thanks to the previous patch, it is now possible to explicitly rely on
stream's events to shut it down. The right event is set in
stream_shutdown(), before waking up the stream, via an atomic operation. In
process_stream(), this event will be handled as expected.

Thus, TASK_F_UEVT* are no longer used, but not removed since still usable
for other tasks.

This patch depends on "MEDIUM: stream: Map task wake up reasons to dedicated
stream events".

include/haproxy/stream.h
src/stream.c

index 3ca799912a3fccb00052b63472e66aeefe056da6..4e503a32d247b77c85a88477d59cf75245413179 100644 (file)
@@ -386,24 +386,25 @@ static inline int stream_check_conn_timeout(struct stream *s)
 }
 
 /* Wake a stream up for shutdown by sending it an event. The stream must be
- * locked one way or another so that it cannot leave (i.e. when inspecting
- * a locked list or under thread isolation). Process_stream() will recognize
- * the message and complete the job. <why> only supports SF_ERR_DOWN (mapped
- * to UEVT1), SF_ERR_KILLED (mapped to UEVT2) and SF_ERR_UP (mapped to UEVT3).
- * Other values will just trigger TASK_WOKEN_OTHER.
- * The stream handler will first call function stream_shutdown_self() on wakeup
- * to complete the notification.
+ * locked one way or another so that it cannot leave (i.e. when inspecting a
+ * locked list or under thread isolation). Process_stream() will recognize the
+ * message and complete the job. <why> only supports SF_ERR_DOWN (mapped to
+ * STRM_EVT_SHUT_SRV_DOWN), SF_ERR_KILLED (mapped to STRM_EVT_KILLED) and
+ * SF_ERR_UP (mapped to STRM_EVT_SHUT_SRV_UP). Other values will just be
+ * ignored. The stream is woken up with TASK_WOKEN_OTHER reason. The stream
+ * handler will first call function stream_shutdown_self() on wakeup to complete
+ * the notification.
  */
 static inline void stream_shutdown(struct stream *s, int why)
 {
-       task_wakeup(s->task, TASK_WOKEN_OTHER |
-                   ((why == SF_ERR_DOWN) ? TASK_F_UEVT1 :
-                    (why == SF_ERR_KILLED) ? TASK_F_UEVT2 :
-                    (why == SF_ERR_UP) ? TASK_F_UEVT3 :
-                    0));
+       HA_ATOMIC_OR(&s->new_events, ((why == SF_ERR_DOWN) ? STRM_EVT_SHUT_SRV_DOWN :
+                                     (why == SF_ERR_KILLED) ? STRM_EVT_KILLED :
+                                     (why == SF_ERR_UP) ? STRM_EVT_SHUT_SRV_UP :
+                                     0));
+       task_wakeup(s->task, TASK_WOKEN_OTHER);
 }
 
-/* Map task states to stream events. TASK_WOKEN_* and TASK_F_UEVT* are mapped on
+/* Map task states to stream events. TASK_WOKEN_* are mapped on
  * STRM_EVT_*. Not all states/flags are mapped, only those explicitly used by
  * the stream.
  */
index f5a3f806e8000bb2db6a4b97c4ed514299ded5e4..819de896798fdda1d41e0ec7c890eb357324e0e3 100644 (file)
@@ -1703,12 +1703,14 @@ void stream_update_timings(struct task *t, uint64_t lat, uint64_t cpu)
  * and each function is called only if at least another function has changed at
  * least one flag it is interested in.
  *
- * This task handler understands a few wake up reasons:
- *  - TASK_WOKEN_MSG forces analysers to be re-evaluated
- *  - TASK_WOKEN_OTHER+TASK_F_UEVT1 shuts the stream down on server down
- *  - TASK_WOKEN_OTHER+TASK_F_UEVT2 shuts the stream down on active kill
- *  - TASK_WOKEN_OTHER+TASK_F_UEVT3 shuts the stream down because a preferred backend became available
- *  - TASK_WOKEN_OTHER alone has no effect
+ * TASK_WOKEN_* wake up reasons are mapped to STRM_EVT_*
+ *
+ * This task handler understands a few wake up events:
+ *  - STRM_EVT_MSG forces analysers to be re-evaluated
+ *  - STRM_EVT_TIMER forces timers to be re-evaluated
+ *  - STRM_EVT_SHUT_SRV_DOWN shuts the stream down on server down
+ *  - STRM_EVT_KILLED shuts the stream down on active kill
+ *  - STRM_EVT_SHUT_SRV_UP shuts the stream down because a preferred backend became available
  */
 struct task *process_stream(struct task *t, void *context, unsigned int state)
 {