static pj_status_t pool_buf_initialize() { pj_atexit(&pool_buf_cleanup); stack_based_factory.policy.block_alloc = &stack_alloc; return pj_thread_local_alloc(&tls); }
/* * mod_ua_load() * * Called when module is being loaded by endpoint. */ static pj_status_t mod_ua_load(pjsip_endpoint *endpt) { pj_status_t status; /* Initialize the user agent. */ mod_ua.endpt = endpt; mod_ua.pool = pjsip_endpt_create_pool( endpt, "ua%p", PJSIP_POOL_LEN_UA, PJSIP_POOL_INC_UA); if (mod_ua.pool == NULL) return PJ_ENOMEM; status = pj_mutex_create_recursive(mod_ua.pool, " ua%p", &mod_ua.mutex); if (status != PJ_SUCCESS) return status; mod_ua.dlg_table = pj_hash_create(mod_ua.pool, PJSIP_MAX_DIALOG_COUNT); if (mod_ua.dlg_table == NULL) return PJ_ENOMEM; pj_list_init(&mod_ua.free_dlgset_nodes); /* Initialize dialog lock. */ status = pj_thread_local_alloc(&pjsip_dlg_lock_tls_id); if (status != PJ_SUCCESS) return status; pj_thread_local_set(pjsip_dlg_lock_tls_id, NULL); return PJ_SUCCESS; }
pj_status_t pj_log_init(void) { #if PJ_HAS_THREADS if (thread_suspended_tls_id == -1) { pj_thread_local_alloc(&thread_suspended_tls_id); pj_atexit(&logging_shutdown); } #endif return PJ_SUCCESS; }
pj_status_t pj_thread_init(void) { pj_status_t rc; pj_thread_t *dummy; rc = pj_thread_local_alloc(&thread_tls_id); if (rc != PJ_SUCCESS) return rc; return pj_thread_register("pjlib-main", (long*)&main_thread, &dummy); }
/* * pj_thread_init(void) */ pj_status_t pj_thread_init(void) { pj_status_t rc; pj_thread_t *thread; rc = pj_thread_local_alloc(&thread_tls_id); if (rc != PJ_SUCCESS) return rc; return pj_thread_register("thr%p", main_thread, &thread); }
pj_status_t pj_thread_init(void) { thread_tls_id = pj_thread_local_alloc(); if (thread_tls_id == -1) return -1; if (pj_thread_register("thr%p", main_thread) == NULL) return -1; return PJ_OK; }
PJ_DEF(void) pj_push_exception_handler_(struct pj_exception_state_t *rec) { struct pj_exception_state_t *parent_handler = NULL; if (thread_local_id == -1) { pj_thread_local_alloc(&thread_local_id); pj_assert(thread_local_id != -1); pj_atexit(&exception_cleanup); } parent_handler = pj_thread_local_get(thread_local_id); rec->prev = parent_handler; pj_thread_local_set(thread_local_id, rec); }
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; }
/* * pj_thread_init(void) */ pj_status_t pj_thread_init(void) { #if PJ_HAS_THREADS pj_status_t rc; pj_thread_t *dummy; rc = pj_thread_local_alloc(&thread_tls_id ); if (rc != PJ_SUCCESS) { return rc; } return pj_thread_register("thr%p", (long*)&main_thread, &dummy); #else PJ_LOG(2,(THIS_FILE, "Thread init error. Threading is not enabled!")); return PJ_EINVALIDOP; #endif }
pj_status_t pj_thread_init(void) { #if PJ_HAS_THREADS pj_memset(&main_thread, 0, sizeof(main_thread)); main_thread.thread = pthread_self(); sprintf(main_thread.obj_name, "thr%p", &main_thread); thread_tls_id = pj_thread_local_alloc(); if (thread_tls_id == -1) { return -1; } pj_thread_local_set(thread_tls_id, &main_thread); return PJ_OK; #else PJ_LOG(2,(THIS_FILE, "Thread init error. Threading is not enabled!")); return -1; #endif }
// // Allocate thread local storage (TLS) index. // static pj_status_t alloc(long *index) { return pj_thread_local_alloc(index); }
/* * Create server. */ PJ_DEF(pj_status_t) pj_turn_srv_create(pj_pool_factory *pf, pj_turn_srv **p_srv) { pj_pool_t *pool; pj_stun_session_cb sess_cb; pj_turn_srv *srv; unsigned i; pj_status_t status; PJ_ASSERT_RETURN(pf && p_srv, PJ_EINVAL); /* Create server and init core settings */ pool = pj_pool_create(pf, "srv%p", 1000, 1000, NULL); srv = PJ_POOL_ZALLOC_T(pool, pj_turn_srv); srv->obj_name = pool->obj_name; srv->core.pf = pf; srv->core.pool = pool; srv->core.tls_key = srv->core.tls_data = -1; /* Create ioqueue */ status = pj_ioqueue_create(pool, MAX_HANDLES, &srv->core.ioqueue); if (status != PJ_SUCCESS) goto on_error; /* Server mutex */ status = pj_lock_create_recursive_mutex(pool, srv->obj_name, &srv->core.lock); if (status != PJ_SUCCESS) goto on_error; /* Allocate TLS */ status = pj_thread_local_alloc(&srv->core.tls_key); if (status != PJ_SUCCESS) goto on_error; status = pj_thread_local_alloc(&srv->core.tls_data); if (status != PJ_SUCCESS) goto on_error; /* Create timer heap */ status = pj_timer_heap_create(pool, MAX_TIMER, &srv->core.timer_heap); if (status != PJ_SUCCESS) goto on_error; /* Configure lock for the timer heap */ pj_timer_heap_set_lock(srv->core.timer_heap, srv->core.lock, PJ_FALSE); /* Array of listeners */ srv->core.listener = (pj_turn_listener**) pj_pool_calloc(pool, MAX_LISTENERS, sizeof(srv->core.listener[0])); /* Create hash tables */ srv->tables.alloc = pj_hash_create(pool, MAX_CLIENTS); srv->tables.res = pj_hash_create(pool, MAX_CLIENTS); /* Init ports settings */ srv->ports.min_udp = srv->ports.next_udp = MIN_PORT; srv->ports.max_udp = MAX_PORT; srv->ports.min_tcp = srv->ports.next_tcp = MIN_PORT; srv->ports.max_tcp = MAX_PORT; /* Init STUN config */ pj_stun_config_init(&srv->core.stun_cfg, pf, 0, srv->core.ioqueue, srv->core.timer_heap); /* Init STUN credential */ srv->core.cred.type = PJ_STUN_AUTH_CRED_DYNAMIC; srv->core.cred.data.dyn_cred.user_data = srv; srv->core.cred.data.dyn_cred.get_auth = &pj_turn_get_auth; srv->core.cred.data.dyn_cred.get_password = &pj_turn_get_password; srv->core.cred.data.dyn_cred.verify_nonce = &pj_turn_verify_nonce; /* Create STUN session to handle new allocation */ pj_bzero(&sess_cb, sizeof(sess_cb)); sess_cb.on_rx_request = &on_rx_stun_request; sess_cb.on_send_msg = &on_tx_stun_msg; status = pj_stun_session_create(&srv->core.stun_cfg, srv->obj_name, &sess_cb, PJ_FALSE, NULL, &srv->core.stun_sess); if (status != PJ_SUCCESS) { goto on_error; } pj_stun_session_set_user_data(srv->core.stun_sess, srv); pj_stun_session_set_credential(srv->core.stun_sess, PJ_STUN_AUTH_LONG_TERM, &srv->core.cred); /* Array of worker threads */ srv->core.thread_cnt = MAX_THREADS; srv->core.thread = (pj_thread_t**) pj_pool_calloc(pool, srv->core.thread_cnt, sizeof(pj_thread_t*)); /* Start the worker threads */ for (i=0; i<srv->core.thread_cnt; ++i) { status = pj_thread_create(pool, srv->obj_name, &server_thread_proc, srv, 0, 0, &srv->core.thread[i]); if (status != PJ_SUCCESS) goto on_error; } /* We're done. Application should add listeners now */ PJ_LOG(4,(srv->obj_name, "TURN server v%s is running", pj_get_version())); *p_srv = srv; return PJ_SUCCESS; on_error: pj_turn_srv_destroy(srv); return status; }