Index: /pjproject/trunk/pjlib/include/pj/string.h
===================================================================
--- /pjproject/trunk/pjlib/include/pj/string.h	(revision 580)
+++ /pjproject/trunk/pjlib/include/pj/string.h	(revision 581)
@@ -544,4 +544,17 @@
 PJ_DECL(int) pj_utoa_pad( unsigned long val, char *buf, int min_dig, int pad);
 
+
+/**
+ * Fill the memory location with zero.
+ *
+ * @param dst	    The destination buffer.
+ * @param size	    The number of bytes.
+ */
+PJ_INLINE(void) pj_bzero(void *dst, pj_size_t size)
+{
+    bzero(dst, size);
+}
+
+
 /**
  * Fill the memory location with value.
Index: /pjproject/trunk/pjlib/src/pj/pool_caching.c
===================================================================
--- /pjproject/trunk/pjlib/src/pj/pool_caching.c	(revision 580)
+++ /pjproject/trunk/pjlib/src/pj/pool_caching.c	(revision 581)
@@ -199,4 +199,6 @@
     pj_pool_reset(pool);
 
+    pool_capacity = pj_pool_get_capacity(pool);
+
     /*
      * Otherwise put the pool in our recycle list.
Index: /pjproject/trunk/pjsip-apps/build/Makefile
===================================================================
--- /pjproject/trunk/pjsip-apps/build/Makefile	(revision 580)
+++ /pjproject/trunk/pjsip-apps/build/Makefile	(revision 581)
@@ -44,17 +44,4 @@
 
 
-
-###############################################################################
-# Defines for building PJSIP-PERF
-#
-export PJSIPPERF_SRCDIR = ../src/pjsip-perf
-export PJSIPPERF_OBJS += $(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \
-			 handler_call.o handler_options.o main.o
-export PJSIPPERF_CFLAGS += $(_CFLAGS)
-export PJSIPPERF_LDFLAGS += $(_LDFLAGS)
-export PJSIPPERF_EXE:=../bin/pjsip-perf-$(TARGET_NAME)$(HOST_EXE)
-
-
-
 export CC_OUT CC AR RANLIB HOST_MV HOST_RM HOST_RMDIR HOST_MKDIR OBJEXT LD LDOUT 
 ###############################################################################
@@ -62,5 +49,5 @@
 #
 #
-TARGETS := pjsua pjsip-perf samples
+TARGETS := pjsua samples
 
 .PHONY: $(TARGETS)
@@ -79,7 +66,4 @@
 	$(MAKE) -f $(RULES_MAK) APP=PJSUA app=pjsua $(PJSUA_EXE)
 
-pjsip-perf:
-	$(MAKE) -f $(RULES_MAK) APP=PJSIPPERF app=pjsip-perf $(PJSUA_EXE)
-
 samples:
 	$(MAKE) -f Samples.mak
@@ -91,9 +75,7 @@
 clean depend realclean:
 	$(MAKE) -f $(RULES_MAK) APP=PJSUA app=pjsua $@
-	$(MAKE) -f $(RULES_MAK) APP=PJSIPPERF app=pjsip-perf $@
 	$(MAKE) -f Samples.mak $@
 	@if test "$@" = "depend"; then \
 	  echo '$(PJSUA_EXE): $(PJSIP_LIB) $(PJSIP_UA_LIB) $(PJSIP_SIMPLE) $(PJSUA_LIB_LIB) $(PJLIB_LIB) $(PJLIB_UTIL_LIB) $(PJMEDIA_LIB) $(PJMEDIA_CODEC_LIB) Makefile' >> .pjsua-$(TARGET_NAME).depend; \
-	  echo '$(PJSIPPERF_EXE): $(PJSIP_LIB) $(PJSIP_UA_LIB) $(PJSIP_SIMPLE) $(PJSUA_LIB_LIB) $(PJLIB_LIB) $(PJLIB_UTIL_LIB) $(PJMEDIA_LIB) $(PJMEDIA_CODEC_LIB)' >> .pjsip-perf-$(TARGET_NAME).depend; \
 	fi
 
Index: /pjproject/trunk/pjsip-apps/build/pjsip_apps.dsw
===================================================================
--- /pjproject/trunk/pjsip-apps/build/pjsip_apps.dsw	(revision 580)
+++ /pjproject/trunk/pjsip-apps/build/pjsip_apps.dsw	(revision 581)
@@ -64,5 +64,29 @@
 ###############################################################################
 
-Project: "pjsip_perf"=".\pjsip_perf.dsp" - Package Owner=<4>
+Project: "pjsip_simple"="..\..\pjsip\build\pjsip_simple.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "pjsip_ua"="..\..\pjsip\build\pjsip_ua.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "pjsua"=".\pjsua.dsp" - Package Owner=<4>
 
 Package=<5>
@@ -79,4 +103,10 @@
     End Project Dependency
     Begin Project Dependency
+    Project_Dep_Name pjmedia
+    End Project Dependency
+    Begin Project Dependency
+    Project_Dep_Name pjmedia_codec
+    End Project Dependency
+    Begin Project Dependency
     Project_Dep_Name pjsip_core
     End Project Dependency
@@ -90,36 +120,57 @@
     Project_Dep_Name pjsua_lib
     End Project Dependency
+}}}
+
+###############################################################################
+
+Project: "pjsua_lib"="..\..\pjsip\build\pjsua_lib.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "sample_debug"=".\sample_debug.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+    Begin Project Dependency
+    Project_Dep_Name pjlib
+    End Project Dependency
+    Begin Project Dependency
+    Project_Dep_Name pjlib_util
+    End Project Dependency
     Begin Project Dependency
     Project_Dep_Name pjmedia
     End Project Dependency
-}}}
-
-###############################################################################
-
-Project: "pjsip_simple"="..\..\pjsip\build\pjsip_simple.dsp" - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Project: "pjsip_ua"="..\..\pjsip\build\pjsip_ua.dsp" - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Project: "pjsua"=".\pjsua.dsp" - Package Owner=<4>
+    Begin Project Dependency
+    Project_Dep_Name pjmedia_codec
+    End Project Dependency
+    Begin Project Dependency
+    Project_Dep_Name pjsip_core
+    End Project Dependency
+    Begin Project Dependency
+    Project_Dep_Name pjsip_simple
+    End Project Dependency
+    Begin Project Dependency
+    Project_Dep_Name pjsip_ua
+    End Project Dependency
+    Begin Project Dependency
+    Project_Dep_Name pjsua_lib
+    End Project Dependency
+}}}
+
+###############################################################################
+
+Project: "samples"=".\samples.dsp" - Package Owner=<4>
 
 Package=<5>
@@ -157,88 +208,4 @@
 ###############################################################################
 
-Project: "pjsua_lib"="..\..\pjsip\build\pjsua_lib.dsp" - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Project: "sample_debug"=".\sample_debug.dsp" - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-    Begin Project Dependency
-    Project_Dep_Name pjlib
-    End Project Dependency
-    Begin Project Dependency
-    Project_Dep_Name pjlib_util
-    End Project Dependency
-    Begin Project Dependency
-    Project_Dep_Name pjmedia
-    End Project Dependency
-    Begin Project Dependency
-    Project_Dep_Name pjmedia_codec
-    End Project Dependency
-    Begin Project Dependency
-    Project_Dep_Name pjsip_core
-    End Project Dependency
-    Begin Project Dependency
-    Project_Dep_Name pjsip_simple
-    End Project Dependency
-    Begin Project Dependency
-    Project_Dep_Name pjsip_ua
-    End Project Dependency
-    Begin Project Dependency
-    Project_Dep_Name pjsua_lib
-    End Project Dependency
-}}}
-
-###############################################################################
-
-Project: "samples"=".\samples.dsp" - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-    Begin Project Dependency
-    Project_Dep_Name pjlib
-    End Project Dependency
-    Begin Project Dependency
-    Project_Dep_Name pjlib_util
-    End Project Dependency
-    Begin Project Dependency
-    Project_Dep_Name pjmedia
-    End Project Dependency
-    Begin Project Dependency
-    Project_Dep_Name pjmedia_codec
-    End Project Dependency
-    Begin Project Dependency
-    Project_Dep_Name pjsip_core
-    End Project Dependency
-    Begin Project Dependency
-    Project_Dep_Name pjsip_simple
-    End Project Dependency
-    Begin Project Dependency
-    Project_Dep_Name pjsip_ua
-    End Project Dependency
-    Begin Project Dependency
-    Project_Dep_Name pjsua_lib
-    End Project Dependency
-}}}
-
-###############################################################################
-
 Global:
 
Index: project/trunk/pjsip-apps/build/pjsip_perf.dsp
===================================================================
--- /pjproject/trunk/pjsip-apps/build/pjsip_perf.dsp	(revision 580)
+++ 	(revision )
@@ -1,114 +1,0 @@
-# Microsoft Developer Studio Project File - Name="pjsip_perf" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=pjsip_perf - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE 
-!MESSAGE NMAKE /f "pjsip_perf.mak".
-!MESSAGE 
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE 
-!MESSAGE NMAKE /f "pjsip_perf.mak" CFG="pjsip_perf - Win32 Debug"
-!MESSAGE 
-!MESSAGE Possible choices for configuration are:
-!MESSAGE 
-!MESSAGE "pjsip_perf - Win32 Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "pjsip_perf - Win32 Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE 
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF  "$(CFG)" == "pjsip_perf - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir ".\output\pjsip-perf-i386-win32-vc6-release"
-# PROP BASE Intermediate_Dir ".\output\pjsip-perf-i386-win32-vc6-release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir ".\output\pjsip-perf-i386-win32-vc6-release"
-# PROP Intermediate_Dir ".\output\pjsip-perf-i386-win32-vc6-release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MD /W4 /GX /O2 /I "../../pjsip/include" /I "../../pjmedia/include" /I "../../pjlib-util/include" /I "../../pjlib/include" /D "NDEBUG" /D PJ_WIN32=1 /D PJ_M_I386=1 /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 ole32.lib user32.lib netapi32.lib mswsock.lib ws2_32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"..\bin\pjsip-perf-i386-win32-vc6.exe"
-
-!ELSEIF  "$(CFG)" == "pjsip_perf - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir ".\output\pjsip-perf-i386-win32-vc6-debug"
-# PROP BASE Intermediate_Dir ".\output\pjsip-perf-i386-win32-vc6-debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir ".\output\pjsip-perf-i386-win32-vc6-debug"
-# PROP Intermediate_Dir ".\output\pjsip-perf-i386-win32-vc6-debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "../../pjsip/include" /I "../../pjmedia/include" /I "../../pjlib-util/include" /I "../../pjlib/include" /D "_DEBUG" /D PJ_WIN32=1 /D PJ_M_I386=1 /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 ole32.lib user32.lib netapi32.lib mswsock.lib ws2_32.lib kernel32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /profile /debug /machine:I386 /out:"..\bin\pjsip-perf-i386-win32-vc6d.exe"
-
-!ENDIF 
-
-# Begin Target
-
-# Name "pjsip_perf - Win32 Release"
-# Name "pjsip_perf - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE="..\src\pjsip-perf\handler_call.c"
-# End Source File
-# Begin Source File
-
-SOURCE="..\src\pjsip-perf\handler_options.c"
-# End Source File
-# Begin Source File
-
-SOURCE="..\src\pjsip-perf\main.c"
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE="..\src\pjsip-perf\pjsip_perf.h"
-# End Source File
-# End Group
-# Begin Group "Resource Files"
-
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
-# End Group
-# End Target
-# End Project
Index: /pjproject/trunk/pjsip-apps/build/sample_debug.dsp
===================================================================
--- /pjproject/trunk/pjsip-apps/build/sample_debug.dsp	(revision 580)
+++ /pjproject/trunk/pjsip-apps/build/sample_debug.dsp	(revision 581)
@@ -43,5 +43,6 @@
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "../../pjsip/include" /I "../../pjlib/include" /I "../../pjlib-util/include" /I "../../pjmedia/include" /D PJ_WIN32=1 /D PJ_M_I386=1 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I "../../pjsip/include" /I "../../pjlib/include" /I "../../pjlib-util/include" /I "../../pjmedia/include" /D PJ_WIN32=1 /D PJ_M_I386=1 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
+# SUBTRACT CPP /YX
 # ADD BASE RSC /l 0x409 /d "NDEBUG"
 # ADD RSC /l 0x409 /d "NDEBUG"
Index: /pjproject/trunk/pjsip-apps/src/samples/pjsip-perf.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/pjsip-perf.c	(revision 580)
+++ /pjproject/trunk/pjsip-apps/src/samples/pjsip-perf.c	(revision 581)
@@ -67,7 +67,17 @@
 #include <stdio.h>
 
-#define THIS_FILE	"pjsip-perf.c"
-#define DEFAULT_COUNT	(PJSIP_MAX_TSX_COUNT/2>10000?10000:PJSIP_MAX_TSX_COUNT/2)
-#define JOB_WINDOW	DEFAULT_COUNT
+#if defined(PJ_WIN32) && PJ_WIN32!=0
+#  include <windows.h>
+#endif
+
+#define THIS_FILE	    "pjsip-perf.c"
+#define DEFAULT_COUNT	    (PJSIP_MAX_TSX_COUNT/2>10000?10000:PJSIP_MAX_TSX_COUNT/2)
+#define JOB_WINDOW	    DEFAULT_COUNT
+#define TERMINATE_TSX(x,c)
+
+
+#ifndef CACHING_POOL_SIZE
+#   define CACHING_POOL_SIZE   (256*1024*1024)
+#endif
 
 
@@ -139,4 +149,5 @@
 			     job_finished,
 			     job_window;
+	unsigned	     stat_max_window;
 	pj_time_val	     first_request;
 	pj_time_val	     last_completion;
@@ -588,5 +599,6 @@
 
     /* Must create a pool factory before we can allocate any memory. */
