The branch, hooks has been updated
via 094848a36d3af498e28e6f00a03135ba419f61a4 (commit)
via 5b1b1d89236cab188890964ddf0e3c8c376dd940 (commit)
via 593de9280e36ed57f24091c91d1760eaecbaaf7b (commit)
via 90268eb52b3e5e9dd4c40b066d94afa4f3eb9dd7 (commit)
from 2280c33172a548934266d5f368a04119ab5e5522 (commit)
- Log -----------------------------------------------------------------
commit 094848a36d3af498e28e6f00a03135ba419f61a4
Author: Nicholas Marriott <[email protected]>
Commit: Nicholas Marriott <[email protected]>
Add a helper for each inner loop.
---
cmd-queue.c | 124 +++++++++++++++++++++++++++++++---------------------------
1 files changed, 66 insertions(+), 58 deletions(-)
diff --git a/cmd-queue.c b/cmd-queue.c
index b81143e..3af6b85 100644
--- a/cmd-queue.c
+++ b/cmd-queue.c
@@ -25,8 +25,9 @@
#include "tmux.h"
-int cmdq_hooks_run(struct hooks *, const char *, struct cmd_q *);
-void cmdq_hooks_emptyfn(struct cmd_q *);
+int cmdq_hooks_run(struct hooks *, const char *, struct cmd_q *);
+void cmdq_hooks_emptyfn(struct cmd_q *);
+enum cmd_retval cmdq_continue_one(struct cmd_q *);
/* Create new command queue. */
struct cmd_q *
@@ -216,20 +217,76 @@ cmdq_append(struct cmd_q *cmdq, struct cmd_list *cmdlist)
cmdlist->references++;
}
+/* Process one command. */
+enum cmd_retval
+cmdq_continue_one(struct cmd_q *cmdq)
+{
+ struct cmd *cmd = cmdq->cmd;
+ struct hooks *hooks;
+ enum cmd_retval retval;
+ char s[1024];
+ int flags = !!(cmd->flags & CMD_CONTROL);
+
+ cmd_print(cmd, s, sizeof s);
+ log_debug("cmdq %p: %s", cmdq, s);
+
+ cmdq->time = time(NULL);
+ cmdq->number++;
+
+ if (~cmdq->flags & CMD_Q_REENTRY)
+ cmdq_guard(cmdq, "begin", flags);
+
+ if (~cmdq->flags & CMD_Q_HOOKS) {
+ if (cmd_prepare_state(cmd, cmdq) != 0)
+ goto error;
+ 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->flags |= CMD_Q_REENTRY;
+ if (cmdq_hooks_run(hooks, "before", cmdq))
+ return (CMD_RETURN_WAIT);
+ }
+ } else
+ hooks = NULL;
+ cmdq->flags &= ~CMD_Q_REENTRY;
+
+ if (cmd_prepare_state(cmd, cmdq) != 0)
+ goto error;
+ retval = cmd->entry->exec(cmd, cmdq);
+ if (retval == CMD_RETURN_ERROR)
+ goto error;
+
+ if (hooks != NULL && cmdq_hooks_run(hooks, "after", cmdq))
+ retval = CMD_RETURN_WAIT;
+ cmdq_guard(cmdq, "end", flags);
+
+ return (retval);
+
+error:
+ cmdq_guard(cmdq, "error", flags);
+
+ cmdq->flags &= ~CMD_Q_REENTRY;
+ return (CMD_RETURN_ERROR);
+}
+
/* Continue processing command queue. Returns 1 if finishes empty. */
int
cmdq_continue(struct cmd_q *cmdq)
{
+ struct client *c = cmdq->client;
struct cmd_q_item *next;
- struct cmd *cmd;
- struct hooks *hooks;
enum cmd_retval retval;
- int empty, flags;
- char s[1024];
+ int empty;
notify_disable();
- log_debug("continuing cmdq %p: flags=%#x", cmdq, cmdq->flags);
+ log_debug("continuing cmdq %p: flags=%#x, client=%d", cmdq, cmdq->flags,
+ c != NULL ? c->ibuf.fd : -1);
empty = TAILQ_EMPTY(&cmdq->queue);
if (empty)
@@ -250,64 +307,15 @@ cmdq_continue(struct cmd_q *cmdq)
do {
while (cmdq->cmd != NULL) {
- cmd = cmdq->cmd;
-
- cmd_print(cmd, s, sizeof s);
- log_debug("cmdq %p: %s (client %d)", cmdq, s,
- cmdq->client != NULL ? cmdq->client->ibuf.fd : -1);
-
- cmdq->time = time(NULL);
- cmdq->number++;
-
- flags = !!(cmd->flags & CMD_CONTROL);
-
- 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->flags |= CMD_Q_REENTRY;
- if (cmdq_hooks_run(hooks, "before",
cmdq))
- goto out;
- }
- } else
- hooks = NULL;
- cmdq->flags &= ~CMD_Q_REENTRY;
-
- 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);
+ retval = cmdq_continue_one(cmdq);
+ if (retval == CMD_RETURN_ERROR)
break;
- }
-
- if (hooks != NULL &&
- cmdq_hooks_run(hooks, "after", cmdq))
- retval = CMD_RETURN_WAIT;
-
- cmdq_guard(cmdq, "end", flags);
-
if (retval == CMD_RETURN_WAIT)
goto out;
if (retval == CMD_RETURN_STOP) {
cmdq_flush(cmdq);
goto empty;
}
-
cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry);
}
next = TAILQ_NEXT(cmdq->item, qentry);
commit 5b1b1d89236cab188890964ddf0e3c8c376dd940
Author: Nicholas Marriott <[email protected]>
Commit: Nicholas Marriott <[email protected]>
Notify needs to reference count now.
---
notify.c | 16 ++++++++++------
1 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/notify.c b/notify.c
index 47945ae..49c3f8b 100644
--- a/notify.c
+++ b/notify.c
@@ -43,7 +43,7 @@ struct notify_entry {
TAILQ_ENTRY(notify_entry) entry;
};
TAILQ_HEAD(, notify_entry) notify_queue = TAILQ_HEAD_INITIALIZER(notify_queue);
-int notify_enabled = 1;
+int notify_disabled;
void notify_drain(void);
void notify_add(enum notify_type, struct client *, struct session *,
@@ -52,14 +52,18 @@ void notify_add(enum notify_type, struct client *,
struct session *,
void
notify_enable(void)
{
- notify_enabled = 1;
- notify_drain();
+ if (notify_disabled == 0)
+ return;
+ if (--notify_disabled == 0)
+ notify_drain();
+ log_debug("notify enabled, now %d", notify_disabled);
}
void
notify_disable(void)
{
- notify_enabled = 0;
+ notify_disabled++;
+ log_debug("notify disabled, now %d", notify_disabled);
}
void
@@ -88,7 +92,7 @@ notify_drain(void)
{
struct notify_entry *ne, *ne1;
- if (!notify_enabled)
+ if (notify_disabled)
return;
TAILQ_FOREACH_SAFE(ne, ¬ify_queue, entry, ne1) {
@@ -141,7 +145,7 @@ notify_input(struct window_pane *wp, struct evbuffer *input)
* notify_input() is not queued and only does anything when
* notifications are enabled.
*/
- if (!notify_enabled)
+ if (notify_disabled)
return;
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
commit 593de9280e36ed57f24091c91d1760eaecbaaf7b
Author: Nicholas Marriott <[email protected]>
Commit: Nicholas Marriott <[email protected]>
The emptyfn could be called immediately before cmd_hooks_run returns, so
set it
before calling.
---
cmd-queue.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/cmd-queue.c b/cmd-queue.c
index 7b76469..b81143e 100644
--- a/cmd-queue.c
+++ b/cmd-queue.c
@@ -277,10 +277,10 @@ cmdq_continue(struct cmd_q *cmdq)
else
hooks = &global_hooks;
- if (!(cmdq->flags & CMD_Q_REENTRY) &&
- cmdq_hooks_run(hooks, "before", cmdq)) {
+ if (!(cmdq->flags & CMD_Q_REENTRY)) {
cmdq->flags |= CMD_Q_REENTRY;
- goto out;
+ if (cmdq_hooks_run(hooks, "before",
cmdq))
+ goto out;
}
} else
hooks = NULL;
commit 90268eb52b3e5e9dd4c40b066d94afa4f3eb9dd7
Author: Nicholas Marriott <[email protected]>
Commit: Nicholas Marriott <[email protected]>
Add some logging.
---
cmd-queue.c | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/cmd-queue.c b/cmd-queue.c
index 29b5bb6..7b76469 100644
--- a/cmd-queue.c
+++ b/cmd-queue.c
@@ -166,10 +166,11 @@ cmdq_hooks_run(struct hooks *hooks, const char *prefix,
struct cmd_q *cmdq)
xasprintf(&s, "%s-%s", prefix, cmd->entry->name);
hook = hooks_find(hooks, s);
- free(s);
- if (hook == NULL)
+ if (hook == NULL) {
+ free(s);
return (0);
+ }
hooks_cmdq = cmdq_new(cmdq->client);
hooks_cmdq->flags |= CMD_Q_HOOKS;
@@ -177,6 +178,9 @@ cmdq_hooks_run(struct hooks *hooks, const char *prefix,
struct cmd_q *cmdq)
hooks_cmdq->emptyfn = cmdq_hooks_emptyfn;
hooks_cmdq->data = cmdq;
+ log_debug("entering hooks cmdq %p for %s", hooks_cmdq, s);
+ free(s);
+
cmdq->references++;
cmdq_run(hooks_cmdq, hook->cmdlist);
@@ -189,6 +193,8 @@ cmdq_hooks_emptyfn(struct cmd_q *hooks_cmdq)
{
struct cmd_q *cmdq = hooks_cmdq->data;
+ log_debug("exiting hooks cmdq %p", hooks_cmdq);
+
if (hooks_cmdq->client_exit >= 0)
cmdq->client_exit = hooks_cmdq->client_exit;
@@ -223,6 +229,8 @@ cmdq_continue(struct cmd_q *cmdq)
notify_disable();
+ log_debug("continuing cmdq %p: flags=%#x", cmdq, cmdq->flags);
+
empty = TAILQ_EMPTY(&cmdq->queue);
if (empty)
goto empty;
-----------------------------------------------------------------------
Summary of changes:
cmd-queue.c | 134 +++++++++++++++++++++++++++++++++--------------------------
notify.c | 16 ++++---
2 files changed, 85 insertions(+), 65 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
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-cvs