various improvements in greenlet plugin

This commit is contained in:
Unbit
2013-10-27 18:31:31 +01:00
parent 4489b48603
commit 7a39472700
2 changed files with 26 additions and 7 deletions
+8 -7
View File
@@ -311,26 +311,27 @@ end:
}
void async_schedule_to_req_green(void) {
struct wsgi_request *wsgi_req = uwsgi.wsgi_req;
#ifdef UWSGI_ROUTING
if (uwsgi_apply_routes(uwsgi.wsgi_req) == UWSGI_ROUTE_BREAK) {
if (uwsgi_apply_routes(wsgi_req) == UWSGI_ROUTE_BREAK) {
goto end;
}
#endif
for(;;) {
if (uwsgi.p[uwsgi.wsgi_req->uh->modifier1]->request(uwsgi.wsgi_req) <= UWSGI_OK) {
if (uwsgi.p[uwsgi.wsgi_req->uh->modifier1]->request(wsgi_req) <= UWSGI_OK) {
break;
}
uwsgi.wsgi_req->switches++;
wsgi_req->switches++;
// switch after each yield
uwsgi.schedule_to_main(uwsgi.wsgi_req);
uwsgi.schedule_to_main(wsgi_req);
}
#ifdef UWSGI_ROUTING
end:
#endif
async_reset_request(uwsgi.wsgi_req);
uwsgi_close_request(uwsgi.wsgi_req);
uwsgi.wsgi_req->async_status = UWSGI_OK;
async_reset_request(wsgi_req);
uwsgi_close_request(wsgi_req);
wsgi_req->async_status = UWSGI_OK;
}
void async_loop() {
+18
View File
@@ -16,6 +16,20 @@ static struct uwsgi_option greenlet_options[] = {
{ 0, 0, 0, 0, 0, 0, 0 }
};
struct wsgi_request *uwsgi_greenlet_current_wsgi_req(void) {
struct wsgi_request *wsgi_req = NULL;
PyObject *py_wsgi_req = PyObject_GetAttrString((PyObject *)PyGreenlet_GetCurrent(), "uwsgi_wsgi_req");
// not in greenlet
if (!py_wsgi_req) {
uwsgi_log("[BUG] current_wsgi_req NOT FOUND !!!\n");
goto end;
}
wsgi_req = (struct wsgi_request*) PyLong_AsLong(py_wsgi_req);
Py_DECREF(py_wsgi_req);
end:
return wsgi_req;
}
static void gil_greenlet_get() {
pthread_setspecific(up.upt_gil_key, (void *) PyGILState_Ensure());
}
@@ -46,6 +60,7 @@ static void greenlet_schedule_to_req() {
if (!uwsgi.wsgi_req->suspended) {
ugl.gl[id] = PyGreenlet_New(ugl.callable, NULL);
PyObject_SetAttrString((PyObject *)ugl.gl[id], "uwsgi_wsgi_req", PyLong_FromLong((long) uwsgi.wsgi_req));
uwsgi.wsgi_req->suspended = 1;
}
@@ -93,6 +108,9 @@ static void greenlet_init_apps(void) {
up.gil_release = gil_greenlet_release;
}
// map wsgi_req to greenlet object
uwsgi.current_wsgi_req = uwsgi_greenlet_current_wsgi_req;
// blindy call it as the stackless gil engine is already set
UWSGI_GET_GIL