From 7b315e394fd2224cd6800c2c349c52e5e5ac77f8 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Thu, 20 May 2021 08:42:52 +0100 Subject: [PATCH] smp: give PROTOCOL_INIT a privake fakewsi At init-time, PROTOCOL_INIT needs to be sent to each vhost-protocol combination to give them a chance to instantiate themselves. PROTOCOL_INIT can be deferred a bit, and since its subject is per vhost, which has no tsi affinity, in SMP case, its current use of context->pt[0] fakewsi can clash with other stuff happening simultaneously, eg, CANCEL_SERVICE broadcast, which happens on each pt. Solve this by changing PROTOCOL_INIT to use an on-stack fakewsi that cannot clash with any other service loop use of them. Take care about using a full fake wsi or an lws_a fakewsi if PLAT_FREERTOS. --- lib/core-net/vhost.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/core-net/vhost.c b/lib/core-net/vhost.c index ec5349e0f..6556ef29c 100644 --- a/lib/core-net/vhost.c +++ b/lib/core-net/vhost.c @@ -368,17 +368,25 @@ int lws_protocol_init_vhost(struct lws_vhost *vh, int *any) { const struct lws_protocol_vhost_options *pvo, *pvo1; - lws_fakewsi_def_plwsa(&vh->context->pt[0]); int n; +#if defined(LWS_PLAT_FREERTOS) + struct lws_a _lwsa, *lwsa = &_lwsa; - lws_fakewsi_prep_plwsa_ctx(vh->context); + memset(&_lwsa, 0, sizeof(_lwsa)); +#else + struct lws _lws; + struct lws_a *lwsa = &_lws.a; - plwsa->vhost = vh; + memset(&_lws, 0, sizeof(_lws)); +#endif + + lwsa->context = vh->context; + lwsa->vhost = vh; /* initialize supported protocols on this vhost */ for (n = 0; n < vh->count_protocols; n++) { - plwsa->protocol = &vh->protocols[n]; + lwsa->protocol = &vh->protocols[n]; if (!vh->protocols[n].name) continue; pvo = lws_vhost_protocol_options(vh, vh->protocols[n].name); @@ -424,9 +432,6 @@ lws_protocol_init_vhost(struct lws_vhost *vh, int *any) *any |= !!vh->tls.ssl_ctx; #endif - plwsa->vhost = vh; - plwsa->protocol = &vh->protocols[n]; - pvo = lws_vhost_protocol_options(vh, vh->protocols[n].name); /* @@ -440,7 +445,7 @@ lws_protocol_init_vhost(struct lws_vhost *vh, int *any) if (pvo || !vh->pvo) { lwsl_info("%s: init %s.%s\n", __func__, vh->name, vh->protocols[n].name); - if (vh->protocols[n].callback((struct lws *)plwsa, + if (vh->protocols[n].callback((struct lws *)lwsa, LWS_CALLBACK_PROTOCOL_INIT, NULL, (void *)(pvo ? pvo->options : NULL), 0)) { if (vh->protocol_vh_privs && vh->protocol_vh_privs[n]) {