|
24 | 24 | #include <linux/input.h> |
25 | 25 | #endif |
26 | 26 |
|
| 27 | +#if defined(Py_GIL_DISABLED) |
| 28 | + #define MAYBE_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS |
| 29 | + #define MAYBE_END_ALLOW_THREADS Py_END_ALLOW_THREADS |
| 30 | +#else |
| 31 | + #define MAYBE_BEGIN_ALLOW_THREADS |
| 32 | + #define MAYBE_END_ALLOW_THREADS |
| 33 | +#endif |
| 34 | + |
27 | 35 | #ifndef input_event_sec |
28 | 36 | #define input_event_sec time.tv_sec |
29 | 37 | #define input_event_usec time.tv_usec |
@@ -51,7 +59,10 @@ device_read(PyObject *self, PyObject *args) |
51 | 59 | // get device file descriptor (O_RDONLY|O_NONBLOCK) |
52 | 60 | int fd = (int)PyLong_AsLong(PyTuple_GET_ITEM(args, 0)); |
53 | 61 |
|
54 | | - int n = read(fd, &event, sizeof(event)); |
| 62 | + int n; |
| 63 | + MAYBE_BEGIN_ALLOW_THREADS |
| 64 | + n = read(fd, &event, sizeof(event)); |
| 65 | + MAYBE_END_ALLOW_THREADS |
55 | 66 |
|
56 | 67 | if (n < 0) { |
57 | 68 | if (errno == EAGAIN) { |
@@ -84,7 +95,10 @@ device_read_many(PyObject *self, PyObject *args) |
84 | 95 | struct input_event event[64]; |
85 | 96 |
|
86 | 97 | size_t event_size = sizeof(struct input_event); |
87 | | - ssize_t nread = read(fd, event, event_size*64); |
| 98 | + ssize_t nread; |
| 99 | + MAYBE_BEGIN_ALLOW_THREADS |
| 100 | + nread = read(fd, event, event_size*64); |
| 101 | + MAYBE_END_ALLOW_THREADS |
88 | 102 |
|
89 | 103 | if (nread < 0) { |
90 | 104 | PyErr_SetFromErrno(PyExc_OSError); |
@@ -570,6 +584,9 @@ moduleinit(void) |
570 | 584 | { |
571 | 585 | PyObject* m = PyModule_Create(&moduledef); |
572 | 586 | if (m == NULL) return NULL; |
| 587 | +#ifdef Py_GIL_DISABLED |
| 588 | + PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED); |
| 589 | +#endif |
573 | 590 | return m; |
574 | 591 | } |
575 | 592 |
|
|
0 commit comments