Changeset 16:013ce9851131 in freeDiameter for freeDiameter/p_expiry.c
- Timestamp:
- Oct 2, 2009, 6:57:06 PM (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
freeDiameter/p_expiry.c
r14 r16 36 36 #include "fD.h" 37 37 38 /* Delay for garbage collection of expired threads, in seconds */ 39 #define GC_TIME 60 40 38 41 static pthread_t exp_thr; 42 static pthread_t gc_thr; 39 43 static struct fd_list exp_list = FD_LIST_INITIALIZER( exp_list ); 40 44 static pthread_cond_t exp_cnd = PTHREAD_COND_INITIALIZER; 41 45 static pthread_mutex_t exp_mtx = PTHREAD_MUTEX_INITIALIZER; 46 47 static void * gc_th_fct(void * arg) 48 { 49 fd_log_threadname ( "Peers/garbage" ); 50 TRACE_ENTRY( "" ); 51 52 do { 53 struct fd_list * li, purge = FD_LIST_INITIALIZER(purge); 54 55 pthread_testcancel(); 56 sleep(GC_TIME); 57 58 /* Now check in the peers list if any peer can be deleted */ 59 CHECK_FCT_DO( pthread_rwlock_wrlock(&fd_g_peers_rw), goto error ); 60 61 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) { 62 struct fd_peer * peer = (struct fd_peer *)li; 63 64 if (peer->p_hdr.info.pi_state != STATE_ZOMBIE) 65 continue; 66 67 if (peer->p_hdr.info.pi_flags.exp == PI_EXP_NONE) 68 continue; /* This peer was not supposed to expire, keep it in the list */ 69 70 /* Ok, the peer was expired, let's remove it */ 71 li = li->prev; /* to avoid breaking the loop */ 72 fd_list_unlink(&peer->p_hdr.chain); 73 fd_list_insert_before(&purge, &peer->p_hdr.chain); 74 } 75 76 CHECK_FCT_DO( pthread_rwlock_unlock(&fd_g_peers_rw), goto error ); 77 78 /* Now delete peers that are in the purge list */ 79 while (!FD_IS_LIST_EMPTY(&purge)) { 80 struct fd_peer * peer = (struct fd_peer *)(purge.next); 81 fd_list_unlink(&peer->p_hdr.chain); 82 TRACE_DEBUG(INFO, "Garbage Collect: delete zombie peer '%s'", peer->p_hdr.info.pi_diamid); 83 CHECK_FCT_DO( fd_peer_free(&peer), /* Continue... what else to do ? */ ); 84 } 85 } while (1); 86 87 error: 88 TRACE_DEBUG(INFO, "An error occurred in peers module! GC thread is terminating..."); 89 ASSERT(0); 90 CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, NULL), ); 91 return NULL; 92 } 93 42 94 43 95 static void * exp_th_fct(void * arg) … … 98 150 TRACE_ENTRY(); 99 151 CHECK_FCT( pthread_create( &exp_thr, NULL, exp_th_fct, NULL ) ); 152 CHECK_FCT( pthread_create( &gc_thr, NULL, gc_th_fct, NULL ) ); 100 153 return 0; 101 154 } … … 113 166 114 167 CHECK_POSIX( pthread_mutex_unlock(&exp_mtx) ); 168 CHECK_FCT_DO( fd_thr_term(&gc_thr), ); 115 169 return 0; 116 170 }
Note: See TracChangeset
for help on using the changeset viewer.