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:
Andy Green 2015-11-20 09:51:18 +08:00
parent adf9059d82
commit 5a3b1d307b
2 changed files with 12 additions and 4 deletions

View file

@ -954,6 +954,14 @@ struct libwebsocket_extension;
* LWS_CALLBACK_UNLOCK_POLL: These allow the external poll changes driven * LWS_CALLBACK_UNLOCK_POLL: These allow the external poll changes driven
* by libwebsockets to participate in an external thread locking * by libwebsockets to participate in an external thread locking
* scheme around the changes, so the whole thing is threadsafe. * 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, LWS_VISIBLE LWS_EXTERN int callback(struct libwebsocket_context *context,
struct libwebsocket *wsi, struct libwebsocket *wsi,

View file

@ -47,7 +47,7 @@ insert_wsi_socket_into_fds(struct libwebsocket_context *context,
// wsi, wsi->sock, context->fds_count); // wsi, wsi->sock, context->fds_count);
if (context->protocols[0].callback(context, wsi, 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; return -1;
insert_wsi(context, wsi); insert_wsi(context, wsi);
@ -63,7 +63,7 @@ insert_wsi_socket_into_fds(struct libwebsocket_context *context,
return -1; return -1;
if (context->protocols[0].callback(context, wsi, 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 -1;
return 0; return 0;
@ -92,7 +92,7 @@ remove_wsi_socket_from_fds(struct libwebsocket_context *context,
wsi, wsi->sock, wsi->position_in_fds_table); wsi, wsi->sock, wsi->position_in_fds_table);
if (context->protocols[0].callback(context, wsi, 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; return -1;
m = wsi->position_in_fds_table; /* replace the contents for this */ 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, if (context->protocols[0].callback(context, wsi,
LWS_CALLBACK_UNLOCK_POLL, LWS_CALLBACK_UNLOCK_POLL,
wsi->user_space, (void *) &pa, 0)) wsi->user_space, (void *) &pa, 1))
return -1; return -1;
return 0; return 0;