* 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,
// 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);
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;
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 */
}
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;