Index: /trunk/src/libs/xpcom18a4/ipc/ipcd/client/src/ipcdclient.cpp
===================================================================
--- /trunk/src/libs/xpcom18a4/ipc/ipcd/client/src/ipcdclient.cpp	(revision 46493)
+++ /trunk/src/libs/xpcom18a4/ipc/ipcd/client/src/ipcdclient.cpp	(revision 46494)
@@ -59,4 +59,9 @@
 #include "pratom.h"
 
+#ifdef VBOX
+# include <iprt/critsect.h>
+# define VBOX_WITH_IPCCLIENT_RW_CS
+#endif
+
 /* ------------------------------------------------------------------------- */
 
@@ -147,8 +152,13 @@
   ~ipcClientState()
   {
+#ifndef VBOX_WITH_IPCCLIENT_RW_CS
     if (monitor)
       nsAutoMonitor::DestroyMonitor(monitor);
-  }
-
+#else
+    RTCritSectRwDelete(&critSect);
+#endif
+  }
+
+#ifndef VBOX_WITH_IPCCLIENT_RW_CS
   //
   // the monitor protects the targetMap and the connected and shutdown flags.
@@ -160,4 +170,7 @@
   //
   PRMonitor    *monitor;
+#else  /* VBOX_WITH_IPCCLIENT_RW_CS */
+  RTCRITSECTRW  critSect;
+#endif /* VBOX_WITH_IPCCLIENT_RW_CS */
   ipcTargetMap  targetMap;
   PRBool        connected;
@@ -172,9 +185,18 @@
 
   ipcClientState()
+#ifndef VBOX_WITH_IPCCLIENT_RW_CS
     : monitor(nsAutoMonitor::NewMonitor("ipcClientState"))
     , connected(PR_FALSE)
+#else
+    : connected(PR_FALSE)
+#endif
     , shutdown(PR_FALSE)
     , selfID(0)
-  {}
+  {
+#ifdef VBOX_WITH_IPCCLIENT_RW_CS
+    /* Not employing the lock validator here to keep performance up in debug builds. */
+    RTCritSectRwInitEx(&critSect, RTCRITSECT_FLAGS_NO_LOCK_VAL, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, NULL);
+#endif
+  }
 };
 
@@ -186,5 +208,9 @@
     return NULL;
 
+#ifndef VBOX_WITH_IPCCLIENT_RW_CS
   if (!cs->monitor || !cs->targetMap.Init())
+#else
+  if (!RTCritSectRwIsInitialized(&cs->critSect) || !cs->targetMap.Init())
+#endif
   {
     delete cs;
@@ -202,6 +228,13 @@
 GetTarget(const nsID &aTarget, ipcTargetData **td)
 {
+#ifndef VBOX_WITH_IPCCLIENT_RW_CS
   nsAutoMonitor mon(gClientState->monitor);
   return gClientState->targetMap.Get(nsIDHashKey(&aTarget).GetKey(), td);
+#else
+  RTCritSectRwEnterShared(&gClientState->critSect);
+  PRBool fRc = gClientState->targetMap.Get(nsIDHashKey(&aTarget).GetKey(), td);
+  RTCritSectRwLeaveShared(&gClientState->critSect);
+  return fRc;
+#endif
 }
 
@@ -209,6 +242,13 @@
 PutTarget(const nsID &aTarget, ipcTargetData *td)
 {
+#ifndef VBOX_WITH_IPCCLIENT_RW_CS
   nsAutoMonitor mon(gClientState->monitor);
   return gClientState->targetMap.Put(nsIDHashKey(&aTarget).GetKey(), td);
+#else
+  RTCritSectRwEnterExcl(&gClientState->critSect);
+  PRBool fRc = gClientState->targetMap.Put(nsIDHashKey(&aTarget).GetKey(), td);
+  RTCritSectRwLeaveExcl(&gClientState->critSect);
+  return fRc;
+#endif
 }
 
@@ -216,6 +256,12 @@
 DelTarget(const nsID &aTarget)
 {
+#ifndef VBOX_WITH_IPCCLIENT_RW_CS
   nsAutoMonitor mon(gClientState->monitor);
   gClientState->targetMap.Remove(nsIDHashKey(&aTarget).GetKey());
+#else
+  RTCritSectRwEnterExcl(&gClientState->critSect);
+  gClientState->targetMap.Remove(nsIDHashKey(&aTarget).GetKey());
+  RTCritSectRwLeaveExcl(&gClientState->critSect);
+#endif
 }
 
@@ -805,7 +851,16 @@
       // all targets but IPCM will not be able to use WaitTarget any more.
 
+#ifndef VBOX_WITH_IPCCLIENT_RW_CS
       nsAutoMonitor mon(gClientState->monitor);
+#else
+      RTCritSectRwEnterExcl(&gClientState->critSect);
+#endif
+
       gClientState->shutdown = PR_TRUE;
       gClientState->targetMap.EnumerateRead(EnumerateTargetMapAndNotify, nsnull);
+
+#ifdef VBOX_WITH_IPCCLIENT_RW_CS
+      RTCritSectRwLeaveExcl(&gClientState->critSect);
+#endif
     }
 
@@ -1290,7 +1345,16 @@
   // unblock any calls to WaitTarget.
 
+#ifndef VBOX_WITH_IPCCLIENT_RW_CS
   nsAutoMonitor mon(gClientState->monitor);
+#else
+  RTCritSectRwEnterExcl(&gClientState->critSect);
+#endif
+
   gClientState->connected = PR_FALSE;
   gClientState->targetMap.EnumerateRead(EnumerateTargetMapAndNotify, nsnull);
+
+#ifdef VBOX_WITH_IPCCLIENT_RW_CS
+  RTCritSectRwLeaveExcl(&gClientState->critSect);
+#endif
 }
 
@@ -1393,7 +1457,15 @@
         // targets) giving them an opportuninty to finish wait cycle because of
         // the peer client death, when appropriate.
+#ifndef VBOX_WITH_IPCCLIENT_RW_CS
         nsAutoMonitor mon(gClientState->monitor);
+#else
+        RTCritSectRwEnterShared(&gClientState->critSect);
+#endif
+
         gClientState->targetMap.EnumerateRead(EnumerateTargetMapAndPlaceMsg, msg);
 
+#ifdef VBOX_WITH_IPCCLIENT_RW_CS
+        RTCritSectRwLeaveShared(&gClientState->critSect);
+#endif
         delete msg;
 
