-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcallbacks.c
More file actions
62 lines (51 loc) · 1.44 KB
/
callbacks.c
File metadata and controls
62 lines (51 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifdef WITH_THREAD
#define GIL_DECLARE PyGILState_STATE ___save
#define GIL_ENSURE ___save = PyGILState_Ensure();
#define GIL_RELEASE PyGILState_Release(___save);
#else
#define GIL_DECLARE
#define GIL_ENSURE
#define GIL_RELEASE
#endif
static void cothread_run(gevent_cothread* t) {
GIL_DECLARE;
PyObject *result, *run, *args, *kwargs;
GIL_ENSURE;
assert(t->state == GEVENT_COTHREAD_CURRENT);
run = t->op.init.args[0];
args = t->op.init.args[1];
kwargs = t->op.init.args[2];
Py_INCREF(run);
Py_INCREF(args);
Py_XINCREF(kwargs);
/* we do not incref this objects because they already we increfed by caller */
result = PyObject_Call(run, args, kwargs);
if (result) {
Py_DECREF(result);
}
else {
PyErr_Print();
PyErr_Clear();
}
Py_DECREF(run);
Py_DECREF(args);
Py_XDECREF(kwargs);
GIL_RELEASE;
}
static void cothread_exit_fn(gevent_cothread* t) {
GIL_DECLARE;
PyObject* py_cothread;
GIL_ENSURE;
py_cothread = (PyObject*)ngx_queue_data(t, struct PyGeventCothreadObject, data);
Py_DECREF(py_cothread);
GIL_RELEASE;
}
static void cothread_init(gevent_cothread* t, PyObject* run, PyObject* args, PyObject* kwargs) {
gevent_cothread_init(gevent_default_hub(), t, cothread_run);
t->op.init.args[0] = run;
Py_INCREF(run);
t->op.init.args[1] = args;
Py_INCREF(args);
t->op.init.args[2] = kwargs;
Py_INCREF(kwargs);
}