]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: task: remove unneeded tests before task_destroy()
authorWilly Tarreau <w@1wt.eu>
Tue, 7 May 2019 17:05:35 +0000 (19:05 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 7 May 2019 17:08:16 +0000 (19:08 +0200)
Since previous commit it's not needed anymore to test a task pointer
before calling task_destory() so let's just remove these tests from
the various callers before they become confusing. The function's
arguments were also documented. The same should probably be done
with tasklet_free() which involves a test in roughly half of the
call places.

include/proto/task.h
src/checks.c
src/flt_spoe.c
src/haproxy.c
src/mux_h1.c
src/mux_h2.c
src/session.c

index f16793323154a4a723ab388e3289dc736ba99344..df9bc2ad2e6a8c860e2aacf972fc55752fa6ef87 100644 (file)
@@ -329,6 +329,10 @@ static inline void __task_free(struct task *t)
        _HA_ATOMIC_SUB(&nb_tasks, 1);
 }
 
+/* Destroys a task : it's unlinked from the wait queues and is freed if it's
+ * the current task or not queued otherwise it's marked to be freed by the
+ * scheduler. It does nothing if <t> is NULL.
+ */
 static inline void task_destroy(struct task *t)
 {
        if (!t)
index e6b0bd1d063f37e84143a21c9c3c5cc9ff7208c3..63d9e03401d2bd1a3ce6d2f613c8d50cb9b0b2b9 100644 (file)
@@ -3303,10 +3303,7 @@ int init_email_alert(struct mailers *mls, struct proxy *p, char **err)
                struct email_alertq *q     = &queues[i];
                struct check        *check = &q->check;
 
-               if (check->task) {
-                       task_destroy(check->task);
-                       check->task = NULL;
-               }
+               task_destroy(check->task);
                free_check(check);
        }
        free(queues);
index 2d70aff5bee73cda0c66c3b29311eb20c530486b..75854b7ae31f9fc3b427654a52edd3e40b0a1818 100644 (file)
@@ -1275,9 +1275,7 @@ spoe_release_appctx(struct appctx *appctx)
        }
 
        /* Destroy the task attached to this applet */
-       if (spoe_appctx->task) {
-               task_destroy(spoe_appctx->task);
-       }
+       task_destroy(spoe_appctx->task);
 
        /* Notify all waiting streams */
        list_for_each_entry_safe(ctx, back, &spoe_appctx->waiting_queue, list) {
index f709224c584e917a0fe77f5b9ef109313ff07aea..8ab0c2e6f439c4bb2fd1e619a5cc18f46dd905d5 100644 (file)
@@ -2290,18 +2290,15 @@ void deinit(void)
                while (s) {
                        s_next = s->next;
 
-                       if (s->check.task)
-                               task_destroy(s->check.task);
-                       if (s->agent.task)
-                               task_destroy(s->agent.task);
+                       task_destroy(s->check.task);
+                       task_destroy(s->agent.task);
 
                        if (s->check.wait_list.task)
                                tasklet_free(s->check.wait_list.task);
                        if (s->agent.wait_list.task)
                                tasklet_free(s->agent.wait_list.task);
 
-                       if (s->warmup)
-                               task_destroy(s->warmup);
+                       task_destroy(s->warmup);
 
                        free(s->id);
                        free(s->cookie);
index 46bc33c908ea3591a40e8c5ba49169d7472a65af..69a6e251972133f486e7b2cb58c5c06c2f27013f 100644 (file)
@@ -431,8 +431,7 @@ static int h1_init(struct connection *conn, struct proxy *proxy, struct session
        return 0;
 
   fail:
-       if (t)
-               task_destroy(t);
+       task_destroy(t);
        if (h1c->wait_event.task)
                tasklet_free(h1c->wait_event.task);
        pool_free(pool_head_h1c, h1c);
index 6fb21dd2fd6377d1b17bd7f6d4a668052d905c5d..eca85cbe216e95a4a4d050f77ee336e4f06317d0 100644 (file)
@@ -575,8 +575,7 @@ static int h2_init(struct connection *conn, struct proxy *prx, struct session *s
   fail_stream:
        hpack_dht_free(h2c->ddht);
   fail:
-       if (t)
-               task_destroy(t);
+       task_destroy(t);
        if (h2c->wait_event.task)
                tasklet_free(h2c->wait_event.task);
        pool_free(pool_head_h2c, h2c);
index 875fae89b79eff8d6db624d2615e6087d54583b6..c77f1e9596b296e1e7dcbeacde0943001593215e 100644 (file)
@@ -448,11 +448,8 @@ static int conn_complete_session(struct connection *conn)
                goto fail;
 
        /* the embryonic session's task is not needed anymore */
-       if (sess->task) {
-               task_destroy(sess->task);
-               sess->task = NULL;
-       }
-
+       task_destroy(sess->task);
+       sess->task = NULL;
        conn_set_owner(conn, sess, conn_session_free);
 
        return 0;