=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd-wait-for.c,v retrieving revision 1.15 retrieving revision 1.16 diff -c -r1.15 -r1.16 *** src/usr.bin/tmux/cmd-wait-for.c 2016/10/16 17:55:14 1.15 --- src/usr.bin/tmux/cmd-wait-for.c 2016/10/16 19:04:05 1.16 *************** *** 1,4 **** ! /* $OpenBSD: cmd-wait-for.c,v 1.15 2016/10/16 17:55:14 nicm Exp $ */ /* * Copyright (c) 2013 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: cmd-wait-for.c,v 1.16 2016/10/16 19:04:05 nicm Exp $ */ /* * Copyright (c) 2013 Nicholas Marriott *************** *** 28,34 **** * Block or wake a client on a named wait channel. */ ! static enum cmd_retval cmd_wait_for_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_wait_for_entry = { .name = "wait-for", --- 28,34 ---- * Block or wake a client on a named wait channel. */ ! static enum cmd_retval cmd_wait_for_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_wait_for_entry = { .name = "wait-for", *************** *** 42,48 **** }; struct wait_item { ! struct cmd_q *cmdq; TAILQ_ENTRY(wait_item) entry; }; --- 42,48 ---- }; struct wait_item { ! struct cmdq_item *item; TAILQ_ENTRY(wait_item) entry; }; *************** *** 68,84 **** return (strcmp(wc1->name, wc2->name)); } ! static enum cmd_retval cmd_wait_for_signal(struct cmd_q *, const char *, struct wait_channel *); ! static enum cmd_retval cmd_wait_for_wait(struct cmd_q *, const char *, struct wait_channel *); ! static enum cmd_retval cmd_wait_for_lock(struct cmd_q *, const char *, struct wait_channel *); ! static enum cmd_retval cmd_wait_for_unlock(struct cmd_q *, const char *, struct wait_channel *); static struct wait_channel *cmd_wait_for_add(const char *); ! static void cmd_wait_for_remove(struct wait_channel *wc); static struct wait_channel * cmd_wait_for_add(const char *name) --- 68,84 ---- return (strcmp(wc1->name, wc2->name)); } ! static enum cmd_retval cmd_wait_for_signal(struct cmdq_item *, const char *, struct wait_channel *); ! static enum cmd_retval cmd_wait_for_wait(struct cmdq_item *, const char *, struct wait_channel *); ! static enum cmd_retval cmd_wait_for_lock(struct cmdq_item *, const char *, struct wait_channel *); ! static enum cmd_retval cmd_wait_for_unlock(struct cmdq_item *, const char *, struct wait_channel *); static struct wait_channel *cmd_wait_for_add(const char *); ! static void cmd_wait_for_remove(struct wait_channel *); static struct wait_channel * cmd_wait_for_add(const char *name) *************** *** 118,124 **** } static enum cmd_retval ! cmd_wait_for_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; const char *name = args->argv[0]; --- 118,124 ---- } static enum cmd_retval ! cmd_wait_for_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; const char *name = args->argv[0]; *************** *** 128,143 **** wc = RB_FIND(wait_channels, &wait_channels, &wc0); if (args_has(args, 'S')) ! return (cmd_wait_for_signal(cmdq, name, wc)); if (args_has(args, 'L')) ! return (cmd_wait_for_lock(cmdq, name, wc)); if (args_has(args, 'U')) ! return (cmd_wait_for_unlock(cmdq, name, wc)); ! return (cmd_wait_for_wait(cmdq, name, wc)); } static enum cmd_retval ! cmd_wait_for_signal(__unused struct cmd_q *cmdq, const char *name, struct wait_channel *wc) { struct wait_item *wi, *wi1; --- 128,143 ---- wc = RB_FIND(wait_channels, &wait_channels, &wc0); if (args_has(args, 'S')) ! return (cmd_wait_for_signal(item, name, wc)); if (args_has(args, 'L')) ! return (cmd_wait_for_lock(item, name, wc)); if (args_has(args, 'U')) ! return (cmd_wait_for_unlock(item, name, wc)); ! return (cmd_wait_for_wait(item, name, wc)); } static enum cmd_retval ! cmd_wait_for_signal(__unused struct cmdq_item *item, const char *name, struct wait_channel *wc) { struct wait_item *wi, *wi1; *************** *** 153,159 **** log_debug("signal wait channel %s, with waiters", wc->name); TAILQ_FOREACH_SAFE(wi, &wc->waiters, entry, wi1) { ! wi->cmdq->flags &= ~CMD_Q_WAITING; TAILQ_REMOVE(&wc->waiters, wi, entry); free(wi); --- 153,159 ---- log_debug("signal wait channel %s, with waiters", wc->name); TAILQ_FOREACH_SAFE(wi, &wc->waiters, entry, wi1) { ! wi->item->flags &= ~CMDQ_WAITING; TAILQ_REMOVE(&wc->waiters, wi, entry); free(wi); *************** *** 164,176 **** } static enum cmd_retval ! cmd_wait_for_wait(struct cmd_q *cmdq, const char *name, struct wait_channel *wc) { ! struct client *c = cmdq->client; struct wait_item *wi; if (c == NULL || c->session != NULL) { ! cmdq_error(cmdq, "not able to wait"); return (CMD_RETURN_ERROR); } --- 164,177 ---- } static enum cmd_retval ! cmd_wait_for_wait(struct cmdq_item *item, const char *name, ! struct wait_channel *wc) { ! struct client *c = item->client; struct wait_item *wi; if (c == NULL || c->session != NULL) { ! cmdq_error(item, "not able to wait"); return (CMD_RETURN_ERROR); } *************** *** 185,203 **** log_debug("wait channel %s not woken (%p)", wc->name, c); wi = xcalloc(1, sizeof *wi); ! wi->cmdq = cmdq; TAILQ_INSERT_TAIL(&wc->waiters, wi, entry); return (CMD_RETURN_WAIT); } static enum cmd_retval ! cmd_wait_for_lock(struct cmd_q *cmdq, const char *name, struct wait_channel *wc) { struct wait_item *wi; ! if (cmdq->client == NULL || cmdq->client->session != NULL) { ! cmdq_error(cmdq, "not able to lock"); return (CMD_RETURN_ERROR); } --- 186,205 ---- log_debug("wait channel %s not woken (%p)", wc->name, c); wi = xcalloc(1, sizeof *wi); ! wi->item = item; TAILQ_INSERT_TAIL(&wc->waiters, wi, entry); return (CMD_RETURN_WAIT); } static enum cmd_retval ! cmd_wait_for_lock(struct cmdq_item *item, const char *name, ! struct wait_channel *wc) { struct wait_item *wi; ! if (item->client == NULL || item->client->session != NULL) { ! cmdq_error(item, "not able to lock"); return (CMD_RETURN_ERROR); } *************** *** 206,212 **** if (wc->locked) { wi = xcalloc(1, sizeof *wi); ! wi->cmdq = cmdq; TAILQ_INSERT_TAIL(&wc->lockers, wi, entry); return (CMD_RETURN_WAIT); } --- 208,214 ---- if (wc->locked) { wi = xcalloc(1, sizeof *wi); ! wi->item = item; TAILQ_INSERT_TAIL(&wc->lockers, wi, entry); return (CMD_RETURN_WAIT); } *************** *** 216,233 **** } static enum cmd_retval ! cmd_wait_for_unlock(struct cmd_q *cmdq, const char *name, struct wait_channel *wc) { struct wait_item *wi; if (wc == NULL || !wc->locked) { ! cmdq_error(cmdq, "channel %s not locked", name); return (CMD_RETURN_ERROR); } if ((wi = TAILQ_FIRST(&wc->lockers)) != NULL) { ! wi->cmdq->flags &= ~CMD_Q_WAITING; TAILQ_REMOVE(&wc->lockers, wi, entry); free(wi); } else { --- 218,235 ---- } static enum cmd_retval ! cmd_wait_for_unlock(struct cmdq_item *item, const char *name, struct wait_channel *wc) { struct wait_item *wi; if (wc == NULL || !wc->locked) { ! cmdq_error(item, "channel %s not locked", name); return (CMD_RETURN_ERROR); } if ((wi = TAILQ_FIRST(&wc->lockers)) != NULL) { ! wi->item->flags &= ~CMDQ_WAITING; TAILQ_REMOVE(&wc->lockers, wi, entry); free(wi); } else { *************** *** 246,258 **** RB_FOREACH_SAFE(wc, wait_channels, &wait_channels, wc1) { TAILQ_FOREACH_SAFE(wi, &wc->waiters, entry, wi1) { ! wi->cmdq->flags &= ~CMD_Q_WAITING; TAILQ_REMOVE(&wc->waiters, wi, entry); free(wi); } wc->woken = 1; TAILQ_FOREACH_SAFE(wi, &wc->lockers, entry, wi1) { ! wi->cmdq->flags &= ~CMD_Q_WAITING; TAILQ_REMOVE(&wc->lockers, wi, entry); free(wi); } --- 248,260 ---- RB_FOREACH_SAFE(wc, wait_channels, &wait_channels, wc1) { TAILQ_FOREACH_SAFE(wi, &wc->waiters, entry, wi1) { ! wi->item->flags &= ~CMDQ_WAITING; TAILQ_REMOVE(&wc->waiters, wi, entry); free(wi); } wc->woken = 1; TAILQ_FOREACH_SAFE(wi, &wc->lockers, entry, wi1) { ! wi->item->flags &= ~CMDQ_WAITING; TAILQ_REMOVE(&wc->lockers, wi, entry); free(wi); }