Navigation


Changeset 16:013ce9851131 in freeDiameter for freeDiameter/p_expiry.c


Ignore:
Timestamp:
Oct 2, 2009, 6:57:06 PM (15 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Started including TLS code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • freeDiameter/p_expiry.c

    r14 r16  
    3636#include "fD.h"
    3737
     38/* Delay for garbage collection of expired threads, in seconds */
     39#define GC_TIME         60
     40
    3841static pthread_t       exp_thr;
     42static pthread_t       gc_thr;
    3943static struct fd_list  exp_list = FD_LIST_INITIALIZER( exp_list );
    4044static pthread_cond_t  exp_cnd  = PTHREAD_COND_INITIALIZER;
    4145static pthread_mutex_t exp_mtx  = PTHREAD_MUTEX_INITIALIZER;
     46
     47static 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       
     87error:
     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
    4294
    4395static void * exp_th_fct(void * arg)
     
    98150        TRACE_ENTRY();
    99151        CHECK_FCT( pthread_create( &exp_thr, NULL, exp_th_fct, NULL ) );
     152        CHECK_FCT( pthread_create( &gc_thr,  NULL, gc_th_fct,  NULL ) );
    100153        return 0;
    101154}
     
    113166       
    114167        CHECK_POSIX( pthread_mutex_unlock(&exp_mtx) );
     168        CHECK_FCT_DO( fd_thr_term(&gc_thr), );
    115169        return 0;
    116170}
Note: See TracChangeset for help on using the changeset viewer.