]> git.neil.brown.name Git - edlib.git/commitdiff
Change times_up() to use pane_too_long() on root.
authorNeilBrown <neil@brown.name>
Sat, 22 Jul 2023 02:06:44 +0000 (12:06 +1000)
committerNeilBrown <neil@brown.name>
Sat, 22 Jul 2023 02:06:44 +0000 (12:06 +1000)
Also check for debugger in all pane_too_long() calls.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
core-keymap.c
core-misc.c
core-pane.c
core-pane.h
lib-input.c
misc.h

index de3a3a71fb84047fd334e46464acaae4abeb421b..967c25afbbd5516b4e58b8223efabaf5f60de310 100644 (file)
@@ -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
index c0e22746903e44408b01c636bc05671122d976a1..c2b6e492ae9932a507575aa716d0b3d7670fd858 100644 (file)
@@ -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) {
index 891157f3894b8ad7db3e1ccded4f41ae1a69b36c..4ad03f252356b481bf94ea1344df98532c4d0616 100644 (file)
@@ -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;
-}
index e30420937586cf68441f2343c2815c75aad0d146..0ad66dc5a24780270375649eb1b1e72f4bc6ec7a 100644 (file)
@@ -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;
+}
index 9c1fa6fce4d5ac7e3bda33daef48a46ecf2e7e76..1e1460472adf47e4a358c79549c46601a6be2a8c 100644 (file)
@@ -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;
index eae717557c34aebce566ab9785d0408ac75f0326..69e6a7ebda10dc32676f1b498969d6ff65c067c7 100644 (file)
@@ -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 9283cdab2199ac684f2bb8648c83a2af5dfc22d8..18b3bcc489a2bcc521cee509a940f0508f62426d 100644 (file)
--- 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);