Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"", "gen_ut":1713545042, "reponame":"libwebsockets", "desc":"libwebsockets lightweight C networking library", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets", "f":3, "items": [ {"schema":"libjg2-1", "cid":"68d5feb1c34d5e61222d46bffde9733b", "commit": {"type":"commit", "time": 1525260449, "time_ofs": 480, "oid_tree": { "oid": "269ba393be9e80eefcf7cd8fb0ead04b9ac24495", "alias": []}, "oid":{ "oid": "9cce1874b03dfc5dafe8b07f21ddbb0b35fde45d", "alias": []}, "msg": "context_destroy: figure out if anything still in event loop", "sig_commit": { "git_time": { "time": 1525260449, "offset": 480 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }, "sig_author": { "git_time": { "time": 1525260449, "offset": 480 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }}, "body": "context_destroy: figure out if anything still in event loop" , "diff": "diff --git a/lib/context.c b/lib/context.c\nindex d638ff5..c85a481 100644\n--- a/lib/context.c\n+++ b/lib/context.c\n@@ -1721,6 +1721,10 @@ lws_vhost_destroy(struct lws_vhost *vh)\n * destroys the context itself, setting what was info.pcontext to NULL.\n */\n \n+/*\n+ * destroy the actual context itself\n+ */\n+\n static void\n lws_context_destroy3(struct lws_context *context)\n {\n@@ -1733,6 +1737,10 @@ lws_context_destroy3(struct lws_context *context)\n \t\t*pcontext_finalize \u003d NULL;\n }\n \n+/*\n+ * really start destroying things\n+ */\n+\n void\n lws_context_destroy2(struct lws_context *context)\n {\n@@ -1802,6 +1810,10 @@ lws_context_destroy2(struct lws_context *context)\n \tlws_context_destroy3(context);\n }\n \n+/*\n+ * Begin the context takedown\n+ */\n+\n LWS_VISIBLE void\n lws_context_destroy(struct lws_context *context)\n {\n@@ -1909,6 +1921,22 @@ lws_context_destroy(struct lws_context *context)\n \n \tlws_plat_context_early_destroy(context);\n \n+\t/*\n+\t * We face two different needs depending if foreign loop or not.\n+\t *\n+\t * 1) If foreign loop, we really want to advance the destroy_context()\n+\t * past here, and block only for libuv-style async close completion.\n+\t *\n+\t * 2a) If poll, and we exited by ourselves and are calling a final\n+\t * destroy_context() outside of any service already, we want to\n+\t * advance all the way in one step.\n+\t *\n+\t * 2b) If poll, and we are reacting to a SIGINT, service thread(s) may\n+\t * be in poll wait or servicing. We can't advance the\n+\t * destroy_context() to the point it's freeing things; we have to\n+\t * leave that for the final destroy_context() after the service\n+\t * thread(s) are finished calling for service.\n+\t */\n \n \tif (context-\u003eevent_loop_ops-\u003edestroy_context1) {\n \t\tcontext-\u003eevent_loop_ops-\u003edestroy_context1(context);\n@@ -1916,5 +1944,10 @@ lws_context_destroy(struct lws_context *context)\n \t\treturn;\n \t}\n \n+\tif (!context-\u003ept[0].event_loop_foreign)\n+\t\tfor (n \u003d 0; n \u003c context-\u003ecount_threads; n++)\n+\t\t\tif (context-\u003ept[n].inside_service)\n+\t\t\t\treturn;\n+\n \tlws_context_destroy2(context);\n }\ndiff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h\nindex a221201..4ff5878 100644\n--- a/lib/private-libwebsockets.h\n+++ b/lib/private-libwebsockets.h\n@@ -593,6 +593,7 @@ struct lws_context_per_thread {\n \tunsigned char tid;\n \n \tunsigned char lock_depth;\n+\tunsigned char inside_service:1;\n \tunsigned char event_loop_foreign:1;\n \tunsigned char event_loop_destroy_processing_done:1;\n };\ndiff --git a/lib/service.c b/lib/service.c\nindex 39dba41..8cf8c93 100644\n--- a/lib/service.c\n+++ b/lib/service.c\n@@ -939,24 +939,49 @@ lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd)\n LWS_VISIBLE int\n lws_service(struct lws_context *context, int timeout_ms)\n {\n+\tstruct lws_context_per_thread *pt \u003d \u0026context-\u003ept[0];\n+\tint n;\n+\n+\tif (!context)\n+\t\treturn 1;\n+\n+\tpt-\u003einside_service \u003d 1;\n+\n \tif (context-\u003eevent_loop_ops-\u003erun_pt) {\n \t\t/* we are configured for an event loop */\n \t\tcontext-\u003eevent_loop_ops-\u003erun_pt(context, 0);\n \n+\t\tpt-\u003einside_service \u003d 0;\n+\n \t\treturn 1;\n \t}\n-\treturn lws_plat_service(context, timeout_ms);\n+\tn \u003d lws_plat_service(context, timeout_ms);\n+\n+\tpt-\u003einside_service \u003d 0;\n+\n+\treturn n;\n }\n \n LWS_VISIBLE int\n lws_service_tsi(struct lws_context *context, int timeout_ms, int tsi)\n {\n+\tstruct lws_context_per_thread *pt \u003d \u0026context-\u003ept[tsi];\n+\tint n;\n+\n+\tpt-\u003einside_service \u003d 1;\n+\n \tif (context-\u003eevent_loop_ops-\u003erun_pt) {\n \t\t/* we are configured for an event loop */\n \t\tcontext-\u003eevent_loop_ops-\u003erun_pt(context, tsi);\n \n+\t\tpt-\u003einside_service \u003d 0;\n+\n \t\treturn 1;\n \t}\n \n-\treturn _lws_plat_service_tsi(context, timeout_ms, tsi);\n+\tn \u003d _lws_plat_service_tsi(context, timeout_ms, tsi);\n+\n+\tpt-\u003einside_service \u003d 0;\n+\n+\treturn n;\n }\n","s":{"c":1713545042,"u": 5961}} ],"g": 6838,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}