Index: trunk/src/VBox/Runtime/r0drv/nt/semmutex-r0drv-nt.cpp
===================================================================
--- trunk/src/VBox/Runtime/r0drv/nt/semmutex-r0drv-nt.cpp	(revision 25645)
+++ trunk/src/VBox/Runtime/r0drv/nt/semmutex-r0drv-nt.cpp	(revision 25714)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2006-2007 Sun Microsystems, Inc.
+ * Copyright (C) 2006-2010 Sun Microsystems, Inc.
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -64,43 +64,49 @@
 
 
-/* Undefine debug mappings. */
-#undef RTSemMutexRequest
-#undef RTSemMutexRequestNoResume
-
-
-RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX pMutexSem)
-{
-    Assert(sizeof(RTSEMMUTEXINTERNAL) > sizeof(void *));
-    PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)RTMemAlloc(sizeof(*pMutexInt));
-    if (pMutexInt)
-    {
-        pMutexInt->u32Magic = RTSEMMUTEX_MAGIC;
-#ifdef RT_USE_FAST_MUTEX
-        ExInitializeFastMutex(&pMutexInt->Mutex);
+
+RTDECL(int)  RTSemMutexCreate(PRTSEMMUTEX phMutexSem)
+{
+    return RTSemMutexCreateEx(phMutexSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, NULL);
+}
+
+
+RTDECL(int) RTSemMutexCreateEx(PRTSEMMUTEX phMutexSem, uint32_t fFlags,
+                               RTLOCKVALCLASS hClass, uint32_t uSubClass, const char *pszNameFmt, ...)
+{
+    AssertReturn(!(fFlags & ~RTSEMMUTEX_FLAGS_NO_LOCK_VAL), VERR_INVALID_PARAMETER);
+
+    AssertCompile(sizeof(RTSEMMUTEXINTERNAL) > sizeof(void *));
+    PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)RTMemAlloc(sizeof(*pThis));
+    if (!pThis)
+        return VERR_NO_MEMORY;
+
+    pThis->u32Magic = RTSEMMUTEX_MAGIC;
+#ifdef RT_USE_FAST_MUTEX
+    ExInitializeFastMutex(&pThis->Mutex);
 #else
-        KeInitializeMutex(&pMutexInt->Mutex, 0);
+    KeInitializeMutex(&pThis->Mutex, 0);
 #endif
-        *pMutexSem = pMutexInt;
+
+    *phMutexSem = pThis;
+    return VINF_SUCCESS;
+}
+
+
+RTDECL(int) RTSemMutexDestroy(RTSEMMUTEX MutexSem)
+{
+    /*
+     * Validate input.
+     */
+    PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)MutexSem;
+    if (pThis == NIL_RTSEMMUTEX)
         return VINF_SUCCESS;
-    }
-    return VERR_NO_MEMORY;
-}
-
-
-RTDECL(int) RTSemMutexDestroy(RTSEMMUTEX MutexSem)
-{
-    /*
-     * Validate input.
-     */
-    PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)MutexSem;
-    if (!pMutexInt)
-        return VERR_INVALID_PARAMETER;
-    AssertReturn(pMutexInt->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
+    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
+    AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
 
     /*
      * Invalidate it and signal the object just in case.
      */
-    AssertReturn(ASMAtomicCmpXchgU32(&pMutexInt->u32Magic, RTSEMMUTEX_MAGIC_DEAD, RTSEMMUTEX_MAGIC), VERR_INVALID_HANDLE);
-    RTMemFree(pMutexInt);
+    AssertReturn(ASMAtomicCmpXchgU32(&pThis->u32Magic, RTSEMMUTEX_MAGIC_DEAD, RTSEMMUTEX_MAGIC), VERR_INVALID_HANDLE);
+    RTMemFree(pThis);
     return VINF_SUCCESS;
 }
@@ -122,8 +128,7 @@
      * Validate input.
      */
-    PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)MutexSem;
-    if (!pMutexInt)
-        return VERR_INVALID_PARAMETER;
-    AssertReturn(pMutexInt->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
+    PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)MutexSem;
+    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
+    AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
 
     /*
@@ -132,19 +137,19 @@
 #ifdef RT_USE_FAST_MUTEX
     AssertMsg(cMillies == RT_INDEFINITE_WAIT, ("timeouts are not supported when using fast mutexes!\n"));
-    ExAcquireFastMutex(&pMutexInt->Mutex);
+    ExAcquireFastMutex(&pThis->Mutex);
 #else  /* !RT_USE_FAST_MUTEX */
     NTSTATUS rcNt;
     if (cMillies == RT_INDEFINITE_WAIT)
-        rcNt = KeWaitForSingleObject(&pMutexInt->Mutex, Executive, KernelMode, fInterruptible, NULL);
+        rcNt = KeWaitForSingleObject(&pThis->Mutex, Executive, KernelMode, fInterruptible, NULL);
     else
     {
         LARGE_INTEGER Timeout;
         Timeout.QuadPart = -(int64_t)cMillies * 10000;
-        rcNt = KeWaitForSingleObject(&pMutexInt->Mutex, Executive, KernelMode, fInterruptible, &Timeout);
+        rcNt = KeWaitForSingleObject(&pThis->Mutex, Executive, KernelMode, fInterruptible, &Timeout);
     }
     switch (rcNt)
     {
         case STATUS_SUCCESS:
-            if (pMutexInt->u32Magic == RTSEMMUTEX_MAGIC)
+            if (pThis->u32Magic == RTSEMMUTEX_MAGIC)
                 return VINF_SUCCESS;
             return VERR_SEM_DESTROYED;
@@ -159,6 +164,6 @@
 
         default:
-            AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p: wait returned %lx!\n",
-                             pMutexInt->u32Magic, pMutexInt, (long)rcNt));
+            AssertMsgFailed(("pThis->u32Magic=%RX32 pThis=%p: wait returned %lx!\n",
+                             pThis->u32Magic, pThis, (long)rcNt));
             return VERR_INTERNAL_ERROR;
     }
@@ -168,4 +173,5 @@
 
 
+#undef RTSemMutexRequest
 RTDECL(int) RTSemMutexRequest(RTSEMMUTEX MutexSem, unsigned cMillies)
 {
@@ -180,4 +186,5 @@
 
 
+#undef RTSemMutexRequestNoResume
 RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies)
 {
@@ -197,8 +204,7 @@
      * Validate input.
      */
-    PRTSEMMUTEXINTERNAL pMutexInt = (PRTSEMMUTEXINTERNAL)MutexSem;
-    if (!pMutexInt)
-        return VERR_INVALID_PARAMETER;
-    AssertReturn(pMutexInt->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
+    PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)MutexSem;
+    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
+    AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
 
     /*
@@ -206,7 +212,7 @@
      */
 #ifdef RT_USE_FAST_MUTEX
-    ExReleaseFastMutex(&pMutexInt->Mutex);
+    ExReleaseFastMutex(&pThis->Mutex);
 #else
-    KeReleaseMutex(&pMutexInt->Mutex, FALSE /*Wait*/);
+    KeReleaseMutex(&pThis->Mutex, FALSE /*Wait*/);
 #endif
     return VINF_SUCCESS;
