Ejemplo n.º 1
0
static void logging_shutdown(void)
{
    if (thread_suspended_tls_id != -1) {
	pj_thread_local_free(thread_suspended_tls_id);
	thread_suspended_tls_id = -1;
    }
#  if PJ_LOG_ENABLE_INDENT
    if (thread_indent_tls_id != -1) {
	pj_thread_local_free(thread_indent_tls_id);
	thread_indent_tls_id = -1;
    }
#  endif
}
Ejemplo n.º 2
0
/*
 * pj_shutdown(void)
 */
PJ_DEF(void) pj_shutdown()
{
    int i;

    /* Call atexit() functions */
    for (i=atexit_count-1; i>=0; --i) {
	(*atexit_func[i])();
    }
    atexit_count = 0;

    /* Free exception ID */
    if (PJ_NO_MEMORY_EXCEPTION != -1) {
	pj_exception_id_free(PJ_NO_MEMORY_EXCEPTION);
	PJ_NO_MEMORY_EXCEPTION = -1;
    }

#if PJ_HAS_THREADS
    /* Destroy PJLIB critical section */
    pj_mutex_destroy(&critical_section);

    /* Free PJLIB TLS */
    if (thread_tls_id != -1) {
	pj_thread_local_free(thread_tls_id);
	thread_tls_id = -1;
    }
#endif

    /* Clear static variables */
    pj_errno_clear_handlers();
}
Ejemplo n.º 3
0
static void pool_buf_cleanup(void)
{
    if (tls != -1) {
	pj_thread_local_free(tls);
	tls = -1;
    }
    if (is_initialized)
	is_initialized = 0;
}
Ejemplo n.º 4
0
static void logging_shutdown(void)
{
#if PJ_HAS_THREADS
    if (thread_suspended_tls_id != -1) {
	pj_thread_local_free(thread_suspended_tls_id);
	thread_suspended_tls_id = -1;
    }
#endif
}
Ejemplo n.º 5
0
/*
 * mod_ua_unload()
 *
 * Called when module is being unloaded.
 */
static pj_status_t mod_ua_unload(void)
{
    pj_thread_local_free(pjsip_dlg_lock_tls_id);
    pj_mutex_destroy(mod_ua.mutex);

    /* Release pool */
    if (mod_ua.pool) {
	pjsip_endpt_release_pool( mod_ua.endpt, mod_ua.pool );
    }
    return PJ_SUCCESS;
}
Ejemplo n.º 6
0
/*
 * pj_shutdown(void)
 */
PJ_DEF(void) pj_shutdown()
{
    int i;

    /* Only perform shutdown operation when 'initialized' reaches zero */
    pj_assert(initialized > 0);
    if (--initialized != 0)
	return;

    /* Display stack usage */
#if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0
    {
	pj_thread_t *rec = (pj_thread_t*)main_thread;
	PJ_LOG(5,(rec->obj_name, "Main thread stack max usage=%u by %s:%d", 
		  rec->stk_max_usage, rec->caller_file, rec->caller_line));
    }
#endif

    /* Call atexit() functions */
    for (i=atexit_count-1; i>=0; --i) {
	(*atexit_func[i])();
    }
    atexit_count = 0;

    /* Free exception ID */
    if (PJ_NO_MEMORY_EXCEPTION != -1) {
	pj_exception_id_free(PJ_NO_MEMORY_EXCEPTION);
	PJ_NO_MEMORY_EXCEPTION = -1;
    }

    /* Destroy PJLIB critical section */
    pj_mutex_destroy(&critical_section_mutex);

    /* Free PJLIB TLS */
    if (thread_tls_id != -1) {
	pj_thread_local_free(thread_tls_id);
	thread_tls_id = -1;
    }

    /* Clear static variables */
    pj_errno_clear_handlers();

    /* Ticket #1132: Assertion when (re)starting PJLIB on different thread */
    pj_bzero(main_thread, sizeof(main_thread));

    /* Shutdown Winsock */
    WSACleanup();
}
Ejemplo n.º 7
0
static void exception_cleanup(void)
{
    if (thread_local_id != -1) {
	pj_thread_local_free(thread_local_id);
	thread_local_id = -1;
    }

#if defined(PJ_HAS_EXCEPTION_NAMES) && PJ_HAS_EXCEPTION_NAMES != 0
    {
	unsigned i;
	for (i=0; i<PJ_MAX_EXCEPTION_ID; ++i)
	    exception_id_names[i] = NULL;
    }
#else
    last_exception_id = 1;
#endif
}
Ejemplo n.º 8
0
/*
 * pj_shutdown(void)
 */
