summaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
Diffstat (limited to 'input')
-rw-r--r--input/input.c67
-rw-r--r--input/input.h1
2 files changed, 42 insertions, 26 deletions
diff --git a/input/input.c b/input/input.c
index b5e66f6603..d9c95238d1 100644
--- a/input/input.c
+++ b/input/input.c
@@ -573,9 +573,6 @@ struct cmd_bind_section {
struct cmd_queue {
struct mp_cmd *first;
- struct mp_cmd *last;
- int num_cmds;
- int num_abort_cmds;
};
struct input_ctx {
@@ -707,32 +704,52 @@ static bool is_abort_cmd(int cmd_id)
return false;
}
+static int queue_count_cmds(struct cmd_queue *queue)
+{
+ int res = 0;
+ for (struct mp_cmd *cmd = queue->first; cmd; cmd = cmd->queue_next)
+ res++;
+ return res;
+}
+
+static bool queue_has_abort_cmds(struct cmd_queue *queue)
+{
+ for (struct mp_cmd *cmd = queue->first; cmd; cmd = cmd->queue_next) {
+ if (is_abort_cmd(cmd->id))
+ return true;
+ }
+ return false;
+}
+
+static void queue_remove(struct cmd_queue *queue, struct mp_cmd *cmd)
+{
+ struct mp_cmd **p_prev = &queue->first;
+ while (*p_prev != cmd) {
+ p_prev = &(*p_prev)->queue_next;
+ }
+ // if this fails, cmd was not in the queue
+ assert(*p_prev == cmd);
+ *p_prev = cmd->queue_next;
+}
+
static void queue_pop(struct cmd_queue *queue)
{
- assert(queue->num_cmds > 0);
- struct mp_cmd *cmd = queue->first;
- queue->first = cmd->queue_next;
- queue->num_cmds--;
- queue->num_abort_cmds -= is_abort_cmd(cmd->id);
+ queue_remove(queue, queue->first);
}
static void queue_add(struct cmd_queue *queue, struct mp_cmd *cmd,
bool at_head)
{
- if (!queue->num_cmds) {
- queue->first = cmd;
- queue->last = cmd;
- } else if (at_head) {
- queue->first->queue_prev = cmd;
+ if (at_head) {
cmd->queue_next = queue->first;
queue->first = cmd;
} else {
- queue->last->queue_next = cmd;
- cmd->queue_prev = queue->last;
- queue->last = cmd;
+ struct mp_cmd **p_prev = &queue->first;
+ while (*p_prev)
+ p_prev = &(*p_prev)->queue_next;
+ *p_prev = cmd;
+ cmd->queue_next = NULL;
}
- queue->num_cmds++;
- queue->num_abort_cmds += is_abort_cmd(cmd->id);
}
int mp_input_add_cmd_fd(struct input_ctx *ictx, int fd, int select,
@@ -1293,8 +1310,8 @@ void mp_input_feed_key(struct input_ctx *ictx, int code)
if (!cmd)
return;
struct cmd_queue *queue = &ictx->key_cmd_queue;
- if (queue->num_cmds >= ictx->key_fifo_size &&
- (!is_abort_cmd(cmd->id) || queue->num_abort_cmds))
+ if (queue_count_cmds(queue) >= ictx->key_fifo_size &&
+ (!is_abort_cmd(cmd->id) || queue_has_abort_cmds(queue)))
return;
queue_add(queue, cmd, false);
}
@@ -1445,14 +1462,14 @@ mp_cmd_t *mp_input_get_cmd(struct input_ctx *ictx, int time, int peek_only)
if (async_quit_request)
return mp_input_parse_cmd("quit 1");
- if (ictx->control_cmd_queue.num_cmds || ictx->key_cmd_queue.num_cmds)
+ if (ictx->control_cmd_queue.first || ictx->key_cmd_queue.first)
time = 0;
read_all_events(ictx, time);
struct mp_cmd *ret;
struct cmd_queue *queue = &ictx->control_cmd_queue;
- if (!queue->num_cmds)
+ if (!queue->first)
queue = &ictx->key_cmd_queue;
- if (!queue->num_cmds) {
+ if (!queue->first) {
ret = check_autorepeat(ictx);
if (!ret)
return NULL;
@@ -1883,8 +1900,8 @@ static int print_cmd_list(m_option_t *cfg)
int mp_input_check_interrupt(struct input_ctx *ictx, int time)
{
for (int i = 0; ; i++) {
- if (async_quit_request || ictx->key_cmd_queue.num_abort_cmds ||
- ictx->control_cmd_queue.num_abort_cmds) {
+ if (async_quit_request || queue_has_abort_cmds(&ictx->key_cmd_queue) ||
+ queue_has_abort_cmds(&ictx->control_cmd_queue)) {
mp_tmsg(MSGT_INPUT, MSGL_WARN, "Received command to move to "
"another file. Aborting current processing.\n");
return true;
diff --git a/input/input.h b/input/input.h
index 4058ce3d99..8d32a9907c 100644
--- a/input/input.h
+++ b/input/input.h
@@ -194,7 +194,6 @@ typedef struct mp_cmd {
int nargs;
struct mp_cmd_arg args[MP_CMD_MAX_ARGS];
int pausing;
- struct mp_cmd *queue_prev;
struct mp_cmd *queue_next;
} mp_cmd_t;