Index: trunk/src/VBox/GuestHost/OpenGL/util/vboxhgcm.c
===================================================================
--- trunk/src/VBox/GuestHost/OpenGL/util/vboxhgcm.c	(revision 37986)
+++ trunk/src/VBox/GuestHost/OpenGL/util/vboxhgcm.c	(revision 38314)
@@ -820,5 +820,11 @@
     void *pvBuff;
     VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
+#ifdef CHROMIUM_THREADSAFE
+    crLockMutex(&g_crvboxhgcm.mutex);
+#endif
     pvBuff = _crVBoxHGCMAlloc(conn);
+#ifdef CHROMIUM_THREADSAFE
+    crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
     VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
     return pvBuff;
@@ -877,5 +883,11 @@
 {
     VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
+#ifdef CHROMIUM_THREADSAFE
+    crLockMutex(&g_crvboxhgcm.mutex);
+#endif
     _crVBoxHGCMWriteExact(conn, buf, len);
+#ifdef CHROMIUM_THREADSAFE
+    crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
     VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
 }
@@ -1068,4 +1080,8 @@
     CRVBOXHGCMBUFFER *hgcm_buffer;
     VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
+
+#ifdef CHROMIUM_THREADSAFE
+    crLockMutex(&g_crvboxhgcm.mutex);
+#endif
 
     if (!bufp) /* We're sending a user-allocated buffer. */
@@ -1080,4 +1096,7 @@
             crVBoxHGCMWriteReadExact(conn, start, len, CR_VBOXHGCM_USERALLOCATED);
 #endif
+#ifdef CHROMIUM_THREADSAFE
+            crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
             VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
         return;
@@ -1119,4 +1138,8 @@
     *bufp = NULL;
 
+#ifdef CHROMIUM_THREADSAFE
+    crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
+
     VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
 }
@@ -1159,5 +1182,11 @@
 {
     VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
+#ifdef CHROMIUM_THREADSAFE
+    crLockMutex(&g_crvboxhgcm.mutex);
+#endif
     crVBoxHGCMReadExact(conn, buf, len);
+#ifdef CHROMIUM_THREADSAFE
+    crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
     VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
 }
@@ -1205,5 +1234,11 @@
 {
     VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
+#ifdef CHROMIUM_THREADSAFE
+    crLockMutex(&g_crvboxhgcm.mutex);
+#endif
     _crVBoxHGCMFree(conn, buf);
+#ifdef CHROMIUM_THREADSAFE
+    crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
     VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
 }
@@ -1290,5 +1325,11 @@
 {
     VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
+#ifdef CHROMIUM_THREADSAFE
+    crLockMutex(&g_crvboxhgcm.mutex);
+#endif
     _crVBoxHGCMReceiveMessage(conn);
+#ifdef CHROMIUM_THREADSAFE
+    crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
     VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
 }
@@ -1592,6 +1633,12 @@
 {
     VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
+#ifdef CHROMIUM_THREADSAFE
+    crLockMutex(&g_crvboxhgcm.mutex);
+#endif
     _crVBoxHGCMFree(conn, mess);
     CRASSERT(FALSE);
+#ifdef CHROMIUM_THREADSAFE
+    crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
     VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
 }
@@ -1701,4 +1748,8 @@
     VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
 
+#ifdef CHROMIUM_THREADSAFE
+    crLockMutex(&g_crvboxhgcm.mutex);
+#endif
+
     pClient = _crVBoxHGSMIClientGet(conn);
     if (pClient)
@@ -1712,4 +1763,8 @@
     }
 
+#ifdef CHROMIUM_THREADSAFE
+    crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
+
     VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
 
@@ -1720,5 +1775,11 @@
 {
     VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
+#ifdef CHROMIUM_THREADSAFE
+    crLockMutex(&g_crvboxhgcm.mutex);
+#endif
     _crVBoxHGSMIFree(conn, buf);
+#ifdef CHROMIUM_THREADSAFE
+    crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
     VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
 }
@@ -2077,4 +2138,8 @@
     VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
 
