Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"", "gen_ut":1760854034, "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":"34267248139212122189a5a45db3629d", "commit": {"type":"commit", "time": 1598889097, "time_ofs": 60, "oid_tree": { "oid": "76df22205d8dd50d2ad5f051d8be8756bbc60e56", "alias": []}, "oid":{ "oid": "095b76853e286aae902f3aee5f49354d25a7589b", "alias": []}, "msg": "smp: lws_mutex_refcount: add assert held helper", "sig_commit": { "git_time": { "time": 1598889097, "offset": 60 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }, "sig_author": { "git_time": { "time": 1598857936, "offset": 60 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }}, "body": "smp: lws_mutex_refcount: add assert held helper\n\nalso additional pt locks shown as needed by that" , "diff": "diff --git a/lib/core-net/close.c b/lib/core-net/close.c\nindex e8f7567..be113b4 100644\n--- a/lib/core-net/close.c\n+++ b/lib/core-net/close.c\n@@ -275,6 +275,9 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason,\n \n \tcontext \u003d wsi-\u003ea.context;\n \tpt \u003d \u0026context-\u003ept[(int)wsi-\u003etsi];\n+\n+\tlws_pt_assert_lock_held(pt);\n+\n \tlws_stats_bump(pt, LWSSTATS_C_API_CLOSE, 1);\n \n #if defined(LWS_WITH_CLIENT)\ndiff --git a/lib/core-net/pollfd.c b/lib/core-net/pollfd.c\nindex eaeda94..894d777 100644\n--- a/lib/core-net/pollfd.c\n+++ b/lib/core-net/pollfd.c\n@@ -271,6 +271,8 @@ __insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi)\n \n //\t__dump_fds(pt, \u0022pre insert\u0022);\n \n+\tlws_pt_assert_lock_held(pt);\n+\n \tlwsl_debug(\u0022%s: %p: tsi\u003d%d, sock\u003d%d, pos-in-fds\u003d%d\u005cn\u0022,\n \t\t __func__, wsi, wsi-\u003etsi, wsi-\u003edesc.sockfd, pt-\u003efds_count);\n \n@@ -352,6 +354,8 @@ __remove_wsi_socket_from_fds(struct lws *wsi)\n \tstruct lws *end_wsi;\n \tint v, m, ret \u003d 0;\n \n+\tlws_pt_assert_lock_held(pt);\n+\n //\t__dump_fds(pt, \u0022pre remove\u0022);\n \n #if !defined(_WIN32)\ndiff --git a/lib/core-net/private-lib-core-net.h b/lib/core-net/private-lib-core-net.h\nindex 05ca1e7..ea785c5 100644\n--- a/lib/core-net/private-lib-core-net.h\n+++ b/lib/core-net/private-lib-core-net.h\n@@ -999,6 +999,7 @@ lws_pt_mutex_destroy(struct lws_context_per_thread *pt)\n \n #define lws_pt_lock(pt, reason) lws_mutex_refcount_lock(\u0026pt-\u003emr, reason)\n #define lws_pt_unlock(pt) lws_mutex_refcount_unlock(\u0026pt-\u003emr)\n+#define lws_pt_assert_lock_held(pt) lws_mutex_refcount_assert_held(\u0026pt-\u003emr)\n \n static LWS_INLINE void\n lws_pt_stats_lock(struct lws_context_per_thread *pt)\ndiff --git a/lib/core-net/vhost.c b/lib/core-net/vhost.c\nindex 09cb979..5e01967 100644\n--- a/lib/core-net/vhost.c\n+++ b/lib/core-net/vhost.c\n@@ -908,6 +908,7 @@ lws_cancel_service(struct lws_context *context)\n int\n lws_create_event_pipes(struct lws_context *context)\n {\n+\tstruct lws_context_per_thread *pt;\n \tsize_t s \u003d sizeof(struct lws);\n \tstruct lws *wsi;\n \tint n;\n@@ -923,7 +924,9 @@ lws_create_event_pipes(struct lws_context *context)\n \tn \u003d 0;\n \t{\n #endif\n-\t\tif (context-\u003ept[n].pipe_wsi)\n+\t\tpt \u003d \u0026context-\u003ept[n];\n+\n+\t\tif (pt-\u003epipe_wsi)\n \t\t\treturn 0;\n \n #if defined(LWS_WITH_EVENT_LIBS)\n@@ -948,6 +951,8 @@ lws_create_event_pipes(struct lws_context *context)\n \t\tcontext-\u003ept[n].pipe_wsi \u003d wsi;\n \t\tcontext-\u003ecount_wsi_allocated++;\n \n+\t\tlws_pt_lock(pt, __func__); /* -------------- pt { */\n+\n \t\tif (!lws_plat_pipe_create(wsi)) {\n \t\t\t/*\n \t\t\t * platform code returns 0 if it actually created pipes\n@@ -963,14 +968,21 @@ lws_create_event_pipes(struct lws_context *context)\n \n \t\t\tif (context-\u003eevent_loop_ops-\u003esock_accept)\n \t\t\t\tif (context-\u003eevent_loop_ops-\u003esock_accept(wsi))\n-\t\t\t\t\treturn 1;\n+\t\t\t\t\tgoto bail;\n \n \t\t\tif (__insert_wsi_socket_into_fds(context, wsi))\n-\t\t\t\treturn 1;\n+\t\t\t\tgoto bail;\n \t\t}\n+\n+\t\tlws_pt_unlock(pt);\n \t}\n \n \treturn 0;\n+\n+bail:\n+\tlws_pt_unlock(pt);\n+\n+\treturn 1;\n }\n \n void\ndiff --git a/lib/core-net/wsi-timeout.c b/lib/core-net/wsi-timeout.c\nindex f3610a5..f6b9fac 100644\n--- a/lib/core-net/wsi-timeout.c\n+++ b/lib/core-net/wsi-timeout.c\n@@ -118,7 +118,9 @@ lws_sul_wsitimeout_cb(lws_sorted_usec_list_t *sul)\n \t\t\t(void *)\u0022Timed out waiting SSL\u0022, 21);\n #endif\n \n+\tlws_pt_lock(pt, __func__);\n \t__lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, \u0022timeout\u0022);\n+\tlws_pt_unlock(pt);\n }\n \n void\ndiff --git a/lib/core/context.c b/lib/core/context.c\nindex 85f77b0..d25e916 100644\n--- a/lib/core/context.c\n+++ b/lib/core/context.c\n@@ -1540,8 +1540,10 @@ lws_pt_destroy(struct lws_context_per_thread *pt)\n \t}\n \tvpt-\u003eforeign_pfd_list \u003d NULL;\n \n+\tlws_pt_lock(pt, __func__);\n \tif (pt-\u003epipe_wsi)\n \t\tlws_destroy_event_pipe(pt-\u003epipe_wsi);\n+\tlws_pt_unlock(pt);\n \tpt-\u003epipe_wsi \u003d NULL;\n \n \twhile (pt-\u003efds_count) {\ndiff --git a/lib/core/libwebsockets.c b/lib/core/libwebsockets.c\nindex e3b7c95..a44e6d5 100644\n--- a/lib/core/libwebsockets.c\n+++ b/lib/core/libwebsockets.c\n@@ -1194,6 +1194,12 @@ lws_mutex_refcount_unlock(struct lws_mutex_refcount *mr)\n \tpthread_mutex_unlock(\u0026mr-\u003elock);\n }\n \n+void\n+lws_mutex_refcount_assert_held(struct lws_mutex_refcount *mr)\n+{\n+\tassert(mr-\u003elock_owner \u003d\u003d pthread_self() \u0026\u0026 mr-\u003elock_depth);\n+}\n+\n #endif /* SMP */\n \n \ndiff --git a/lib/core/private-lib-core.h b/lib/core/private-lib-core.h\nindex ca82651..b4dcf70 100644\n--- a/lib/core/private-lib-core.h\n+++ b/lib/core/private-lib-core.h\n@@ -251,6 +251,9 @@ void\n lws_mutex_refcount_lock(struct lws_mutex_refcount *mr, const char *reason);\n \n void\n+lws_mutex_refcount_assert_held(struct lws_mutex_refcount *mr);\n+\n+void\n lws_mutex_refcount_unlock(struct lws_mutex_refcount *mr);\n #endif\n \n@@ -644,6 +647,7 @@ lws_vhost_unlock(struct lws_vhost *vhost)\n #define lws_pt_mutex_init(_a) (void)(_a)\n #define lws_pt_mutex_destroy(_a) (void)(_a)\n #define lws_pt_lock(_a, b) (void)(_a)\n+#define lws_pt_assert_lock_held(_a) (void)(_a)\n #define lws_pt_unlock(_a) (void)(_a)\n #define lws_context_lock(_a, _b) (void)(_a)\n #define lws_context_unlock(_a) (void)(_a)\ndiff --git a/lib/roles/http/server/server.c b/lib/roles/http/server/server.c\nindex 01a6b38..c8683fc 100644\n--- a/lib/roles/http/server/server.c\n+++ b/lib/roles/http/server/server.c\n@@ -52,6 +52,7 @@ int\n _lws_vhost_init_server(const struct lws_context_creation_info *info,\n \t\t struct lws_vhost *vhost)\n {\n+\tstruct lws_context_per_thread *pt;\n \tint n, opt \u003d 1, limit \u003d 1;\n \tlws_sockfd_type sockfd;\n \tstruct lws_vhost *vh;\n@@ -309,13 +310,18 @@ done_list:\n \t\tif (wsi-\u003ea.context-\u003eevent_loop_ops-\u003einit_vhost_listen_wsi)\n \t\t\twsi-\u003ea.context-\u003eevent_loop_ops-\u003einit_vhost_listen_wsi(wsi);\n \n+\t\tpt \u003d \u0026vhost-\u003econtext-\u003ept[m];\n+\t\tlws_pt_lock(pt, __func__);\n+\n \t\tif (__insert_wsi_socket_into_fds(vhost-\u003econtext, wsi)) {\n \t\t\tlwsl_notice(\u0022inserting wsi socket into fds failed\u005cn\u0022);\n+\t\t\tlws_pt_unlock(pt);\n \t\t\tgoto bail;\n \t\t}\n \n \t\tvhost-\u003econtext-\u003ecount_wsi_allocated++;\n \t\tvhost-\u003elserv_wsi \u003d wsi;\n+\t\tlws_pt_unlock(pt);\n \n \t\tn \u003d listen(wsi-\u003edesc.sockfd, LWS_SOMAXCONN);\n \t\tif (n \u003c 0) {\n","s":{"c":1760854034,"u": 21174}} ],"g": 22580,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}