detect service tid once and use wsi with valid context to do it

Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
Andy Green 2015-12-24 13:00:54 +08:00
parent 400e5a7fed
commit c35b36b1cf
4 changed files with 22 additions and 5 deletions

View file

@ -112,8 +112,16 @@ lws_plat_service(struct lws_context *context, int timeout_ms)
lws_libev_run(context);
context->service_tid = context->protocols[0].callback(NULL,
LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
if (!context->service_tid_detected) {
struct lws _lws;
memset(&_lws, 0, sizeof(_lws));
_lws.context = context;
context->service_tid_detected = context->protocols[0].callback(
&_lws, LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
}
context->service_tid = context->service_tid_detected;
#ifdef LWS_OPENSSL_SUPPORT
/* if we know we have non-network pending data, do not wait in poll */

View file

@ -149,8 +149,16 @@ lws_plat_service(struct lws_context *context, int timeout_ms)
if (context == NULL)
return 1;
context->service_tid = context->protocols[0].callback(NULL,
LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
if (!context->service_tid_detected) {
struct lws _lws;
memset(&_lws, 0, sizeof(_lws));
_lws.context = context;
context->service_tid_detected = context->protocols[0].callback(
&_lws, LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
}
context->service_tid = context->service_tid_detected;
for (i = 0; i < context->fds_count; ++i) {
pfd = &context->fds[i];

View file

@ -174,7 +174,7 @@ lws_change_pollfd(struct lws *wsi, int _and, int _or)
sampled_tid = context->service_tid;
if (sampled_tid) {
tid = context->protocols[0].callback(NULL,
tid = context->protocols[0].callback(wsi,
LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
if (tid == -1)
return -1;

View file

@ -502,6 +502,7 @@ struct lws_context {
* for pollfd event change.
*/
volatile int service_tid;
int service_tid_detected;
#ifndef _WIN32
int dummy_pipe_fds[2];
#endif