Skip to content

Commit

Permalink
detect service tid once and use wsi with valid context to do it
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Green <andy.green@linaro.org>
  • Loading branch information
Andy Green committed Dec 24, 2015
1 parent 400e5a7 commit c35b36b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
12 changes: 10 additions & 2 deletions lib/lws-plat-unix.c
Expand Up @@ -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 */
Expand Down
12 changes: 10 additions & 2 deletions lib/lws-plat-win.c
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion lib/pollfd.c
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/private-libwebsockets.h
Expand Up @@ -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
Expand Down

0 comments on commit c35b36b

Please sign in to comment.