From 84f94abb5e8edc7e8080e09751573d8c97faf8bd Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sat, 22 Jul 2023 12:06:44 +1000 Subject: [PATCH] Change times_up() to use pane_too_long() on root. Also check for debugger in all pane_too_long() calls. Signed-off-by: NeilBrown --- DOC/TODO.md | 2 +- core-keymap.c | 6 +++--- core-misc.c | 33 --------------------------------- core-pane.c | 37 +++++++++++++++++++++++++++++++++++++ core-pane.h | 46 +++++++++++++++++++++++----------------------- lib-input.c | 12 ++++++------ misc.h | 9 +-------- 7 files changed, 71 insertions(+), 74 deletions(-) diff --git a/DOC/TODO.md b/DOC/TODO.md index de3a3a71..967c25af 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -32,7 +32,7 @@ the file. messages. - [X] menu for address completions in email-compose -- [ ] Change times_up() to use pane_too_long() +- [X] Change times_up() to use pane_too_long() - [ ] change :A-x menu to use doc-list - add sorting - [ ] Change render-lines to handle centring and right-align in flush_line - [ ] Teach render-lines to pad spaces to left/right align text diff --git a/core-keymap.c b/core-keymap.c index c0e22746..c2b6e492 100644 --- a/core-keymap.c +++ b/core-keymap.c @@ -436,14 +436,14 @@ static int do_comm_call(struct command *comm safe, struct backtrace bt; int ret; - if (edlib_timing == 1) + if (times_up_fast(ci->home)) return Efail; if (backtrace_depth > 100) { backtrace_depth = 0; LOG("Recursion limit of 100 reached"); LOG_BT(); backtrace_depth = 100; - edlib_timing = 1; + pane_root(ci->home)->timestamp = 1; return Efail; } bt.comm = comm; @@ -537,7 +537,7 @@ int key_handle(const struct cmd_info *ci safe) if (ci->mark2 && !mark_valid(ci->mark2)) return Einval; - if (times_up()) + if (times_up(ci->home)) return Efail; time_start_key(ci->key); if ((void*) ci->comm) { diff --git a/core-misc.c b/core-misc.c index 891157f3..4ad03f25 100644 --- a/core-misc.c +++ b/core-misc.c @@ -533,8 +533,6 @@ int utf8_round_len(const char *text safe, int len) return len; } -time_t edlib_timing = 0; - static int _debugger_present = -1; static void _sigtrap_handler(int signum) { @@ -551,34 +549,3 @@ bool debugger_is_present(void) } return _debugger_present; } - -int times_up(void) -{ - time_t now; - if (edlib_timing == 0) - return 0; - if (edlib_timing == 1) - return 1; - now = time(NULL); - if (edlib_timing + 15 < now) { - /* If running under gdb, then I was probaly delayed - * by single-stepping, so don't through an error - */ - if (debugger_is_present()) - return 0; - edlib_timing = 1; - return 1; - } - return 0; -} - -void time_starts(void) -{ - if (_debugger_present != 1) - edlib_timing = time(NULL); -} - -void time_ends(void) -{ - edlib_timing = 0; -} diff --git a/core-pane.c b/core-pane.c index e3042093..0ad66dc5 100644 --- a/core-pane.c +++ b/core-pane.c @@ -1161,3 +1161,40 @@ struct xy pane_scale(struct pane *p safe) xy.y = scale * mh / 10; return xy; } + +static inline unsigned int ts_to_ms(struct timespec *ts safe) +{ + return ts->tv_nsec / 1000 / 1000 + ts->tv_sec * 1000; +} + +bool pane_too_long(struct pane *p safe, unsigned int msec) +{ + struct timespec ts; + unsigned int duration; + + if (p->timestamp == 0) + return False; + if (p->timestamp == 1) + return True; + clock_gettime(CLOCK_MONOTONIC_COARSE, &ts); + duration = ts_to_ms(&ts) - p->timestamp; + if (msec < 100) + msec = 100; + if (duration <= msec) + return False; + /* If running under gdb, then I was probaly delayed + * by single-stepping, so don't through an error + */ + p->timestamp = ! debugger_is_present(); + return p->timestamp; +} + +void pane_set_time(struct pane *p safe) +{ + struct timespec ts; + + clock_gettime(CLOCK_MONOTONIC_COARSE, &ts); + p->timestamp = ts_to_ms(&ts); + if (p->timestamp <= 1) + p->timestamp = 2; +} diff --git a/core-pane.h b/core-pane.h index 9c1fa6fc..1e146047 100644 --- a/core-pane.h +++ b/core-pane.h @@ -16,7 +16,9 @@ struct pane { int refs; /* timestamp is low bits of time in milliseconds when some * command started. This makes it easy to check when we - * have done too much work + * have done too much work. + * 0 means nothing is running. + * 1 means time is exhausted */ unsigned int timestamp; @@ -38,38 +40,36 @@ struct pane { }; }; -static inline unsigned int ts_to_ms(struct timespec *ts safe) +bool pane_too_long(struct pane *p safe, unsigned int msec); +void pane_set_time(struct pane *p safe); +static inline void pane_end_time(struct pane *p safe) { - return ts->tv_nsec / 1000 / 1000 + ts->tv_sec * 1000; + p->timestamp = 0; } -extern bool debugger_is_present(void); - -static inline bool pane_too_long(struct pane *p safe, unsigned int msec) +static inline struct pane * safe pane_root(struct pane *p safe) { - struct timespec ts; - unsigned int duration; + return p->root; +} - clock_gettime(CLOCK_MONOTONIC_COARSE, &ts); - duration = ts_to_ms(&ts) - p->timestamp; - if (msec < 100) - msec = 100; - if (duration <= msec) - return False; - return ! debugger_is_present(); +static inline void time_starts(struct pane *p safe) +{ + pane_set_time(pane_root(p)); } -static inline void pane_set_time(struct pane *p safe) +static inline void time_ends(struct pane *p safe) { - struct timespec ts; + pane_end_time(pane_root(p)); +} - clock_gettime(CLOCK_MONOTONIC_COARSE, &ts); - p->timestamp = ts_to_ms(&ts); +static inline bool times_up(struct pane *p safe) +{ + return pane_too_long(pane_root(p), 15000); } -static inline struct pane * safe pane_root(struct pane *p safe) +static inline bool times_up_fast(struct pane *p safe) { - return p->root; + return pane_root(p)->timestamp == 1; } static inline struct pane *safe pane_leaf(struct pane *p safe) @@ -129,7 +129,7 @@ static inline int do_call_val(enum target_type type, struct pane *home, case TYPE_pane: if (!home->handle || (home->damaged & DAMAGED_DEAD)) return Efail; - if (times_up_fast()) + if (times_up_fast(focus)) return Efail; if (home) ci.home = home; @@ -137,7 +137,7 @@ static inline int do_call_val(enum target_type type, struct pane *home, ret = ci.comm->func(&ci); break; case TYPE_comm: - if (times_up_fast()) + if (times_up_fast(focus)) return Efail; if (home) ci.home = home; diff --git a/lib-input.c b/lib-input.c index eae71755..69e6a7eb 100644 --- a/lib-input.c +++ b/lib-input.c @@ -214,13 +214,13 @@ DEF_CMD(keystroke) m = im->point; key = strconcat(ci->home, "K", mode, ci->str); - time_starts(); + time_starts(ci->home); ret = call(key, p, num, m, NULL, num2); if (ret == 0 && (alt = map_key(ci->str)) != NULL) { key = strconcat(ci->home, "K", mode, alt); ret = call(key, p, num, m, NULL, num2); } - time_ends(); + time_ends(ci->home); if (ret < 0) call("Message:default", ci->focus, 0, NULL, "** Command Failed **"); @@ -351,10 +351,10 @@ DEF_CMD(mouse_event) if (!ms) { int ret; key = strconcat(ci->home, "M", mode, ci->str); - time_starts(); + time_starts(ci->home); ret = call(key, focus, num, NULL, NULL, ex, NULL, NULL, xy.x, xy.y); - time_ends(); + time_ends(ci->home); return ret; } if (press) { @@ -395,10 +395,10 @@ DEF_CMD(mouse_event) n[1] = 0; key = strconcat(ci->home, "M", mode, ms->mod, ":", mult, cmd, n); - time_starts(); + time_starts(ci->home); ret = call(key, focus, num, NULL, NULL, ex, NULL, NULL, xy.x, xy.y); - time_ends(); + time_ends(ci->home); if (ret > 0) { /* If this is 'press', then don't want * click_on_up. If this is release, it diff --git a/misc.h b/misc.h index 9283cdab..18b3bcc4 100644 --- a/misc.h +++ b/misc.h @@ -98,14 +98,7 @@ void time_stop(enum timetype); void time_start_key(const char *key safe); void time_stop_key(const char *key safe); -extern time_t edlib_timing; -int times_up(void); -void time_starts(void); -void time_ends(void); -static inline int times_up_fast(void) -{ - return edlib_timing == 1; -} +extern bool debugger_is_present(void); void stat_count(char *name safe); -- 2.39.5