Mercurial > hg > waaad
changeset 232:65efaa0c849b
Resolution for the deadlock
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Tue, 11 Nov 2008 16:18:42 +0900 |
parents | ebd37fdf7a99 |
children | fa76f88326fd |
files | waaad/peer-events.c waaad/peer-in.c waaad/peer-internal.h waaad/peer-psm.c |
diffstat | 4 files changed, 23 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/waaad/peer-events.c Thu Nov 06 18:21:12 2008 +0900 +++ b/waaad/peer-events.c Tue Nov 11 16:18:42 2008 +0900 @@ -70,14 +70,25 @@ } /* Send an event to a peer from outside; the peer lock must not be held. */ +/* Periodical check for cancelation state when trying to lock the mutex. */ int _peer_events_send(_peer_t * peer, _pevent_t event, void * data) { int ret = 0; CHECK_PARAMS( VALIDATE_PEER( peer ) ); - /* lock the peer */ - CHECK_POSIX( pthread_mutex_lock(&peer->p_lock) ); + /* loop until we suceed to lock the peer. */ + do { + struct timespec to; + CHECK_SYS( clock_gettime(CLOCK_REALTIME, &to) ); + to.tv_sec += 1; /* one second timeout */ + + pthread_testcancel(); + + ret = pthread_mutex_timedlock( &peer->p_lock, &to ); + } while (ret == ETIMEDOUT); + + CHECK_POSIX(ret); /* Create and queue the event */ CHECK_FCT_DO( ret = _peer_events_send_nl(peer, event, data), /* continue */ );
--- a/waaad/peer-in.c Thu Nov 06 18:21:12 2008 +0900 +++ b/waaad/peer-in.c Tue Nov 11 16:18:42 2008 +0900 @@ -76,8 +76,8 @@ CHECK_PARAMS_DO(VALIDATE_PEER( peer ), goto end); CHECK_PARAMS_DO(peer->p_secmod, goto error); - /* loop until error / cancellation */ - while (1) { + /* loop until error / cancellation if using a real security module, once only otherwise */ + do { int ret; msg_t * msg; msg_data_t * values; @@ -186,7 +186,9 @@ CHECK_FCT_DO( _peer_events_send(peer, PEVENT_MSGRCVD, NULL), goto error ); /* loop to next received message */ - } + } while (peer->p_sec_hdl != NULL); + + goto end; error: /* Signal the parent thread that we have terminated */
--- a/waaad/peer-internal.h Thu Nov 06 18:21:12 2008 +0900 +++ b/waaad/peer-internal.h Tue Nov 11 16:18:42 2008 +0900 @@ -467,6 +467,7 @@ int _peer_events_send_nl(_peer_t * peer, _pevent_t event, void * data); int _peer_events_send(_peer_t * peer, _pevent_t event, void * data); +int _peer_events_send_ltc(_peer_t * peer, _pevent_t event, void * data); void _peer_events_dispose_data( _pevent_t event, void ** data ); void _peer_events_reset( _peer_t * peer );
--- a/waaad/peer-psm.c Thu Nov 06 18:21:12 2008 +0900 +++ b/waaad/peer-psm.c Tue Nov 11 16:18:42 2008 +0900 @@ -978,10 +978,10 @@ /* PEVENT_ASSOC_CHG */ { _psm_NOTSUP }, /* PEVENT_PEERADDR_CHG */ { _psm_NOTSUP }, /* PEVENT_REMOTE_ERR */ { _psm_NOTSUP }, - /* PEVENT_DISCONNECTED */ { _psm_NOTSUP }, - /* PEVENT_SND_FAILED */ { _psm_NOTSUP }, - /* PEVENT_TH_TERM_IN */ { _psm_NOTSUP }, - /* PEVENT_TH_TERM_OUT */ { _psm_NOTSUP } + /* PEVENT_DISCONNECTED */ { _psm_reset }, + /* PEVENT_SND_FAILED */ { _psm_reset }, + /* PEVENT_TH_TERM_IN */ { _psm_reset }, + /* PEVENT_TH_TERM_OUT */ { _psm_reset } }, /* STATE_REOPEN */ { /* PEVENT_SHUTDOWN */ { _psm_NOTSUP },