Mercurial > hg > freeDiameter
comparison freeDiameter/p_psm.c @ 454:f1484823cb4a
Small hack which might spear some concurrency problems and is quite harmless
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Thu, 29 Jul 2010 16:11:12 +0900 |
parents | 26aafbbc1640 |
children |
comparison
equal
deleted
inserted
replaced
453:9a8b3178a7a7 | 454:f1484823cb4a |
---|---|
181 { | 181 { |
182 int old; | 182 int old; |
183 | 183 |
184 TRACE_ENTRY("%p %d(%s)", peer, new_state, STATE_STR(new_state)); | 184 TRACE_ENTRY("%p %d(%s)", peer, new_state, STATE_STR(new_state)); |
185 CHECK_PARAMS( CHECK_PEER(peer) ); | 185 CHECK_PARAMS( CHECK_PEER(peer) ); |
186 fd_cpu_flush_cache(); | |
186 old = peer->p_hdr.info.runtime.pir_state; | 187 old = peer->p_hdr.info.runtime.pir_state; |
187 if (old == new_state) | 188 if (old == new_state) |
188 return 0; | 189 return 0; |
189 | 190 |
190 TRACE_DEBUG(((old == STATE_OPEN) || (new_state == STATE_OPEN)) ? INFO : FULL, "'%s'\t-> '%s'\t'%s'", | 191 TRACE_DEBUG(((old == STATE_OPEN) || (new_state == STATE_OPEN)) ? INFO : FULL, "'%s'\t-> '%s'\t'%s'", |
191 STATE_STR(old), | 192 STATE_STR(old), |
192 STATE_STR(new_state), | 193 STATE_STR(new_state), |
193 peer->p_hdr.info.pi_diamid); | 194 peer->p_hdr.info.pi_diamid); |
194 | 195 |
195 peer->p_hdr.info.runtime.pir_state = new_state; | 196 peer->p_hdr.info.runtime.pir_state = new_state; |
197 fd_cpu_flush_cache(); | |
196 | 198 |
197 if (old == STATE_OPEN) { | 199 if (old == STATE_OPEN) { |
198 CHECK_FCT( leave_open_state(peer) ); | 200 CHECK_FCT( leave_open_state(peer) ); |
199 } | 201 } |
200 | 202 |
248 | 250 |
249 /* Cleanup the peer */ | 251 /* Cleanup the peer */ |
250 void fd_psm_cleanup(struct fd_peer * peer, int terminate) | 252 void fd_psm_cleanup(struct fd_peer * peer, int terminate) |
251 { | 253 { |
252 /* Move to CLOSED state: failover messages, stop OUT thread, unlink peer from active list */ | 254 /* Move to CLOSED state: failover messages, stop OUT thread, unlink peer from active list */ |
255 fd_cpu_flush_cache(); | |
253 if (peer->p_hdr.info.runtime.pir_state != STATE_ZOMBIE) { | 256 if (peer->p_hdr.info.runtime.pir_state != STATE_ZOMBIE) { |
254 CHECK_FCT_DO( fd_psm_change_state(peer, STATE_CLOSED), /* continue */ ); | 257 CHECK_FCT_DO( fd_psm_change_state(peer, STATE_CLOSED), /* continue */ ); |
255 } | 258 } |
256 | 259 |
257 fd_p_cnx_abort(peer, terminate); | 260 fd_p_cnx_abort(peer, terminate); |
278 void cleanup_setstate(void * arg) | 281 void cleanup_setstate(void * arg) |
279 { | 282 { |
280 struct fd_peer * peer = (struct fd_peer *)arg; | 283 struct fd_peer * peer = (struct fd_peer *)arg; |
281 CHECK_PARAMS_DO( CHECK_PEER(peer), return ); | 284 CHECK_PARAMS_DO( CHECK_PEER(peer), return ); |
282 peer->p_hdr.info.runtime.pir_state = STATE_ZOMBIE; | 285 peer->p_hdr.info.runtime.pir_state = STATE_ZOMBIE; |
286 fd_cpu_flush_cache(); | |
283 return; | 287 return; |
284 } | 288 } |
285 | 289 |
286 /* The state machine thread (controler) */ | 290 /* The state machine thread (controler) */ |
287 static void * p_psm_th( void * arg ) | 291 static void * p_psm_th( void * arg ) |
303 fd_log_threadname ( buf ); | 307 fd_log_threadname ( buf ); |
304 } | 308 } |
305 | 309 |
306 /* The state machine starts in CLOSED state */ | 310 /* The state machine starts in CLOSED state */ |
307 peer->p_hdr.info.runtime.pir_state = STATE_CLOSED; | 311 peer->p_hdr.info.runtime.pir_state = STATE_CLOSED; |
308 | 312 |
309 /* Wait that the PSM are authorized to start in the daemon */ | 313 /* Wait that the PSM are authorized to start in the daemon */ |
310 CHECK_FCT_DO( fd_psm_waitstart(), goto psm_end ); | 314 CHECK_FCT_DO( fd_psm_waitstart(), goto psm_end ); |
311 | 315 |
312 /* Initialize the timer */ | 316 /* Initialize the timer */ |
313 if (peer->p_flags.pf_responder) { | 317 if (peer->p_flags.pf_responder) { |
706 fd_psm_cleanup(peer, 1); | 710 fd_psm_cleanup(peer, 1); |
707 TRACE_DEBUG(INFO, "'%s'\t-> STATE_ZOMBIE (terminated)\t'%s'", | 711 TRACE_DEBUG(INFO, "'%s'\t-> STATE_ZOMBIE (terminated)\t'%s'", |
708 STATE_STR(peer->p_hdr.info.runtime.pir_state), | 712 STATE_STR(peer->p_hdr.info.runtime.pir_state), |
709 peer->p_hdr.info.pi_diamid); | 713 peer->p_hdr.info.pi_diamid); |
710 pthread_cleanup_pop(1); /* set STATE_ZOMBIE */ | 714 pthread_cleanup_pop(1); /* set STATE_ZOMBIE */ |
715 fd_cpu_flush_cache(); | |
711 peer->p_psm = (pthread_t)NULL; | 716 peer->p_psm = (pthread_t)NULL; |
712 pthread_detach(pthread_self()); | 717 pthread_detach(pthread_self()); |
713 return NULL; | 718 return NULL; |
714 } | 719 } |
715 | 720 |
739 int fd_psm_terminate(struct fd_peer * peer, char * reason ) | 744 int fd_psm_terminate(struct fd_peer * peer, char * reason ) |
740 { | 745 { |
741 TRACE_ENTRY("%p", peer); | 746 TRACE_ENTRY("%p", peer); |
742 CHECK_PARAMS( CHECK_PEER(peer) ); | 747 CHECK_PARAMS( CHECK_PEER(peer) ); |
743 | 748 |
749 fd_cpu_flush_cache(); | |
744 if (peer->p_hdr.info.runtime.pir_state != STATE_ZOMBIE) { | 750 if (peer->p_hdr.info.runtime.pir_state != STATE_ZOMBIE) { |
745 CHECK_FCT( fd_event_send(peer->p_events, FDEVP_TERMINATE, 0, reason) ); | 751 CHECK_FCT( fd_event_send(peer->p_events, FDEVP_TERMINATE, 0, reason) ); |
746 } else { | 752 } else { |
747 TRACE_DEBUG(FULL, "Peer '%s' was already terminated", peer->p_hdr.info.pi_diamid); | 753 TRACE_DEBUG(FULL, "Peer '%s' was already terminated", peer->p_hdr.info.pi_diamid); |
748 } | 754 } |