Fix for races in thread status

This commit is contained in:
Ron Pedde 2005-11-14 04:30:12 +00:00
parent dee22896a8
commit a57b002243
3 changed files with 39 additions and 11 deletions

View File

@ -1254,6 +1254,7 @@ void config_set_status(WS_CONNINFO *pwsc, int session, char *fmt, ...) {
newmsg = strdup(buffer);
}
ws_lock_local_storage(pwsc);
if(!(pfirst = ws_get_local_storage(pwsc))) {
/* new info */
pfirst=(SCAN_STATUS*)malloc(sizeof(SCAN_STATUS));
@ -1266,6 +1267,7 @@ void config_set_status(WS_CONNINFO *pwsc, int session, char *fmt, ...) {
} else {
if(newmsg)
free(newmsg);
ws_unlock_local_storage(pwsc);
return;
}
}
@ -1277,6 +1279,7 @@ void config_set_status(WS_CONNINFO *pwsc, int session, char *fmt, ...) {
pfirst->what=newmsg;
pfirst->session=session;
ws_unlock_local_storage(pwsc);
DPRINTF(E_DBG,L_CONF,"Exiting config_set_status\n");
}

View File

@ -267,6 +267,17 @@ void ws_remove_dispatch_thread(WS_PRIVATE *pwsp, WS_CONNINFO *pwsc) {
if(pthread_mutex_lock(&pwsp->exit_mutex))
DPRINTF(E_FATAL,L_WS,"Cannot lock condition mutex\n");
/* Get rid of the local storage */
if(pwsc->local_storage) {
if(pwsc->storage_callback) {
pwsc->storage_callback(pwsc->local_storage);
pwsc->local_storage=NULL;
} else {
free(pwsc->local_storage);
pwsc->local_storage=NULL;
}
}
pTail=&(pwsp->connlist);
pHead=pwsp->connlist.next;
@ -477,16 +488,6 @@ void ws_close(WS_CONNINFO *pwsc) {
DPRINTF(E_SPAM,L_WS,"Entering ws_close\n");
if(pwsc->local_storage) {
if(pwsc->storage_callback) {
pwsc->storage_callback(pwsc->local_storage);
pwsc->local_storage=NULL;
} else {
free(pwsc->local_storage);
pwsc->local_storage=NULL;
}
}
DPRINTF(E_DBG,L_WS,"Thread %d: Terminating\n",pwsc->threadno);
DPRINTF(E_DBG,L_WS,"Thread %d: Freeing request headers\n",pwsc->threadno);
ws_freearglist(&pwsc->request_headers);
@ -1522,7 +1523,7 @@ char *ws_getrequestheader(WS_CONNINFO *pwsc, char *header) {
}
/**
* get the local storage pointer
* get the local storage pointer.
*
* @param pwsc connection to get local storage for
*/
@ -1530,6 +1531,28 @@ void *ws_get_local_storage(WS_CONNINFO *pwsc) {
return pwsc->local_storage;
}
/**
* lock the local storage pointer. This is sort of wrong, as
* the all operations manipulating local storage are locked,
* not just the one you are working on.
*
* @param pwsc connection you are working with
*/
void ws_lock_local_storage(WS_CONNINFO *pwsc) {
WS_PRIVATE *pwsp;
pwsp = (WS_PRIVATE *)pwsc->pwsp;
ws_lock_connlist(pwsp);
}
void ws_unlock_local_storage(WS_CONNINFO *pwsc) {
WS_PRIVATE *pwsp;
pwsp = (WS_PRIVATE *)pwsc->pwsp;
ws_unlock_connlist(pwsp);
}
/**
* set the local storage pointer (and callback)
*/

View File

@ -79,6 +79,8 @@ extern int ws_registerhandler(WSHANDLE ws, char *regex,
int(*auth)(char *, char *),
int addheaders);
extern void ws_lock_local_storage(WS_CONNINFO *pwsc);
extern void ws_unlock_local_storage(WS_CONNINFO *pwsc);
extern void *ws_get_local_storage(WS_CONNINFO *pwsc);
extern void ws_set_local_storage(WS_CONNINFO *pwsc, void *ptr, void (*callback)(void *));