mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
smp: lws_mutex_refcount: add assert held helper
also additional pt locks shown as needed by that
This commit is contained in:
parent
8235db7726
commit
095b76853e
9 changed files with 43 additions and 3 deletions
|
@ -275,6 +275,9 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason,
|
|||
|
||||
context = wsi->a.context;
|
||||
pt = &context->pt[(int)wsi->tsi];
|
||||
|
||||
lws_pt_assert_lock_held(pt);
|
||||
|
||||
lws_stats_bump(pt, LWSSTATS_C_API_CLOSE, 1);
|
||||
|
||||
#if defined(LWS_WITH_CLIENT)
|
||||
|
|
|
@ -271,6 +271,8 @@ __insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi)
|
|||
|
||||
// __dump_fds(pt, "pre insert");
|
||||
|
||||
lws_pt_assert_lock_held(pt);
|
||||
|
||||
lwsl_debug("%s: %p: tsi=%d, sock=%d, pos-in-fds=%d\n",
|
||||
__func__, wsi, wsi->tsi, wsi->desc.sockfd, pt->fds_count);
|
||||
|
||||
|
@ -352,6 +354,8 @@ __remove_wsi_socket_from_fds(struct lws *wsi)
|
|||
struct lws *end_wsi;
|
||||
int v, m, ret = 0;
|
||||
|
||||
lws_pt_assert_lock_held(pt);
|
||||
|
||||
// __dump_fds(pt, "pre remove");
|
||||
|
||||
#if !defined(_WIN32)
|
||||
|
|
|
@ -999,6 +999,7 @@ lws_pt_mutex_destroy(struct lws_context_per_thread *pt)
|
|||
|
||||
#define lws_pt_lock(pt, reason) lws_mutex_refcount_lock(&pt->mr, reason)
|
||||
#define lws_pt_unlock(pt) lws_mutex_refcount_unlock(&pt->mr)
|
||||
#define lws_pt_assert_lock_held(pt) lws_mutex_refcount_assert_held(&pt->mr)
|
||||
|
||||
static LWS_INLINE void
|
||||
lws_pt_stats_lock(struct lws_context_per_thread *pt)
|
||||
|
|
|
@ -908,6 +908,7 @@ lws_cancel_service(struct lws_context *context)
|
|||
int
|
||||
lws_create_event_pipes(struct lws_context *context)
|
||||
{
|
||||
struct lws_context_per_thread *pt;
|
||||
size_t s = sizeof(struct lws);
|
||||
struct lws *wsi;
|
||||
int n;
|
||||
|
@ -923,7 +924,9 @@ lws_create_event_pipes(struct lws_context *context)
|
|||
n = 0;
|
||||
{
|
||||
#endif
|
||||
if (context->pt[n].pipe_wsi)
|
||||
pt = &context->pt[n];
|
||||
|
||||
if (pt->pipe_wsi)
|
||||
return 0;
|
||||
|
||||
#if defined(LWS_WITH_EVENT_LIBS)
|
||||
|
@ -948,6 +951,8 @@ lws_create_event_pipes(struct lws_context *context)
|
|||
context->pt[n].pipe_wsi = wsi;
|
||||
context->count_wsi_allocated++;
|
||||
|
||||
lws_pt_lock(pt, __func__); /* -------------- pt { */
|
||||
|
||||
if (!lws_plat_pipe_create(wsi)) {
|
||||
/*
|
||||
* platform code returns 0 if it actually created pipes
|
||||
|
@ -963,14 +968,21 @@ lws_create_event_pipes(struct lws_context *context)
|
|||
|
||||
if (context->event_loop_ops->sock_accept)
|
||||
if (context->event_loop_ops->sock_accept(wsi))
|
||||
return 1;
|
||||
goto bail;
|
||||
|
||||
if (__insert_wsi_socket_into_fds(context, wsi))
|
||||
return 1;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
lws_pt_unlock(pt);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
bail:
|
||||
lws_pt_unlock(pt);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -118,7 +118,9 @@ lws_sul_wsitimeout_cb(lws_sorted_usec_list_t *sul)
|
|||
(void *)"Timed out waiting SSL", 21);
|
||||
#endif
|
||||
|
||||
lws_pt_lock(pt, __func__);
|
||||
__lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "timeout");
|
||||
lws_pt_unlock(pt);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1540,8 +1540,10 @@ lws_pt_destroy(struct lws_context_per_thread *pt)
|
|||
}
|
||||
vpt->foreign_pfd_list = NULL;
|
||||
|
||||
lws_pt_lock(pt, __func__);
|
||||
if (pt->pipe_wsi)
|
||||
lws_destroy_event_pipe(pt->pipe_wsi);
|
||||
lws_pt_unlock(pt);
|
||||
pt->pipe_wsi = NULL;
|
||||
|
||||
while (pt->fds_count) {
|
||||
|
|
|
@ -1194,6 +1194,12 @@ lws_mutex_refcount_unlock(struct lws_mutex_refcount *mr)
|
|||
pthread_mutex_unlock(&mr->lock);
|
||||
}
|
||||
|
||||
void
|
||||
lws_mutex_refcount_assert_held(struct lws_mutex_refcount *mr)
|
||||
{
|
||||
assert(mr->lock_owner == pthread_self() && mr->lock_depth);
|
||||
}
|
||||
|
||||
#endif /* SMP */
|
||||
|
||||
|
||||
|
|
|
@ -250,6 +250,9 @@ lws_mutex_refcount_destroy(struct lws_mutex_refcount *mr);
|
|||
void
|
||||
lws_mutex_refcount_lock(struct lws_mutex_refcount *mr, const char *reason);
|
||||
|
||||
void
|
||||
lws_mutex_refcount_assert_held(struct lws_mutex_refcount *mr);
|
||||
|
||||
void
|
||||
lws_mutex_refcount_unlock(struct lws_mutex_refcount *mr);
|
||||
#endif
|
||||
|
@ -644,6 +647,7 @@ lws_vhost_unlock(struct lws_vhost *vhost)
|
|||
#define lws_pt_mutex_init(_a) (void)(_a)
|
||||
#define lws_pt_mutex_destroy(_a) (void)(_a)
|
||||
#define lws_pt_lock(_a, b) (void)(_a)
|
||||
#define lws_pt_assert_lock_held(_a) (void)(_a)
|
||||
#define lws_pt_unlock(_a) (void)(_a)
|
||||
#define lws_context_lock(_a, _b) (void)(_a)
|
||||
#define lws_context_unlock(_a) (void)(_a)
|
||||
|
|
|
@ -52,6 +52,7 @@ int
|
|||
_lws_vhost_init_server(const struct lws_context_creation_info *info,
|
||||
struct lws_vhost *vhost)
|
||||
{
|
||||
struct lws_context_per_thread *pt;
|
||||
int n, opt = 1, limit = 1;
|
||||
lws_sockfd_type sockfd;
|
||||
struct lws_vhost *vh;
|
||||
|
@ -309,13 +310,18 @@ done_list:
|
|||
if (wsi->a.context->event_loop_ops->init_vhost_listen_wsi)
|
||||
wsi->a.context->event_loop_ops->init_vhost_listen_wsi(wsi);
|
||||
|
||||
pt = &vhost->context->pt[m];
|
||||
lws_pt_lock(pt, __func__);
|
||||
|
||||
if (__insert_wsi_socket_into_fds(vhost->context, wsi)) {
|
||||
lwsl_notice("inserting wsi socket into fds failed\n");
|
||||
lws_pt_unlock(pt);
|
||||
goto bail;
|
||||
}
|
||||
|
||||
vhost->context->count_wsi_allocated++;
|
||||
vhost->lserv_wsi = wsi;
|
||||
lws_pt_unlock(pt);
|
||||
|
||||
n = listen(wsi->desc.sockfd, LWS_SOMAXCONN);
|
||||
if (n < 0) {
|
||||
|
|
Loading…
Add table
Reference in a new issue