+#ifdef CHROMIUM_THREADSAFE
+    crLockMutex(&g_crvboxhgcm.mutex);
+#endif
+
     if (!bufp) /* We're sending a user-allocated buffer. */
     {
@@ -2091,4 +2156,7 @@
             _crVBoxHGSMIWriteReadExact(conn, pClient, (void*)start, 0, len, false);
 #endif
+#ifdef CHROMIUM_THREADSAFE
+            crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
             VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
             return;
@@ -2097,4 +2165,7 @@
         /* fallback */
         crVBoxHGCMSend(conn, bufp, start, len);
+#ifdef CHROMIUM_THREADSAFE
+        crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
         VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
         return;
@@ -2113,4 +2184,7 @@
         /* fallback */
         crVBoxHGCMSend(conn, bufp, start, len);
+#ifdef CHROMIUM_THREADSAFE
+        crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
         VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
         return;
@@ -2127,4 +2201,7 @@
     {
         crVBoxHGCMSend(conn, bufp, start, len);
+#ifdef CHROMIUM_THREADSAFE
+        crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
         VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
         return;
@@ -2159,4 +2236,8 @@
     *bufp = NULL;
 
+#ifdef CHROMIUM_THREADSAFE
+    crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
+
     VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
 }
@@ -2167,11 +2248,5 @@
 
     CRASSERT(0);
-//    PCRVBOXHGSMI_CLIENT pClient;
-//    PVBOXUHGSMI_BUFFER pBuf = _crVBoxHGSMIBufFromMemPtr(buf);
-//    if (!pBuf)
-//        return;
-//    pClient = (PCRVBOXHGSMI_CLIENT)pBuf->pvUserData;
-//    _crVBoxHGSMIWriteExact(conn, pClient, pBuf, 0, len);
-//    _crVBoxHGSMIBufFree(pClient, pBuf);
+
     VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
 }
@@ -2179,17 +2254,8 @@
 static void crVBoxHGSMISingleRecv(CRConnection *conn, void *buf, unsigned int len)
 {
-//    PCRVBOXHGSMI_CLIENT pClient;
-//    PVBOXUHGSMI_BUFFER pBuf;
     VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
-//    pBuf = _crVBoxHGSMIBufFromMemPtr(buf);
-//    Assert(pBuf);
+
     CRASSERT(0);
-//    if (!pBuf)
-//    {
-//        VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
-//        return;
-//    }
-//    pClient = (PCRVBOXHGSMI_CLIENT)pBuf->pvUserData;
-//    _crVBoxHGSMIReadExact(conn, pClient);
+
     VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
 }
@@ -2199,7 +2265,16 @@
     VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
 
+#ifdef CHROMIUM_THREADSAFE
+    crLockMutex(&g_crvboxhgcm.mutex);
+#endif
+
     CRASSERT(0);
 
     _crVBoxHGCMReceiveMessage(conn);
+
+#ifdef CHROMIUM_THREADSAFE
+    crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
+
     VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
 }
@@ -2227,4 +2302,7 @@
 static void crVBoxHGSMIDoDisconnect( CRConnection *conn )
 {
+#ifdef CHROMIUM_THREADSAFE
+    crLockMutex(&g_crvboxhgcm.mutex);
+#endif
 #ifndef VBOX_CRHGSMI_WITH_D3DDEV
     if (conn->HgsmiClient.pHgsmi)
@@ -2235,7 +2313,9 @@
         VBoxCrHgsmiDestroy(pHgsmi);
     }
-
 #endif
     crVBoxHGCMDoDisconnect(conn);
+#ifdef CHROMIUM_THREADSAFE
+    crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
 }
 
@@ -2243,9 +2323,14 @@
 {
     VBOXCRHGSMIPROFILE_FUNC_PROLOGUE();
+#ifdef CHROMIUM_THREADSAFE
+    crLockMutex(&g_crvboxhgcm.mutex);
+#endif
     CRASSERT(0);
 
     _crVBoxHGSMIFree(conn, mess);
-    CRASSERT(FALSE);
-
+
+#ifdef CHROMIUM_THREADSAFE
+    crUnlockMutex(&g_crvboxhgcm.mutex);
+#endif
     VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
 }
