Fixed race-condition/deadlock problems in the dialog/user agent layer 
all the way up to PJSUA-API:
- standardized locking order: dialog then user agent, and dialog then PJSUA
- any threads that attempt to acquire mutexes in different order than
  above MUST employ retry mechanism (for an example, see acquire_call() in
  pjsua_call.c). This retry mechanism has also been used in the UA layer
  (sip_ua_layer.c) since it needs to lock user agent layer first before
  the dialog.
- introduced pjsip_dlg_try_inc_lock() and PJSUA_TRY_LOCK() to accomodate
  above.
- pjsua tested on Quad Xeon with 4 threads and 200 cps, so far so good.



git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@729 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip-apps/src/pjsua/pjsua_app.c b/pjsip-apps/src/pjsua/pjsua_app.c
index 57b6ad2..0a495b0 100644
--- a/pjsip-apps/src/pjsua/pjsua_app.c
+++ b/pjsip-apps/src/pjsua/pjsua_app.c
@@ -1196,6 +1196,11 @@
 
     PJ_UNUSED_ARG(timer_heap);
 
+    if (call_id == PJSUA_INVALID_ID) {
+	PJ_LOG(1,(THIS_FILE, "Invalid call ID in timer callback"));
+	return;
+    }
+    
     /* Add warning header */
     pjsua_msg_data_init(&msg_data);
     pjsip_generic_string_hdr_init2(&warn, &hname, &hvalue);