detect service tid once and use wsi with valid context to do it
authorAndy Green <andy.green@linaro.org>
Thu, 24 Dec 2015 05:00:54 +0000 (13:00 +0800)
committerAndy Green <andy.green@linaro.org>
Thu, 24 Dec 2015 05:00:54 +0000 (13:00 +0800)
Signed-off-by: Andy Green <andy.green@linaro.org>
lib/lws-plat-unix.c
lib/lws-plat-win.c
lib/pollfd.c
lib/private-libwebsockets.h

index c972a36..23c11b0 100644 (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 */
index ccbe47a..eac500b 100644 (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];
index 46417c8..319abbd 100644 (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;
index 62a3646..731deb2 100644 (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