PJ_DEF(void) pj_shutdown()
{
  int i;

  /* Only perform shutdown operation when 'initialized' reaches zero */
  pj_assert(initialized > 0);
  if (--initialized != 0)
    return;

  /* Call atexit() functions */
  for (i=atexit_count-1; i>=0; --i)
  {
    (*atexit_func[i])();
  }
  atexit_count = 0;

  /* Free exception ID */
  if (PJ_NO_MEMORY_EXCEPTION != -1)
  {
    pj_exception_id_free(PJ_NO_MEMORY_EXCEPTION);
    PJ_NO_MEMORY_EXCEPTION = -1;
  }

  #if PJ_HAS_THREADS
  /* Destroy PJLIB critical section */
  pj_mutex_destroy(&critical_section);

  /* Free PJLIB TLS */
  if (thread_tls_id != -1)
  {
    pj_thread_local_free(thread_tls_id);
    thread_tls_id = -1;
  }

  /* Ticket #1132: Assertion when (re)starting PJLIB on different thread */
  pj_bzero(&main_thread, sizeof(main_thread));
  #endif

  /* Clear static variables */
  pj_errno_clear_handlers();
}
Ejemplo n.º 9
0
pj_status_t pj_log_init(void)
{
#if PJ_HAS_THREADS
    if (thread_suspended_tls_id == -1) {
	pj_status_t status;
	status = pj_thread_local_alloc(&thread_suspended_tls_id);
	if (status != PJ_SUCCESS)
	    return status;

#  if PJ_LOG_ENABLE_INDENT
	status = pj_thread_local_alloc(&thread_indent_tls_id);
	if (status != PJ_SUCCESS) {
	    pj_thread_local_free(thread_suspended_tls_id);
	    thread_suspended_tls_id = -1;
	    return status;
	}
#  endif
	pj_atexit(&logging_shutdown);
    }
#endif
    g_last_thread = NULL;
    return PJ_SUCCESS;
}
Ejemplo n.º 10
0
 //
 // Free TLS index.
 //
 static void free(long index)
 {
     pj_thread_local_free(index);
 }
Ejemplo n.º 11
0
/*
 * Destroy the server.
 */
PJ_DEF(pj_status_t) pj_turn_srv_destroy(pj_turn_srv *srv)
{
    pj_hash_iterator_t itbuf, *it;
    unsigned i;

    /* Stop all worker threads */
    srv->core.quit = PJ_TRUE;
    for (i=0; i<srv->core.thread_cnt; ++i) {
	if (srv->core.thread[i]) {
	    pj_thread_join(srv->core.thread[i]);
	    pj_thread_destroy(srv->core.thread[i]);
	    srv->core.thread[i] = NULL;
	}
    }

    /* Destroy all allocations FIRST */
    if (srv->tables.alloc) {
	it = pj_hash_first(srv->tables.alloc, &itbuf);
	while (it != NULL) {
	    pj_turn_allocation *alloc = (pj_turn_allocation*)
					pj_hash_this(srv->tables.alloc, it);
	    pj_hash_iterator_t *next = pj_hash_next(srv->tables.alloc, it);
	    pj_turn_allocation_destroy(alloc);
	    it = next;
	}
    }
    
    /* Destroy all listeners. */
    for (i=0; i<srv->core.lis_cnt; ++i) {
	if (srv->core.listener[i]) {
	    pj_turn_listener_destroy(srv->core.listener[i]);
	    srv->core.listener[i] = NULL;
	}
    }

    /* Destroy STUN session */
    if (srv->core.stun_sess) {
	pj_stun_session_destroy(srv->core.stun_sess);
	srv->core.stun_sess = NULL;
    }

    /* Destroy hash tables (well, sort of) */
    if (srv->tables.alloc) {
	srv->tables.alloc = NULL;
	srv->tables.res = NULL;
    }
    
    /* Destroy timer heap */
    if (srv->core.timer_heap) {
	pj_timer_heap_destroy(srv->core.timer_heap);
	srv->core.timer_heap = NULL;
    }

    /* Destroy ioqueue */
    if (srv->core.ioqueue) {
	pj_ioqueue_destroy(srv->core.ioqueue);
	srv->core.ioqueue = NULL;
    }

    /* Destroy thread local IDs */
    if (srv->core.tls_key != -1) {
	pj_thread_local_free(srv->core.tls_key);
	srv->core.tls_key = -1;
    }
    if (srv->core.tls_data != -1) {
	pj_thread_local_free(srv->core.tls_data);
	srv->core.tls_data = -1;
    }

    /* Destroy server lock */
    if (srv->core.lock) {
	pj_lock_destroy(srv->core.lock);
	srv->core.lock = NULL;
    }

    /* Release pool */
    if (srv->core.pool) {
	pj_pool_t *pool = srv->core.pool;
	srv->core.pool = NULL;
	pj_pool_release(pool);
    }

    /* Done */
    return PJ_SUCCESS;
}