Changeset 4887 for pjproject/trunk
- Timestamp:
- Aug 13, 2014 9:14:53 AM (10 years ago)
- Location:
- pjproject/trunk/pjsip
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
r4860 r4887 1884 1884 1885 1885 /** 1886 * Register a thread to poll for events. This function should be1887 * called by an external worker thread, and it will block polling1888 * for events until the library is destroyed.1889 *1890 * @return PJ_SUCCESS if things are working correctly1891 * or an error polling cannot be done for some1892 * reason.1893 */1894 PJ_DECL(pj_status_t) pjsua_register_worker_thread(const char *name);1895 1896 1897 /**1898 1886 * Signal all worker threads to quit. This will only wait until internal 1899 * threads are done. For external threads, application must perform 1900 * its own waiting for the external threads to quit from 1901 * pjsua_register_worker_thread() function. 1887 * threads are done. 1902 1888 */ 1903 1889 PJ_DECL(void) pjsua_stop_worker_threads(void); 1890 1904 1891 1905 1892 /** -
pjproject/trunk/pjsip/include/pjsua2/endpoint.hpp
r4704 r4887 28 28 #include <pjsua2/siptypes.hpp> 29 29 #include <list> 30 #include <map> 30 31 31 32 /** PJSUA2 API is inside pj namespace */ … … 722 723 723 724 /** 724 * Register a thread to poll for events. This function should be 725 * called by an external worker thread, and it will block polling 726 * for events until the library is destroyed. 727 */ 728 void libRegisterWorkerThread(const string &name) throw(Error); 725 * Register a thread that was created by external or native API to the 726 * library. Note that each time this function is called, it will allocate 727 * some memory to store the thread description, which will only be freed 728 * when the library is destroyed. 729 * 730 * @param name The optional name to be assigned to the thread. 731 */ 732 void libRegisterThread(const string &name) throw(Error); 733 734 /** 735 * Check if this thread has been registered to the library. Note that 736 * this function is only applicable for library main & worker threads and 737 * external/native threads registered using libRegisterThread(). 738 */ 739 bool libIsThreadRegistered(); 729 740 730 741 /** … … 1173 1184 AudDevManager audioDevMgr; 1174 1185 CodecInfoVector codecInfoList; 1186 std::map<pj_thread_t*, pj_thread_desc*> threadDescMap; 1175 1187 1176 1188 /* Pending logging */ -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r4861 r4887 700 700 } 701 701 702 PJ_DEF(pj_status_t) pjsua_register_worker_thread(const char *name)703 {704 pj_thread_desc desc;705 pj_thread_t *thread;706 pj_status_t status;707 708 if (pjsua_var.thread_quit_flag)709 return PJ_EGONE;710 711 status = pj_thread_register(NULL, desc, &thread);712 if (status != PJ_SUCCESS)713 return status;714 715 if (name)716 PJ_LOG(4,(THIS_FILE, "Worker thread %s started", name));717 718 worker_thread(NULL);719 720 if (name)721 PJ_LOG(4,(THIS_FILE, "Worker thread %s stopped", name));722 723 return PJ_SUCCESS;724 }725 702 726 703 PJ_DEF(void) pjsua_stop_worker_threads(void) -
pjproject/trunk/pjsip/src/pjsua2/endpoint.cpp
r4847 r4887 27 27 using namespace std; 28 28 29 #include <pjsua2/account.hpp> 30 #include <pjsua2/call.hpp> 29 #include <pjsua-lib/pjsua_internal.h> /* For retrieving pjsua threads */ 31 30 32 31 #define THIS_FILE "endpoint.cpp" … … 1218 1217 PJSUA2_CHECK_EXPR( pjsua_create() ); 1219 1218 mainThread = pj_thread_this(); 1219 1220 /* Register library main thread */ 1221 threadDescMap[pj_thread_this()] = NULL; 1220 1222 } 1221 1223 … … 1278 1280 /* Init! */ 1279 1281 PJSUA2_CHECK_EXPR( pjsua_init(&ua_cfg, &log_cfg, &med_cfg) ); 1282 1283 /* Register worker threads */ 1284 int i = pjsua_var.ua_cfg.thread_cnt; 1285 while (i) { 1286 pj_thread_t *t = pjsua_var.thread[--i]; 1287 if (t) 1288 threadDescMap[t] = NULL; 1289 } 1290 1291 /* Register media endpoint worker thread */ 1292 pjmedia_endpt *medept = pjsua_get_pjmedia_endpt(); 1293 i = pjmedia_endpt_get_thread_count(medept); 1294 while (i) { 1295 pj_thread_t *t = pjmedia_endpt_get_thread(medept, --i); 1296 if (t) 1297 threadDescMap[t] = NULL; 1298 } 1280 1299 } 1281 1300 … … 1285 1304 } 1286 1305 1287 void Endpoint::libRegisterWorkerThread(const string &name) throw(Error) 1288 { 1289 PJSUA2_CHECK_EXPR(pjsua_register_worker_thread(name.c_str())); 1306 void Endpoint::libRegisterThread(const string &name) throw(Error) 1307 { 1308 pj_thread_t *thread; 1309 pj_thread_desc *desc; 1310 pj_status_t status; 1311 1312 desc = (pj_thread_desc*)malloc(sizeof(pj_thread_desc)); 1313 status = pj_thread_register(name.c_str(), *desc, &thread); 1314 if (status == PJ_SUCCESS) { 1315 threadDescMap[thread] = desc; 1316 } else { 1317 free(desc); 1318 PJSUA2_RAISE_ERROR(status); 1319 } 1320 } 1321 1322 bool Endpoint::libIsThreadRegistered() 1323 { 1324 if (pj_thread_is_registered()) { 1325 /* Recheck again if it exists in the thread description map */ 1326 return (threadDescMap.find(pj_thread_this()) != threadDescMap.end()); 1327 } 1328 1329 return false; 1290 1330 } 1291 1331 … … 1315 1355 } 1316 1356 #endif 1357 1358 /* Clean up thread descriptors */ 1359 std::map<pj_thread_t*, pj_thread_desc*>::iterator i; 1360 for (i = threadDescMap.begin(); i != threadDescMap.end(); ++i) { 1361 pj_thread_desc* d = (*i).second; 1362 if (d != NULL) 1363 free(d); 1364 } 1365 threadDescMap.clear(); 1317 1366 1318 1367 PJSUA2_CHECK_RAISE_ERROR(status);
Note: See TracChangeset
for help on using the changeset viewer.