- Timestamp:
- Dec 12, 2017 7:44:09 AM (7 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/include/pj/config_site_sample.h
r5543 r5712 411 411 #define PJSIP_MAX_DIALOG_COUNT 31 412 412 #define PJSUA_MAX_CALLS 4 413 414 /* Separate worker thread for timer and ioqueue */ 415 #define PJSUA_SEPARATE_WORKER_FOR_TIMER 1 413 416 414 417 /* Other pjsua settings */ -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
r5686 r5712 349 349 #ifndef PJSUA_VID_REQ_KEYFRAME_INTERVAL 350 350 # define PJSUA_VID_REQ_KEYFRAME_INTERVAL 3000 351 #endif 352 353 354 /** 355 * Specify whether timer heap events will be polled by a separate worker 356 * thread. If this is set/enabled, a worker thread will be dedicated to 357 * poll timer heap events only, and the rest worker thread(s) will poll 358 * ioqueue/network events only. 359 * 360 * Note that if worker thread count setting (i.e: pjsua_config.thread_cnt) 361 * is set to zero, this setting will be ignored. 362 * 363 * Default: 0 (disabled) 364 */ 365 #ifndef PJSUA_SEPARATE_WORKER_FOR_TIMER 366 # define PJSUA_SEPARATE_WORKER_FOR_TIMER 0 351 367 #endif 352 368 -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r5686 r5712 104 104 105 105 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; 107 107 cfg->nat_type_in_sdp = 1; 108 108 cfg->stun_ignore_failure = PJ_TRUE; … … 710 710 } 711 711 712 /* Timer heap worker thread function. */ 713 static 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. */ 738 static 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 712 752 713 753 PJ_DEF(void) pjsua_stop_worker_threads(void) … … 1113 1153 pjsua_var.ua_cfg.thread_cnt = PJ_ARRAY_SIZE(pjsua_var.thread); 1114 1154 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 1115 1160 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, 1119 1177 NULL, 0, 0, &pjsua_var.thread[ii]); 1178 #endif 1120 1179 if (status != PJ_SUCCESS) 1121 1180 goto on_error;
Note: See TracChangeset
for help on using the changeset viewer.