-    pj_caching_pool_init(&app.cp, &pj_pool_factory_default_policy, 0);
+    pj_caching_pool_init(&app.cp, &pj_pool_factory_default_policy, 
+			 CACHING_POOL_SIZE);
 
     /* Create application pool for misc. */
@@ -633,5 +645,5 @@
 	    
 	    transport_type = "tcp";
-	    pj_sockaddr_in_init(&local_addr, 0, app.local_port);
+	    pj_sockaddr_in_init(&local_addr, 0, (pj_uint16_t)app.local_port);
 	    status = pjsip_tcp_transport_start(app.sip_endpt, &local_addr,
 					       app.thread_count, &tpfactory);
@@ -976,4 +988,5 @@
 	"   --stateless, -s         Set client to operate in stateless mode\n"
 	"                           (default: stateful)\n"
+	"   --window=COUNT, -w      Set maximum outstanding job in client (default: %d)\n"
 	"   --real-sdp              Generate real SDP from pjmedia, and also perform\n"
 	"                           proper SDP negotiation (default: dummy)\n"
@@ -986,5 +999,5 @@
 	"   - sip:1@server-addr     To handle requests statefully (INVITE and non-INVITE)\n"
 	"   - sip:2@server-addr     To handle INVITE call (INVITE only)\n",
