Simply use of repaint_delay in parse_input()

Dont maintain per child parse times. Instead just gate it globally.
This could result in slowdowns with lots of very active children, but
that seems unlikely.
This commit is contained in:
Kovid Goyal
2017-09-07 20:50:39 +05:30
parent 161161f840
commit ff3ddfd369

View File

@@ -36,7 +36,6 @@ typedef struct {
bool needs_removal; bool needs_removal;
int fd; int fd;
unsigned long id; unsigned long id;
double last_paint_at;
pid_t pid; pid_t pid;
} Child; } Child;
@@ -256,7 +255,7 @@ shutdown(ChildMonitor *self) {
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static inline void static inline bool
do_parse(ChildMonitor *self, Screen *screen, unsigned long child_id) { do_parse(ChildMonitor *self, Screen *screen, unsigned long child_id) {
bool updated = false; bool updated = false;
screen_mutex(lock, read); screen_mutex(lock, read);
@@ -272,12 +271,17 @@ do_parse(ChildMonitor *self, Screen *screen, unsigned long child_id) {
if (t == NULL) PyErr_Print(); if (t == NULL) PyErr_Print();
else Py_DECREF(t); else Py_DECREF(t);
} }
return updated;
} }
static double last_parse_at = -1000;
static void static void
parse_input(ChildMonitor *self) { parse_input(ChildMonitor *self) {
// Parse all available input that was read in the I/O thread. // Parse all available input that was read in the I/O thread.
size_t count = 0, remove_count = 0; size_t count = 0, remove_count = 0;
double now = monotonic();
double time_since_last_parse = now - last_parse_at;
bool parse_needed = time_since_last_parse >= self->repaint_delay ? true : false;
children_mutex(lock); children_mutex(lock);
while (remove_queue_count) { while (remove_queue_count) {
remove_queue_count--; remove_queue_count--;
@@ -290,10 +294,13 @@ parse_input(ChildMonitor *self) {
glfwSetWindowShouldClose(glfw_window_id, true); glfwSetWindowShouldClose(glfw_window_id, true);
glfwPostEmptyEvent(); glfwPostEmptyEvent();
} else { } else {
count = self->count; if (parse_needed) {
for (size_t i = 0; i < count; i++) { count = self->count;
scratch[i] = children[i]; for (size_t i = 0; i < count; i++) {
INCREF_CHILD(scratch[i]); scratch[i] = children[i];
INCREF_CHILD(scratch[i]);
}
last_parse_at = now;
} }
} }
children_mutex(unlock); children_mutex(unlock);
@@ -307,22 +314,14 @@ parse_input(ChildMonitor *self) {
else Py_DECREF(t); else Py_DECREF(t);
} }
double wait_for = self->repaint_delay;
for (size_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
if (!scratch[i].needs_removal) { if (!scratch[i].needs_removal) {
double now = monotonic(); do_parse(self, scratch[i].screen, scratch[i].id);
double time_since_last_repaint = now - scratch[i].last_paint_at;
if (time_since_last_repaint >= self->repaint_delay) {
do_parse(self, scratch[i].screen, scratch[i].id);
children[i].last_paint_at = now;
} else {
wait_for = MIN(wait_for, self->repaint_delay - time_since_last_repaint);
}
} }
DECREF_CHILD(scratch[i]); DECREF_CHILD(scratch[i]);
} }
if (wait_for < self->repaint_delay) { if (!parse_needed) {
timers_add(self->timers, wait_for, false, Py_None, NULL); timers_add(self->timers, self->repaint_delay - time_since_last_parse, false, Py_None, NULL);
} }
} }