mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-16 00:00:07 +01:00
CALLBACK_LOCK_POLL use len to differentiate locking on pollfd change
Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
parent
adf9059d82
commit
5a3b1d307b
2 changed files with 12 additions and 4 deletions
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue