PJ_DEF(pj_status_t) pj_exception_id_free( pj_exception_id_t id ) { /* * Start from 1 (not 0)!!! * Exception 0 is reserved for normal path of setjmp()!!! */ PJ_ASSERT_RETURN(id>0 && id<PJ_MAX_EXCEPTION_ID, PJ_EINVAL); pj_enter_critical_section(); exception_id_names[id] = NULL; pj_leave_critical_section(); return PJ_SUCCESS; }
PJ_DEF(void) pj_grp_lock_t::pj_grp_lock_dump() { #if PJ_GRP_LOCK_DEBUG grp_lock_ref *ref = grp_lock->ref_list.next; char info_buf[1000]; pj_str_t info; info.ptr = info_buf; info.slen = 0; pj_grp_lock_acquire(grp_lock); pj_enter_critical_section(); while (ref != &grp_lock->ref_list && info.slen < sizeof(info_buf)) { char *start = info.ptr + info.slen; int max_len = sizeof(info_buf) - info.slen; int len; len = pj_ansi_snprintf(start, max_len, "%s:%d ", ref->file, ref->line); if (len < 1 || len >= max_len) { len = strlen(ref->file); if (len > max_len - 1) len = max_len - 1; memcpy(start, ref->file, len); start[len++] = ' '; } info.slen += len; ref = ref->next; } if (ref != &grp_lock->ref_list) { int i; for (i=0; i<4; ++i) info_buf[sizeof(info_buf)-i-1] = '.'; } info.ptr[info.slen-1] = '\0'; pj_leave_critical_section(); pj_grp_lock_release(grp_lock); PJ_LOG(4,(THIS_FILE, "Group lock %p, ref_cnt=%d. Reference holders: %s", grp_lock, pj_grp_lock_get_ref(grp_lock), info.ptr)); #endif }
PJ_DEF(pj_status_t) pjmedia_endpt_atexit( pjmedia_endpt *endpt, pjmedia_endpt_exit_callback func) { exit_cb *new_cb; PJ_ASSERT_RETURN(endpt && func, PJ_EINVAL); if (endpt->quit_flag) return PJ_EINVALIDOP; new_cb = PJ_POOL_ZALLOC_T(endpt->pool, exit_cb); new_cb->func = func; pj_enter_critical_section(); pj_list_push_back(&endpt->exit_cb_list, new_cb); pj_leave_critical_section(); return PJ_SUCCESS; }
PJ_DEF(pj_status_t) pj_exception_id_alloc( const char *name, pj_exception_id_t *id) { unsigned i; pj_enter_critical_section(); /* * Start from 1 (not 0)!!! * Exception 0 is reserved for normal path of setjmp()!!! */ for (i=1; i<PJ_MAX_EXCEPTION_ID; ++i) { if (exception_id_names[i] == NULL) { exception_id_names[i] = name; *id = i; pj_leave_critical_section(); return PJ_SUCCESS; } } pj_leave_critical_section(); return PJ_ETOOMANY; }
// Find 1st Jan 1970 as a FILETIME static pj_status_t get_base_time(void) { SYSTEMTIME st; FILETIME ft; pj_status_t status = PJ_SUCCESS; memset(&st,0,sizeof(st)); st.wYear=1970; st.wMonth=1; st.wDay=1; SystemTimeToFileTime(&st, &ft); base_time.LowPart = ft.dwLowDateTime; base_time.HighPart = ft.dwHighDateTime; base_time.QuadPart /= SECS_TO_FT_MULT; #ifdef WINCE_TIME pj_enter_critical_section(); status = init_start_time(); pj_leave_critical_section(); #endif return status; }
static int timer_initialize() { pj_status_t rc; pj_mutex_t* temp_mutex; rc = pj_mutex_create_simple(timer_pool, "zrtp_timer", &temp_mutex); if (rc != PJ_SUCCESS) { return rc; } pj_enter_critical_section(); if (timer_mutex == NULL) timer_mutex = temp_mutex; else pj_mutex_destroy(temp_mutex); pj_leave_critical_section(); pj_mutex_lock(timer_mutex); if (timer_initialized) { pj_mutex_unlock(timer_mutex); return PJ_SUCCESS; } rc = pj_timer_heap_create(timer_pool, 4, &timer); if (rc != PJ_SUCCESS) { goto ERROR; } rc = pj_sem_create(timer_pool, "zrtp_timer", 0, 1, &timer_sem); if (rc != PJ_SUCCESS) { goto ERROR; } rc = pj_thread_create(timer_pool, "zrtp_timer", &timer_thread_run, NULL, PJ_THREAD_DEFAULT_STACK_SIZE, 0, &thread_run); if (rc != PJ_SUCCESS) { goto ERROR; } timer_initialized = 1; pj_mutex_unlock(timer_mutex); return PJ_SUCCESS; ERROR: if (timer != NULL) { pj_timer_heap_destroy(timer); timer = NULL; } if (timer_sem != NULL) { pj_sem_destroy(timer_sem); timer_sem = NULL; } if (timer_mutex != NULL) { pj_mutex_unlock(timer_mutex); pj_mutex_destroy(timer_mutex); timer_mutex = NULL; } return rc; }