I think this could be much simpler - to give you an idea, this is the
kind of thing I had in mind, but instead of just one saved cmdq having a
tree of wait channels each with a list of cmdq attached.
Locking can be implemented very similarly and perhaps even using the
same data structures as needed for waiting.
diff --git a/Makefile.am b/Makefile.am
index 5caa498..19220d8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -135,6 +135,7 @@ dist_tmux_SOURCES = \
cmd-switch-client.c \
cmd-unbind-key.c \
cmd-unlink-window.c \
+ cmd-wait-for.c \
cmd.c \
colour.c \
control.c \
diff --git a/cmd-wait-for.c b/cmd-wait-for.c
new file mode 100644
index 0000000..7b11c8d
--- /dev/null
+++ b/cmd-wait-for.c
@@ -0,0 +1,69 @@
+/* $Id$ */
+
+/*
+ * Copyright (c) 2013 Nicholas Marriott <[email protected]>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include "tmux.h"
+
+/*
+ * Block client until woken.
+ */
+
+struct cmd_q *xxx_wait_cmdq; /* XXX tree */
+
+enum cmd_retval cmd_wait_for_exec(struct cmd *, struct cmd_q *);
+
+const struct cmd_entry cmd_wait_for_entry = {
+ "wait-for", "wait",
+ "S", 1, 1,
+ "[-S] channel",
+ 0,
+ NULL,
+ NULL,
+ cmd_wait_for_exec
+};
+
+enum cmd_retval
+cmd_wait_for_exec(struct cmd *self, struct cmd_q *cmdq)
+{
+ struct args *args = self->args;
+
+ if (args_has(args, 'S')) {
+ if (xxx_wait_cmdq == NULL) {
+ cmdq_error(cmdq, "no waiting clients");
+ return (CMD_RETURN_ERROR);
+ }
+ if (!cmdq_free(xxx_wait_cmdq))
+ cmdq_continue(xxx_wait_cmdq);
+ xxx_wait_cmdq = NULL;
+ return (CMD_RETURN_NORMAL);
+ }
+
+ if (cmdq->client == NULL || cmdq->client->session != NULL) {
+ cmdq_error(cmdq, "not able to wait");
+ return (CMD_RETURN_ERROR);
+ }
+
+ if (xxx_wait_cmdq != NULL) {
+ cmdq_error(cmdq, "client already waiting");
+ return (CMD_RETURN_ERROR);
+ }
+ cmdq->references++;
+ xxx_wait_cmdq = cmdq;
+ return (CMD_RETURN_WAIT);
+}
diff --git a/cmd.c b/cmd.c
index 0d6a85f..20484ed 100644
--- a/cmd.c
+++ b/cmd.c
@@ -112,6 +112,7 @@ const struct cmd_entry *cmd_table[] = {
&cmd_switch_client_entry,
&cmd_unbind_key_entry,
&cmd_unlink_window_entry,
+ &cmd_wait_for_entry,
NULL
};
diff --git a/tmux.h b/tmux.h
index c1ad662..95dd97c 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1835,6 +1835,7 @@ extern const struct cmd_entry cmd_switch_client_entry;
extern const struct cmd_entry cmd_unbind_key_entry;
extern const struct cmd_entry cmd_unlink_window_entry;
extern const struct cmd_entry cmd_up_pane_entry;
+extern const struct cmd_entry cmd_wait_for_entry;
/* cmd-attach-session.c */
enum cmd_retval cmd_attach_session(struct cmd_q *, const char*, int,
int);
On Tue, Mar 05, 2013 at 09:47:45AM -0300, Thiago Padilha wrote:
> Any chance this patch will be accepted?
> I still need to tweak a few things:
> - Detect when a waiting pane exits and remove it from the queue/monitor
> - Move the queue shifting to the event loop
> - Handle SIGINT in the tmux client(Not sure **about this one)
> I didn't manage to implement those myself, so I was hoping for some
> feedback/help
> If you guys want I can recreate the patch against the current master.
>
> On Sun, Mar 3, 2013 at 7:53 PM, Thiago Padilha <[1][email protected]>
> wrote:
>
> Here's a nice integration between vim and tmux for any zsh users that
> want to give this patch a
> try:**[2]https://gist.github.com/tarruda/5051527
> Combined with the new zoom patch, you can get a nice 'toggle top
> terminal' experience.
>
> On Tue, Feb 26, 2013 at 11:37 AM, Thiago Padilha
> <[3][email protected]> wrote:
>
> Here is TAILQ version of the patch, along with the event loop
> diff(which
> randomly crashes the server for me again)
> ---
> **Makefile.am ** ** ** ** | ** 2 +
> **cmd-monitor.c ** ** ** | 110 ++++++++++++++++++++++++++++
> **cmd.c ** ** ** ** ** ** ** | ** 1 +
> **examples/monitor.sh | 120 ++++++++++++++++++++++++++++++
> **monitor.c ** ** ** ** ** | 206
> ++++++++++++++++++++++++++++++++++++++++++++++++++++
> **tmux.c ** ** ** ** ** ** **| ** 3 +
> **tmux.h ** ** ** ** ** ** **| **71 ++++++++++++++++++
> **7 files changed, 513 insertions(+)
> **create mode 100644 cmd-monitor.c
> **create mode 100755 examples/monitor.sh
> **create mode 100644 monitor.c
>
> References
>
> Visible links
> 1. mailto:[email protected]
> 2. https://gist.github.com/tarruda/5051527
> 3. mailto:[email protected]
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_feb
> _______________________________________________
> tmux-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/tmux-users
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
tmux-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-users