-	DEFAULT_COUNT);
+	DEFAULT_COUNT, JOB_WINDOW);
 }
 
@@ -1011,4 +1024,5 @@
 	{ "verbose",        0, 0, 'v' },
 	{ "use-tcp",	    0, 0, 'T' },
+	{ "window",	    1, 0, 'w' },
 	{ NULL, 0, 0, 0 },
     };
@@ -1027,5 +1041,5 @@
     /* Parse options */
     pj_optind = 0;
-    while((c=pj_getopt_long(argc,argv, "p:c:m:t:hsv", 
+    while((c=pj_getopt_long(argc,argv, "p:c:m:t:w:hsv", 
 			    long_options, &option_index))!=-1) 
     {
@@ -1091,4 +1105,12 @@
 	    break;
 
+	case 'w':
+	    app.client.job_window = my_atoi(pj_optarg);
+	    if (app.client.job_window <= 0) {
+		PJ_LOG(3,(THIS_FILE, "Invalid --window %s", pj_optarg));
+		return -1;
+	    }
+	    break;
+
 	case 'T':
 	    app.use_tcp = PJ_TRUE;
@@ -1184,5 +1206,5 @@
 	tsx->mod_data[mod_test.id] = (void*)1;
 
-	pjsip_tsx_terminate(tsx, tsx->status_code);
+	TERMINATE_TSX(tsx, tsx->status_code);
     }
 }
@@ -1220,4 +1242,5 @@
 static int client_thread(void *arg)
 {
+    unsigned last_timeout_check = 0;
     pj_time_val end_time, now;
 
@@ -1240,13 +1263,21 @@
 	pj_status_t status;
 
+	/* Calculate current outstanding job */
+	outstanding = app.client.job_submitted - app.client.job_finished;
+
+	/* Update stats on max outstanding jobs */
+	if (outstanding > (int)app.client.stat_max_window)
+	    app.client.stat_max_window = outstanding;
+
 	/* Wait if there are more pending jobs than allowed in the
 	 * window.
 	 */
-	outstanding = app.client.job_submitted - app.client.job_finished;
-	while (outstanding >= (int)app.client.job_window) {
+	for (i=0; outstanding > (int)app.client.job_window && i<100; ++i) {
 	    pjsip_endpt_handle_events(app.sip_endpt, &timeout);
 	    outstanding = app.client.job_submitted - app.client.job_finished;
 	}
 
+
+	/* Submit one job */
 	if (app.client.method.id == PJSIP_INVITE_METHOD) {
 	    status = make_call(&app.client.dst_uri);
@@ -1259,9 +1290,13 @@
 	++app.client.job_submitted;
 
-	for (i=0; i<2; ++i) {
-	    unsigned cnt=0;
-	    pjsip_endpt_handle_events2(app.sip_endpt, &timeout, &cnt);
-	    if (cnt==0)
+	/* Handle event */
+	pjsip_endpt_handle_events2(app.sip_endpt, &timeout, NULL);
+
+	/* Check for time out */
+	if (app.client.job_submitted - last_timeout_check >= 2000) {
+	    pj_gettimeofday(&now);
+	    if (PJ_TIME_VAL_GTE(now, end_time))
 		break;
+	    last_timeout_check = app.client.job_submitted;
 	}
     }
@@ -1272,9 +1307,6 @@
 	unsigned i;
 
-	for (i=0; i<2; ++i) {
-	    unsigned cnt=0;
-	    pjsip_endpt_handle_events2(app.sip_endpt, &timeout, &cnt);
-	    if (cnt==0)
-		break;
+	for (i=0; i<2000; ++i) {
+	    pjsip_endpt_handle_events2(app.sip_endpt, &timeout, NULL);
 	}
 
@@ -1353,5 +1385,5 @@
 		good_number(str_call, app.server.cur_state.call_cnt);
 
-		printf("Total(rate): stateless:%s (%d/s), statefull:%s (%d/s), call:%s (%d/s)\r",
+		printf("Total(rate): stateless:%s (%d/s), statefull:%s (%d/s), call:%s (%d/s)       \r",
 		       str_stateless, stateless*1000/msec,
 		       str_stateful, stateful*1000/msec,
@@ -1367,6 +1399,18 @@
 }
 
+static void write_report(const char *msg)
+{
+    puts(msg);
+
+#if defined(PJ_WIN32) && PJ_WIN32!=0
+    OutputDebugString(msg);
+    OutputDebugString("\n");
+#endif
+}
+
+
 int main(int argc, char *argv[])
 {
+    static char report[1024];
 
     if (create_app() != 0)
@@ -1459,22 +1503,31 @@
 	if (msec == 0) msec = 1;
 
-	printf("Total %d %s sent, %d responses received in %d msec:\n"
-	       " - 2xx responses:  %7d (rate=%d/sec)\n"
-	       " - 3xx responses:  %7d (rate=%d/sec)\n"
-	       " - 4xx responses:  %7d (rate=%d/sec)\n"
-	       " - 5xx responses:  %7d (rate=%d/sec)\n"
-	       " - 6xx responses:  %7d (rate=%d/sec)\n"
-	       " - 7xx responses:  %7d (rate=%d/sec)\n"
-	       "                       ----------------\n"
-	       " TOTAL responses:  %7d (rate=%d/sec)\n",
-	       app.client.job_submitted, test_type,
-	       app.client.total_responses, msec,
-	       app.client.status_class[2], app.client.status_class[2]*1000/msec,
-	       app.client.status_class[3], app.client.status_class[3]*1000/msec,
-	       app.client.status_class[4], app.client.status_class[4]*1000/msec,
-	       app.client.status_class[5], app.client.status_class[5]*1000/msec,
-	       app.client.status_class[6], app.client.status_class[6]*1000/msec,
-	       app.client.status_class[7], app.client.status_class[7]*1000/msec,
-	       app.client.total_responses, app.client.total_responses*1000/msec);
+	pj_ansi_snprintf(
+	    report, sizeof(report),
+	    "Total %d %s sent, %d responses received in %d ms:\n"
+	    " - 2xx responses:  %7d (rate=%d/sec)\n"
+	    " - 3xx responses:  %7d (rate=%d/sec)\n"
+	    " - 4xx responses:  %7d (rate=%d/sec)\n"
+	    " - 5xx responses:  %7d (rate=%d/sec)\n"
+	    " - 6xx responses:  %7d (rate=%d/sec)\n"
+	    " - 7xx responses:  %7d (rate=%d/sec)\n"
+	    "                       ----------------\n"
+	    " TOTAL responses:  %7d (rate=%d/sec)\n",
+	    app.client.job_submitted, test_type,
+	    app.client.total_responses, msec,
+	    app.client.status_class[2], app.client.status_class[2]*1000/msec,
+	    app.client.status_class[3], app.client.status_class[3]*1000/msec,
+	    app.client.status_class[4], app.client.status_class[4]*1000/msec,
+	    app.client.status_class[5], app.client.status_class[5]*1000/msec,
+	    app.client.status_class[6], app.client.status_class[6]*1000/msec,
+	    app.client.status_class[7], app.client.status_class[7]*1000/msec,
+	    app.client.total_responses, app.client.total_responses*1000/msec);
+
+	write_report(report);
+
+	pj_ansi_sprintf(report, "Maximum outstanding job: %d", 
+			app.client.stat_max_window);
+	write_report(report);
+
 
     } else {
Index: /pjproject/trunk/pjsip/include/pjsip/sip_config.h
===================================================================
--- /pjproject/trunk/pjsip/include/pjsip/sip_config.h	(revision 580)
+++ /pjproject/trunk/pjsip/include/pjsip/sip_config.h	(revision 581)
@@ -118,4 +118,14 @@
 #ifndef PJSIP_MAX_PKT_LEN
 #   define PJSIP_MAX_PKT_LEN		2000
+#endif
+
+
+/**
+ * Allow SIP modules removal or insertions during operation?
+ * If yes, then locking will be employed when endpoint need to
+ * access module.
+ */
+#ifndef PJSIP_SAFE_MODULE
+#   define PJSIP_SAFE_MODULE		1
 #endif
 
Index: /pjproject/trunk/pjsip/src/pjsip/sip_endpoint.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip/sip_endpoint.c	(revision 580)
+++ /pjproject/trunk/pjsip/src/pjsip/sip_endpoint.c	(revision 581)
@@ -89,4 +89,13 @@
 
 
+#if defined(PJSIP_SAFE_MODULE) && PJSIP_SAFE_MODULE!=0
+#   define LOCK_MODULE_ACCESS(ept)	pj_rwmutex_lock_read(ept->mod_mutex)
+#   define UNLOCK_MODULE_ACCESS(ept)	pj_rwmutex_unlock_read(ept->mod_mutex)
+#else
+#   define LOCK_MODULE_ACCESS(endpt)
+#   define UNLOCK_MODULE_ACCESS(endpt)
+#endif
+
+
 
 /*
@@ -582,7 +591,12 @@
     PJ_LOG(6, (THIS_FILE, "Releasing pool %s", pj_pool_getobjname(pool)));
 
-    pj_mutex_lock(endpt->mutex);
+    /* Don't need to acquire mutex since pool factory is thread safe
+       pj_mutex_lock(endpt->mutex);
+     */
     pj_pool_release( pool );
+
+    /*
     pj_mutex_unlock(endpt->mutex);
+     */
 }
 
@@ -777,5 +791,5 @@
 
     /* Distribute to modules, starting from modules with highest priority */
-    pj_rwmutex_lock_read(endpt->mod_mutex);
+    LOCK_MODULE_ACCESS(endpt);
 
     if (msg->type == PJSIP_REQUEST_MSG) {
@@ -824,5 +838,5 @@
     }
 
-    pj_rwmutex_unlock_read(endpt->mod_mutex);
+    UNLOCK_MODULE_ACCESS(endpt);
 
     /* Must clear mod_data before returning rdata to transport, since
@@ -843,5 +857,5 @@
 
     /* Distribute to modules, starting from modules with LOWEST priority */
-    pj_rwmutex_lock_read(endpt->mod_mutex);
+    LOCK_MODULE_ACCESS(endpt);
 
     mod = endpt->module_list.prev;
@@ -865,5 +879,5 @@
     }
 
-    pj_rwmutex_unlock_read(endpt->mod_mutex);
+    UNLOCK_MODULE_ACCESS(endpt);
 
     return status;
