Ignore:
Timestamp:
Dec 12, 2017 7:44:09 AM (6 years ago)
Author:
nanang
Message:

Fixed #2074: Introduced compile time setting PJSUA_SEPARATE_WORKER_FOR_TIMER to allow separate polling for timer events and network events.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r5686 r5712  
    104104 
    105105    cfg->max_calls = ((PJSUA_MAX_CALLS) < 4) ? (PJSUA_MAX_CALLS) : 4; 
    106     cfg->thread_cnt = 1; 
     106    cfg->thread_cnt = PJSUA_SEPARATE_WORKER_FOR_TIMER? 2 : 1; 
    107107    cfg->nat_type_in_sdp = 1; 
    108108    cfg->stun_ignore_failure = PJ_TRUE; 
     
    710710} 
    711711 
     712/* Timer heap worker thread function. */ 
     713static int worker_thread_timer(void *arg) 
     714{ 
     715    pj_timer_heap_t *th; 
     716 
     717    PJ_UNUSED_ARG(arg); 
     718 
     719    th = pjsip_endpt_get_timer_heap(pjsua_var.endpt); 
     720    while (!pjsua_var.thread_quit_flag) { 
     721        pj_time_val timeout = {0, 0}; 
     722        int c; 
     723 
     724        c = pj_timer_heap_poll(th, &timeout); 
     725        if (c == 0) { 
     726            /* Sleep if no event */ 
     727            enum { MAX_SLEEP_MS = 100 }; 
     728            if (PJ_TIME_VAL_MSEC(timeout) < MAX_SLEEP_MS) 
     729                pj_thread_sleep(PJ_TIME_VAL_MSEC(timeout)); 
     730            else 
     731                pj_thread_sleep(MAX_SLEEP_MS); 
     732        } 
     733    } 
     734    return 0; 
     735} 
     736 
     737/* Ioqueue worker thread function. */ 
     738static int worker_thread_ioqueue(void *arg) 
     739{ 
     740    pj_ioqueue_t *ioq; 
     741 
     742    PJ_UNUSED_ARG(arg); 
     743 
     744    ioq = pjsip_endpt_get_ioqueue(pjsua_var.endpt); 
     745    while (!pjsua_var.thread_quit_flag) { 
     746        pj_time_val timeout = {0, 100}; 
     747        pj_ioqueue_poll(ioq, &timeout); 
     748    } 
     749    return 0; 
     750} 
     751 
    712752 
    713753PJ_DEF(void) pjsua_stop_worker_threads(void) 
     
    11131153            pjsua_var.ua_cfg.thread_cnt = PJ_ARRAY_SIZE(pjsua_var.thread); 
    11141154 
     1155#if PJSUA_SEPARATE_WORKER_FOR_TIMER 
     1156        if (pjsua_var.ua_cfg.thread_cnt < 2) 
     1157            pjsua_var.ua_cfg.thread_cnt = 2; 
     1158#endif 
     1159 
    11151160        for (ii=0; ii<pjsua_var.ua_cfg.thread_cnt; ++ii) { 
    1116             char thread_name[16]; 
    1117             pj_ansi_snprintf(thread_name, 16, "pjsua_%d", ii); 
    1118             status = pj_thread_create(pjsua_var.pool, thread_name, &worker_thread, 
     1161            char tname[16]; 
     1162             
     1163            pj_ansi_snprintf(tname, sizeof(tname), "pjsua_%d", ii); 
     1164 
     1165#if PJSUA_SEPARATE_WORKER_FOR_TIMER 
     1166            if (ii == 0) { 
     1167                status = pj_thread_create(pjsua_var.pool, tname, 
     1168                                          &worker_thread_timer, 
     1169                                          NULL, 0, 0, &pjsua_var.thread[ii]); 
     1170            } else { 
     1171                status = pj_thread_create(pjsua_var.pool, tname, 
     1172                                          &worker_thread_ioqueue, 
     1173                                          NULL, 0, 0, &pjsua_var.thread[ii]); 
     1174            } 
     1175#else 
     1176            status = pj_thread_create(pjsua_var.pool, tname, &worker_thread, 
    11191177                                      NULL, 0, 0, &pjsua_var.thread[ii]); 
     1178#endif 
    11201179            if (status != PJ_SUCCESS) 
    11211180                goto on_error; 
Note: See TracChangeset for help on using the changeset viewer.