From: Willy Tarreau Date: Fri, 28 Nov 2014 11:08:47 +0000 (+0100) Subject: MEDIUM: stream-int: use si_task() to retrieve the task from the stream int X-Git-Tag: v1.6-dev1~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=07373b86603c94f2ed27b60d1c745f3fbe6218ac;p=thirdparty%2Fhaproxy.git MEDIUM: stream-int: use si_task() to retrieve the task from the stream int We go back to the session to get the owner. Here again it's very easy and is just a matter of relative offsets. Since the owner always exists and always points to the session's task, we can remove some unneeded tests. --- diff --git a/include/proto/stream_interface.h b/include/proto/stream_interface.h index 4d5abcf2af..584abcf6d5 100644 --- a/include/proto/stream_interface.h +++ b/include/proto/stream_interface.h @@ -73,6 +73,15 @@ static inline struct session *si_sess(struct stream_interface *si) return LIST_ELEM(si, struct session *, si[0]); } +/* returns the task associated to this stream interface */ +static inline struct task *si_task(struct stream_interface *si) +{ + if (si->flags & SI_FL_ISBACK) + return LIST_ELEM(si, struct session *, si[1])->task; + else + return LIST_ELEM(si, struct session *, si[0])->task; +} + /* Initializes all required fields for a new appctx. Note that it does the * minimum acceptable initialization for an appctx. This means only the * 3 integer states st0, st1, st2 are zeroed. diff --git a/src/session.c b/src/session.c index f271e41261..7f726d4293 100644 --- a/src/session.c +++ b/src/session.c @@ -1750,10 +1750,8 @@ struct task *process_session(struct task *t) rpf_last = s->res.flags & ~CF_MASK_ANALYSER; /* we don't want the stream interface functions to recursively wake us up */ - if (s->req.prod->owner == t) - s->req.prod->flags |= SI_FL_DONT_WAKE; - if (s->req.cons->owner == t) - s->req.cons->flags |= SI_FL_DONT_WAKE; + s->req.prod->flags |= SI_FL_DONT_WAKE; + s->req.cons->flags |= SI_FL_DONT_WAKE; /* 1a: Check for low level timeouts if needed. We just set a flag on * stream interfaces when their timeouts have expired. diff --git a/src/stream_interface.c b/src/stream_interface.c index 8ccf78e600..bfc67c24c0 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -212,8 +212,8 @@ static void stream_int_update_embedded(struct stream_interface *si) ((si_oc(si)->flags & CF_WAKE_WRITE) && (si_oc(si)->prod->state != SI_ST_EST || (channel_is_empty(si_oc(si)) && !si_oc(si)->to_forward)))))) { - if (!(si->flags & SI_FL_DONT_WAKE) && si->owner) - task_wakeup(si->owner, TASK_WOKEN_IO); + if (!(si->flags & SI_FL_DONT_WAKE)) + task_wakeup(si_task(si), TASK_WOKEN_IO); } if (si_ic(si)->flags & CF_READ_ACTIVITY) si_ic(si)->flags &= ~CF_READ_DONTWAIT; @@ -250,8 +250,8 @@ static void stream_int_shutr(struct stream_interface *si) } /* note that if the task exists, it must unregister itself once it runs */ - if (!(si->flags & SI_FL_DONT_WAKE) && si->owner) - task_wakeup(si->owner, TASK_WOKEN_IO); + if (!(si->flags & SI_FL_DONT_WAKE)) + task_wakeup(si_task(si), TASK_WOKEN_IO); } /* @@ -299,8 +299,8 @@ static void stream_int_shutw(struct stream_interface *si) } /* note that if the task exists, it must unregister itself once it runs */ - if (!(si->flags & SI_FL_DONT_WAKE) && si->owner) - task_wakeup(si->owner, TASK_WOKEN_IO); + if (!(si->flags & SI_FL_DONT_WAKE)) + task_wakeup(si_task(si), TASK_WOKEN_IO); } /* default chk_rcv function for scheduled tasks */ @@ -322,8 +322,8 @@ static void stream_int_chk_rcv(struct stream_interface *si) else { /* (re)start reading */ si->flags &= ~SI_FL_WAIT_ROOM; - if (!(si->flags & SI_FL_DONT_WAKE) && si->owner) - task_wakeup(si->owner, TASK_WOKEN_IO); + if (!(si->flags & SI_FL_DONT_WAKE)) + task_wakeup(si_task(si), TASK_WOKEN_IO); } } @@ -350,8 +350,8 @@ static void stream_int_chk_snd(struct stream_interface *si) if (!tick_isset(ob->wex)) ob->wex = tick_add_ifset(now_ms, ob->wto); - if (!(si->flags & SI_FL_DONT_WAKE) && si->owner) - task_wakeup(si->owner, TASK_WOKEN_IO); + if (!(si->flags & SI_FL_DONT_WAKE)) + task_wakeup(si_task(si), TASK_WOKEN_IO); } /* Register an applet to handle a stream_interface as part of the @@ -366,7 +366,7 @@ struct appctx *stream_int_register_handler(struct stream_interface *si, struct s { struct appctx *appctx; - DPRINTF(stderr, "registering handler %p for si %p (was %p)\n", app, si, si->owner); + DPRINTF(stderr, "registering handler %p for si %p (was %p)\n", app, si, si_task(si)); appctx = si_alloc_appctx(si); if (!appctx) @@ -639,7 +639,7 @@ static int si_conn_wake_cb(struct connection *conn) ((si_oc(si)->flags & CF_WAKE_WRITE) && (si_oc(si)->prod->state != SI_ST_EST || (channel_is_empty(si_oc(si)) && !si_oc(si)->to_forward)))))) { - task_wakeup(si->owner, TASK_WOKEN_IO); + task_wakeup(si_task(si), TASK_WOKEN_IO); } if (si_ic(si)->flags & CF_READ_ACTIVITY) si_ic(si)->flags &= ~CF_READ_DONTWAIT; @@ -1058,8 +1058,8 @@ static void stream_int_chk_snd_conn(struct stream_interface *si) ((channel_is_empty(si_oc(si)) && !ob->to_forward) || si->state != SI_ST_EST)))) { out_wakeup: - if (!(si->flags & SI_FL_DONT_WAKE) && si->owner) - task_wakeup(si->owner, TASK_WOKEN_IO); + if (!(si->flags & SI_FL_DONT_WAKE)) + task_wakeup(si_task(si), TASK_WOKEN_IO); } /* commit possible polling changes */