Index: trunk/src/VBox/Runtime/r0drv/solaris/semevent-r0drv-solaris.c
===================================================================
--- trunk/src/VBox/Runtime/r0drv/solaris/semevent-r0drv-solaris.c	(revision 30579)
+++ trunk/src/VBox/Runtime/r0drv/solaris/semevent-r0drv-solaris.c	(revision 30711)
@@ -55,10 +55,16 @@
     /** Magic value (RTSEMEVENT_MAGIC). */
     uint32_t volatile   u32Magic;
-    /** The number of waiting threads. */
-    uint32_t volatile   cWaiters;
-    /** The number of signalled threads. */
-    uint32_t volatile   cWakeUp;
     /** The number of threads referencing this object. */
     uint32_t volatile   cRefs;
+    /** Set if the object is signalled when there are no waiters. */
+    bool                fSignaled;
+    /** Object generation.
+     * This is incremented every time the object is signalled and used to
+     * check for spurious wake-ups. */
+    uint32_t            uSignalGen;
+    /** The number of waiting threads. */
+    uint32_t            cWaiters;
+    /** The number of signalled threads. */
+    uint32_t            cWakeUp;
     /** The Solaris mutex protecting this structure and pairing up the with the cv. */
     kmutex_t            Mtx;
@@ -87,7 +93,9 @@
 
     pThis->u32Magic       = RTSEMEVENT_MAGIC;
+    pThis->cRefs          = 1;
+    pThis->fSignaled      = false;
+    pThis->uSignalGen     = 0;
     pThis->cWaiters       = 0;
     pThis->cWakeUp        = 0;
-    pThis->cRefs          = 1;
     mutex_init(&pThis->Mtx, "IPRT Event Semaphore", MUTEX_DRIVER, (void *)ipltospl(DISP_LEVEL));
     cv_init(&pThis->Cnd, "IPRT CV", CV_DRIVER, NULL);
@@ -111,5 +119,5 @@
     ASMAtomicDecU32(&pThis->cRefs);
 
-    ASMAtomicIncU32(&pThis->u32Magic); /* make the handle invalid */
+    pThis->u32Magic = RTSEMEVENT_MAGIC_DEAD; /* make the handle invalid */
     if (pThis->cWaiters > 0)
     {
@@ -175,5 +183,5 @@
     }
 
-    ASMAtomicIncU32(&pThis->cWakeUp);
+    pThis->cWakeUp++;
     if (pThis->cWakeUp <= pThis->cWaiters)
     {
@@ -184,5 +192,8 @@
          */
         cv_signal(&pThis->Cnd);
-    }
+        pThis->uSignalGen++;
+    }
+    else
+        pThis->fSignaled = true;
 
     mutex_exit(&pThis->Mtx);
@@ -237,5 +248,5 @@
     ASMAtomicIncU32(&pThis->cRefs);
 
-    if (pThis->cWakeUp > 0)
+    if (pThis->fSignaled)
     {
         /*
@@ -244,5 +255,6 @@
          */
         Assert(!pThis->cWaiters);
-        ASMAtomicWriteU32((uint32_t volatile *)&pThis->cWakeUp, 0);
+        pThis->fSignaled = false;
+        pThis->cWakeUp = 0;
         rc = VINF_SUCCESS;
     }
@@ -251,58 +263,37 @@
     else
     {
-        uint32_t cWakeUp = ASMAtomicUoReadU32((uint32_t volatile *)&pThis->cWakeUp);
-        ASMAtomicIncU32(&pThis->cWaiters);
+        pThis->cWaiters++;
+        /* This loop is only for continuing after a spurious wake-up. */
         for (;;)
         {
+            uint32_t const uSignalGenBeforeWait = pThis->uSignalGen;
             rc = rtSemEventWaitWorker(pThis, cMillies, fInterruptible);
             if (rc > 0)
             {
-                if (pThis->u32Magic != RTSEMEVENT_MAGIC)
+                if (pThis->u32Magic == RTSEMEVENT_MAGIC)
                 {
-                    /*
-                     * We're being destroyed.
-                     */
-                    ASMAtomicDecU32(&pThis->cWaiters);
-                    rc = VERR_SEM_DESTROYED;
-                    break;
+                    if (pThis->uSignalGen != uSignalGenBeforeWait)
+                    {
+                        /* We've been signaled by cv_signal(), consume the wake up. */
+                        --pThis->cWakeUp;
+                        rc = VINF_SUCCESS;
+                    }
+                    else
+                        /* Spurious wakeup due to some signal, go back to waiting. */
+                        continue;
                 }
                 else
-                {
-                    uint32_t cWakeUpNow = ASMAtomicUoReadU32((uint32_t volatile *)&pThis->cWakeUp);
-                    if (cWakeUpNow > cWakeUp)
-                    {
-                        /*
-                         * We've been signaled by RTSemEventSignal(), consume the wake up.
-                         */
-                        ASMAtomicDecU32(&pThis->cWaiters);
-                        ASMAtomicDecU32(&pThis->cWakeUp);
-                        rc = VINF_SUCCESS;
-                        break;
-                    }
-                    else
-                    {
-                        /*
-                         * Premature wakeup due to some signal, go back to waiting.
-                         */
-                        continue;
-                    }
-                }
+                    /* We're being destroyed. */
+                    rc = VERR_SEM_DESTROYED;
             }
             else if (rc == -1)
-            {
-                /*
-                 * Timeout reached.
-                 */
-                ASMAtomicDecU32(&pThis->cWaiters);
+                /* Timeout reached. */
                 rc = VERR_TIMEOUT;
-                break;
-            }
             else
-            {
                 /* Returned due to pending signal */
-                ASMAtomicDecU32(&pThis->cWaiters);
                 rc = VERR_INTERRUPTED;
-                break;
-            }
+
+            --pThis->cWaiters;
+            break;
         }
     }
Index: trunk/src/VBox/Runtime/r0drv/solaris/semeventmulti-r0drv-solaris.c
===================================================================
--- trunk/src/VBox/Runtime/r0drv/solaris/semeventmulti-r0drv-solaris.c	(revision 30579)
+++ trunk/src/VBox/Runtime/r0drv/solaris/semeventmulti-r0drv-solaris.c	(revision 30711)
@@ -284,5 +284,4 @@
     else
     {
-
         /* This loop is only for continuing after a spurious wake-up. */
         for (;;)
