diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index c1285e86..ec175715 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -954,6 +954,14 @@ struct libwebsocket_extension; * LWS_CALLBACK_UNLOCK_POLL: These allow the external poll changes driven * by libwebsockets to participate in an external thread locking * scheme around the changes, so the whole thing is threadsafe. + * These are called around three activities in the library, + * - inserting a new wsi in the wsi / fd table (len=1) + * - deleting a wsi from the wsi / fd table (len=1) + * - changing a wsi's POLLIN/OUT state (len=0) + * Locking and unlocking external synchronization objects when + * len == 1 allows external threads to be synchronized against + * wsi lifecycle changes if it acquires the same lock for the + * duration of wsi dereference from the other thread context. */ LWS_VISIBLE LWS_EXTERN int callback(struct libwebsocket_context *context, struct libwebsocket *wsi, diff --git a/lib/pollfd.c b/lib/pollfd.c index 08fc4058..b38df3d5 100644 --- a/lib/pollfd.c +++ b/lib/pollfd.c @@ -47,7 +47,7 @@ insert_wsi_socket_into_fds(struct libwebsocket_context *context, // wsi, wsi->sock, context->fds_count); if (context->protocols[0].callback(context, wsi, - LWS_CALLBACK_LOCK_POLL, wsi->user_space, (void *) &pa, 0)) + LWS_CALLBACK_LOCK_POLL, wsi->user_space, (void *) &pa, 1)) return -1; insert_wsi(context, wsi); @@ -63,7 +63,7 @@ insert_wsi_socket_into_fds(struct libwebsocket_context *context, return -1; if (context->protocols[0].callback(context, wsi, - LWS_CALLBACK_UNLOCK_POLL, wsi->user_space, (void *)&pa, 0)) + LWS_CALLBACK_UNLOCK_POLL, wsi->user_space, (void *)&pa, 1)) return -1; return 0; @@ -92,7 +92,7 @@ remove_wsi_socket_from_fds(struct libwebsocket_context *context, wsi, wsi->sock, wsi->position_in_fds_table); if (context->protocols[0].callback(context, wsi, - LWS_CALLBACK_LOCK_POLL, wsi->user_space, (void *)&pa, 0)) + LWS_CALLBACK_LOCK_POLL, wsi->user_space, (void *)&pa, 1)) return -1; m = wsi->position_in_fds_table; /* replace the contents for this */ @@ -123,7 +123,7 @@ remove_wsi_socket_from_fds(struct libwebsocket_context *context, } if (context->protocols[0].callback(context, wsi, LWS_CALLBACK_UNLOCK_POLL, - wsi->user_space, (void *) &pa, 0)) + wsi->user_space, (void *) &pa, 1)) return -1; return 0;