Also check for debugger in all pane_too_long() calls.
Signed-off-by: NeilBrown <neil@brown.name>
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
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;
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) {
return len;
}
-time_t edlib_timing = 0;
-
static int _debugger_present = -1;
static void _sigtrap_handler(int signum)
{
}
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;
-}
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;
+}
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;
};
};
-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)
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;
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;
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 **");
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) {
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
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);