Skip to content

Commit 626efba

Browse files
committed
Merge branch 'feat/ft-support'
2 parents 889289d + 8a01ad5 commit 626efba

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/evdev/genecodes_c.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@
7777
{
7878
PyObject* m = PyModule_Create(&moduledef);
7979
if (m == NULL) return NULL;
80+
#ifdef Py_GIL_DISABLED
81+
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
82+
#endif
8083
8184
%s
8285

src/evdev/input.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
#include <linux/input.h>
2525
#endif
2626

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+
2735
#ifndef input_event_sec
2836
#define input_event_sec time.tv_sec
2937
#define input_event_usec time.tv_usec
@@ -51,7 +59,10 @@ device_read(PyObject *self, PyObject *args)
5159
// get device file descriptor (O_RDONLY|O_NONBLOCK)
5260
int fd = (int)PyLong_AsLong(PyTuple_GET_ITEM(args, 0));
5361

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
5566

5667
if (n < 0) {
5768
if (errno == EAGAIN) {
@@ -84,7 +95,10 @@ device_read_many(PyObject *self, PyObject *args)
8495
struct input_event event[64];
8596

8697
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
88102

89103
if (nread < 0) {
90104
PyErr_SetFromErrno(PyExc_OSError);
@@ -570,6 +584,9 @@ moduleinit(void)
570584
{
571585
PyObject* m = PyModule_Create(&moduledef);
572586
if (m == NULL) return NULL;
587+
#ifdef Py_GIL_DISABLED
588+
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
589+
#endif
573590
return m;
574591
}
575592

src/evdev/uinput.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,9 @@ moduleinit(void)
405405
{
406406
PyObject* m = PyModule_Create(&moduledef);
407407
if (m == NULL) return NULL;
408-
408+
#ifdef Py_GIL_DISABLED
409+
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
410+
#endif
409411
PyModule_AddIntConstant(m, "maxnamelen", UINPUT_MAX_NAME_SIZE);
410412
return m;
411413
}

0 commit comments

Comments
 (0)