RTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI hEventMultiSem) { uint32_t fNew; uint32_t fOld; /* * Validate input. */ PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)hEventMultiSem; if (!pThis) return VERR_INVALID_PARAMETER; AssertPtrReturn(pThis, VERR_INVALID_PARAMETER); AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER); rtR0SemEventMultiBsdRetain(pThis); /* * Signal the event object. The cause of the parnoia here is racing to try * deal with racing RTSemEventMultiSignal calls (should probably be * forbidden, but it's relatively easy to handle). */ do { fNew = fOld = ASMAtomicUoReadU32(&pThis->fStateAndGen); fNew += 1 << RTSEMEVENTMULTIBSD_GEN_SHIFT; fNew |= RTSEMEVENTMULTIBSD_STATE_MASK; } while (!ASMAtomicCmpXchgU32(&pThis->fStateAndGen, fNew, fOld)); rtR0SemBsdBroadcast(pThis); rtR0SemEventMultiBsdRelease(pThis); return VINF_SUCCESS; }
RTDECL(int) RTSemEventDestroy(RTSEMEVENT hEventSem) { /* * Validate input. */ PRTSEMEVENTINTERNAL pThis = hEventSem; if (pThis == NIL_RTSEMEVENT) return VINF_SUCCESS; AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE); Assert(pThis->cRefs > 0); /* * Invalidate it and signal the object just in case. */ ASMAtomicWriteU32(&pThis->u32Magic, ~RTSEMEVENT_MAGIC); ASMAtomicWriteU32(&pThis->fState, 0); rtR0SemBsdBroadcast(pThis); rtR0SemEventBsdRelease(pThis); return VINF_SUCCESS; }
RTDECL(int) RTSemEventMultiDestroy(RTSEMEVENTMULTI hEventMultiSem) { /* * Validate input. */ PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)hEventMultiSem; if (pThis == NIL_RTSEMEVENTMULTI) return VINF_SUCCESS; AssertPtrReturn(pThis, VERR_INVALID_PARAMETER); AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER); Assert(pThis->cRefs > 0); /* * Invalidate it and signal the object just in case. */ ASMAtomicWriteU32(&pThis->u32Magic, ~RTSEMEVENTMULTI_MAGIC); ASMAtomicAndU32(&pThis->fStateAndGen, RTSEMEVENTMULTIBSD_GEN_MASK); rtR0SemBsdBroadcast(pThis); rtR0SemEventMultiBsdRelease(pThis); return VINF_SUCCESS; }