The branch, hooks has been updated via 2280c33172a548934266d5f368a04119ab5e5522 (commit) from bf3104efe6bcee2cda26f3efcc7c39e6b51773f5 (commit)
- Log ----------------------------------------------------------------- commit 2280c33172a548934266d5f368a04119ab5e5522 Author: Nicholas Marriott <nicholas.marri...@gmail.com> Commit: Nicholas Marriott <nicholas.marri...@gmail.com> Instead of storing hooks pointer, flag and recalculate them every time. --- cmd-if-shell.c | 2 +- cmd-queue.c | 71 ++++++++++++++++++++++++++++--------------------------- cmd-run-shell.c | 2 +- server-client.c | 2 +- tmux.h | 8 +++--- 5 files changed, 43 insertions(+), 42 deletions(-) diff --git a/cmd-if-shell.c b/cmd-if-shell.c index e067b96..bbfc5af 100644 --- a/cmd-if-shell.c +++ b/cmd-if-shell.c @@ -121,7 +121,7 @@ cmd_if_shell_callback(struct job *job) struct cmd_list *cmdlist; char *cause, *cmd; - if (cmdq->dead) + if (cmdq->flags & CMD_Q_DEAD) return; if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0) diff --git a/cmd-queue.c b/cmd-queue.c index 057e399..29b5bb6 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -36,7 +36,7 @@ cmdq_new(struct client *c) cmdq = xcalloc(1, sizeof *cmdq); cmdq->references = 1; - cmdq->dead = 0; + cmdq->flags = 0; cmdq->client = c; cmdq->client_exit = -1; @@ -52,8 +52,11 @@ cmdq_new(struct client *c) int cmdq_free(struct cmd_q *cmdq) { - if (--cmdq->references != 0) - return (cmdq->dead); + if (--cmdq->references != 0) { + if (cmdq->flags & CMD_Q_DEAD) + return (1); + return (0); + } cmdq_flush(cmdq); free(cmdq); @@ -169,12 +172,11 @@ cmdq_hooks_run(struct hooks *hooks, const char *prefix, struct cmd_q *cmdq) return (0); hooks_cmdq = cmdq_new(cmdq->client); + hooks_cmdq->flags |= CMD_Q_HOOKS; hooks_cmdq->emptyfn = cmdq_hooks_emptyfn; hooks_cmdq->data = cmdq; - hooks_cmdq->for_hooks = 1; - cmdq->references++; cmdq_run(hooks_cmdq, hook->cmdlist); @@ -214,6 +216,7 @@ cmdq_continue(struct cmd_q *cmdq) { struct cmd_q_item *next; struct cmd *cmd; + struct hooks *hooks; enum cmd_retval retval; int empty, flags; char s[1024]; @@ -229,7 +232,7 @@ cmdq_continue(struct cmd_q *cmdq) * CMD_RETURN_WAIT), move onto the next command; otherwise, leave the * state of the queue as it is. */ - if (cmdq->hooks == NULL) { + if (!(cmdq->flags & CMD_Q_REENTRY)) { if (cmdq->item == NULL) { cmdq->item = TAILQ_FIRST(&cmdq->queue); cmdq->cmd = TAILQ_FIRST(&cmdq->item->cmdlist->list); @@ -250,45 +253,43 @@ cmdq_continue(struct cmd_q *cmdq) flags = !!(cmd->flags & CMD_CONTROL); - /* - * If we've come back here after running hooks, skip - * the before hooks. - */ - if (cmdq->hooks != NULL) - goto skip; - - cmdq_guard(cmdq, "begin", flags); - - if (cmd_prepare_state(cmd, cmdq) != 0) { - cmdq_guard(cmdq, "error", flags); - break; - } - // XXX hooks changed/session destroyed? - if (cmdq->state.tflag.s != NULL) - cmdq->hooks = &cmdq->state.tflag.s->hooks; - else if (cmdq->state.sflag.s != NULL) - cmdq->hooks = &cmdq->state.sflag.s->hooks; - else - cmdq->hooks = &global_hooks; - - if (!cmdq->for_hooks && cmdq_hooks_run(cmdq->hooks, - "before", cmdq)) - goto out; + if (!(cmdq->flags & CMD_Q_REENTRY)) + cmdq_guard(cmdq, "begin", flags); + + if (!(cmdq->flags & CMD_Q_HOOKS)) { + if (cmd_prepare_state(cmd, cmdq) != 0) { + cmdq_guard(cmdq, "error", flags); + cmdq->flags &= ~CMD_Q_REENTRY; + break; + } + if (cmdq->state.tflag.s != NULL) + hooks = &cmdq->state.tflag.s->hooks; + else if (cmdq->state.sflag.s != NULL) + hooks = &cmdq->state.sflag.s->hooks; + else + hooks = &global_hooks; + + if (!(cmdq->flags & CMD_Q_REENTRY) && + cmdq_hooks_run(hooks, "before", cmdq)) { + cmdq->flags |= CMD_Q_REENTRY; + goto out; + } + } else + hooks = NULL; + cmdq->flags &= ~CMD_Q_REENTRY; - skip: if (cmd_prepare_state(cmd, cmdq) != 0) retval = CMD_RETURN_ERROR; else retval = cmd->entry->exec(cmd, cmdq); if (retval == CMD_RETURN_ERROR) { cmdq_guard(cmdq, "error", flags); - cmdq->hooks = NULL; break; } - if (!cmdq->for_hooks && cmdq_hooks_run(cmdq->hooks, - "after", cmdq)) + + if (hooks != NULL && + cmdq_hooks_run(hooks, "after", cmdq)) retval = CMD_RETURN_WAIT; - cmdq->hooks = NULL; cmdq_guard(cmdq, "end", flags); diff --git a/cmd-run-shell.c b/cmd-run-shell.c index ed1ec1d..3b5348f 100644 --- a/cmd-run-shell.c +++ b/cmd-run-shell.c @@ -115,7 +115,7 @@ cmd_run_shell_callback(struct job *job) int retcode; u_int lines; - if (cmdq->dead) + if (cmdq->flags & CMD_Q_DEAD) return; cmd = cdata->cmd; diff --git a/server-client.c b/server-client.c index 18eea9d..0c3e302 100644 --- a/server-client.c +++ b/server-client.c @@ -185,7 +185,7 @@ server_client_lost(struct client *c) free(c->prompt_string); free(c->prompt_buffer); - c->cmdq->dead = 1; + c->cmdq->flags |= CMD_Q_DEAD; cmdq_free(c->cmdq); c->cmdq = NULL; diff --git a/tmux.h b/tmux.h index de594c2..0d37876 100644 --- a/tmux.h +++ b/tmux.h @@ -1416,7 +1416,10 @@ TAILQ_HEAD(cmd_q_items, cmd_q_item); /* Command queue. */ struct cmd_q { int references; - int dead; + int flags; +#define CMD_Q_DEAD 0x1 +#define CMD_Q_REENTRY 0x2 +#define CMD_Q_HOOKS 0x4 struct client *client; int client_exit; @@ -1434,9 +1437,6 @@ struct cmd_q { void *data; TAILQ_ENTRY(cmd_q) waitentry; - - int for_hooks; - struct hooks *hooks; }; /* Command definition. */ ----------------------------------------------------------------------- Summary of changes: cmd-if-shell.c | 2 +- cmd-queue.c | 71 ++++++++++++++++++++++++++++--------------------------- cmd-run-shell.c | 2 +- server-client.c | 2 +- tmux.h | 8 +++--- 5 files changed, 43 insertions(+), 42 deletions(-) hooks/post-receive -- tmux ------------------------------------------------------------------------------ Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ tmux-cvs mailing list tmux-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-cvs