Speed up draining of the wakeup_fd buffer

This commit is contained in:
Kovid Goyal
2016-12-02 16:56:26 +05:30
parent 7ec41ba7fb
commit c75d7f60cb
2 changed files with 11 additions and 5 deletions

View File

@@ -10,8 +10,17 @@
#include "gl.h"
#include "modes.h"
static char drain_buf[1024] = {0};
static PyObject*
drain_read(PyObject UNUSED *self, PyObject *fd) {
read(PyLong_AsLong(fd), drain_buf, sizeof(drain_buf));
Py_RETURN_NONE;
}
static PyMethodDef module_methods[] = {
GL_METHODS
{"drain_read", (PyCFunction)drain_read, METH_O, ""},
{"parse_bytes", (PyCFunction)parse_bytes, METH_VARARGS, ""},
{"parse_bytes_dump", (PyCFunction)parse_bytes_dump, METH_VARARGS, ""},
{"read_bytes", (PyCFunction)read_bytes, METH_VARARGS, ""},

View File

@@ -22,7 +22,7 @@ from .constants import (
from .fast_data_types import (
glViewport, glBlendFunc, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GLFW_PRESS,
GLFW_REPEAT, GLFW_MOUSE_BUTTON_1, glfw_post_empty_event,
GLFW_CURSOR_NORMAL, GLFW_CURSOR, GLFW_CURSOR_HIDDEN,
GLFW_CURSOR_NORMAL, GLFW_CURSOR, GLFW_CURSOR_HIDDEN, drain_read
)
from .fonts import set_font_family
from .borders import Borders, BordersProgram
@@ -199,10 +199,7 @@ class TabManager(Thread):
def on_wakeup(self):
if not self.shutting_down:
try:
os.read(self.read_wakeup_fd, io.DEFAULT_BUFFER_SIZE)
except (EnvironmentError, BlockingIOError):
pass
drain_read(self.read_wakeup_fd)
while True:
try:
func, args = self.action_queue.get_nowait()