void tm_shutdown() { DBG("DEBUG: tm_shutdown : start\n"); /* destroy the hash table */ DBG("DEBUG: tm_shutdown : emptying hash table\n"); free_hash_table( ); DBG("DEBUG: tm_shutdown : removing semaphores\n"); lock_cleanup(); DBG("DEBUG: tm_shutdown : destroying tmcb lists\n"); destroy_tmcb_lists(); free_tm_stats(); DBG("DEBUG: tm_shutdown : done\n"); }
void tm_shutdown(void) { LM_DBG("tm_shutdown : start\n"); unlink_timer_lists(); /* destroy the hash table */ LM_DBG("emptying hash table\n"); free_hash_table( ); LM_DBG("releasing timers\n"); free_timer_table(); LM_DBG("removing semaphores\n"); lock_cleanup(); LM_DBG("destroying callback lists\n"); destroy_tmcb_lists(); LM_DBG("tm_shutdown : done\n"); }
/* initialize the locks; return 0 on success, -1 otherwise */ int lock_initialize() { #ifndef GEN_LOCK_T_PREFERED int i; int probe_run; #endif /* first try allocating semaphore sets with fixed number of semaphores */ DBG("DEBUG: lock_initialize: lock initialization started\n"); #ifndef GEN_LOCK_T_PREFERED i=SEM_MIN; /* probing phase: 0=initial, 1=after the first failure */ probe_run=0; again: do { if (entry_semaphore!=0){ /* clean-up previous attempt */ lock_set_destroy(entry_semaphore); lock_set_dealloc(entry_semaphore); } if (reply_semaphore!=0){ lock_set_destroy(reply_semaphore); lock_set_dealloc(reply_semaphore); } #ifdef ENABLE_ASYNC_MUTEX if (async_semaphore!=0){ lock_set_destroy(async_semaphore); lock_set_dealloc(async_semaphore); } #endif if (i==0){ LOG(L_CRIT, "lock_initialize: could not allocate semaphore" " sets\n"); goto error; } if (((entry_semaphore=lock_set_alloc(i))==0)|| (lock_set_init(entry_semaphore)==0)) { DBG("DEBUG: lock_initialize: entry semaphore " "initialization failure: %s\n", strerror( errno ) ); if (entry_semaphore){ lock_set_dealloc(entry_semaphore); entry_semaphore=0; } /* first time: step back and try again */ if (probe_run==0) { DBG("DEBUG: lock_initialize: first time " "semaphore allocation failure\n"); i--; probe_run=1; continue; /* failure after we stepped back; give up */ } else { DBG("DEBUG: lock_initialize: second time semaphore" " allocation failure\n"); goto error; } } /* allocation succeeded */ if (probe_run==1) { /* if ok after we stepped back, we're done */ break; } else { /* if ok otherwise, try again with larger set */ if (i==SEM_MAX) break; else { i++; continue; } } } while(1); sem_nr=i; if (((reply_semaphore=lock_set_alloc(i))==0)|| (lock_set_init(reply_semaphore)==0)){ if (reply_semaphore){ lock_set_dealloc(reply_semaphore); reply_semaphore=0; } DBG("DEBUG:lock_initialize: reply semaphore initialization" " failure: %s\n", strerror(errno)); probe_run=1; i--; goto again; } #ifdef ENABLE_ASYNC_MUTEX i++; if (((async_semaphore=lock_set_alloc(i))==0)|| (lock_set_init(async_semaphore)==0)){ if (async_semaphore){ lock_set_dealloc(async_semaphore); async_semaphore=0; } DBG("DEBUG:lock_initialize: async semaphore initialization" " failure: %s\n", strerror(errno)); probe_run=1; i--; goto again; } #endif /* return success */ LOG(L_INFO, "INFO: semaphore arrays of size %d allocated\n", sem_nr ); #endif /* GEN_LOCK_T_PREFERED*/ return 0; #ifndef GEN_LOCK_T_PREFERED error: lock_cleanup(); return -1; #endif }
/* initialize the locks; return 0 on success, -1 otherwise */ int lock_initialize(void) { int i; #ifndef GEN_LOCK_T_PREFERED int probe_run; #endif /* first try allocating semaphore sets with fixed number of semaphores */ LM_DBG("lock initialization started\n"); timer_group_lock=shm_malloc(TG_NR*sizeof(ser_lock_t)); if (timer_group_lock==0){ LM_CRIT("no more share mem\n"); goto error; } #ifdef GEN_LOCK_T_PREFERED for(i=0;i<TG_NR;i++) lock_init(&timer_group_lock[i]); #else /* transaction timers */ if (((timer_semaphore= lock_set_alloc( TG_NR ) ) == 0)|| (lock_set_init(timer_semaphore)==0)){ if (timer_semaphore) lock_set_destroy(timer_semaphore); LM_CRIT("transaction timer semaphore initialization failure: %s\n", strerror(errno)); goto error; } for (i=0; i<TG_NR; i++) { timer_group_lock[i].semaphore_set = timer_semaphore; timer_group_lock[i].semaphore_index = timer_group[ i ]; } i=SEM_MIN; /* probing phase: 0=initial, 1=after the first failure */ probe_run=0; again: do { if (entry_semaphore!=0){ /* clean-up previous attempt */ lock_set_destroy(entry_semaphore); lock_set_dealloc(entry_semaphore); } if (reply_semaphore!=0){ lock_set_destroy(reply_semaphore); lock_set_dealloc(reply_semaphore); } if (i==0){ LM_CRIT("failed allocate semaphore sets\n"); goto error; } if (((entry_semaphore=lock_set_alloc(i))==0)|| (lock_set_init(entry_semaphore)==0)) { LM_DBG("entry semaphore initialization failure: %s\n", strerror( errno ) ); if (entry_semaphore){ lock_set_dealloc(entry_semaphore); entry_semaphore=0; } /* first time: step back and try again */ if (probe_run==0) { LM_DBG("first time semaphore allocation failure\n"); i--; probe_run=1; continue; /* failure after we stepped back; give up */ } else { LM_DBG("second time semaphore allocation failure\n"); goto error; } } /* allocation succeeded */ if (probe_run==1) { /* if ok after we stepped back, we're done */ break; } else { /* if ok otherwise, try again with larger set */ if (i==SEM_MAX) break; else { i++; continue; } } } while(1); sem_nr=i; if (((reply_semaphore=lock_set_alloc(i))==0)|| (lock_set_init(reply_semaphore)==0)){ if (reply_semaphore){ lock_set_dealloc(reply_semaphore); reply_semaphore=0; } LM_DBG("reply semaphore initialization failure: %s\n", strerror(errno)); probe_run=1; i--; goto again; } /* return success */ LM_INFO("semaphore arrays of size %d allocated\n", sem_nr ); #endif /* GEN_LOCK_T_PREFERED*/ return 0; error: lock_cleanup(); return -1; }