semeventmulti-win.cpp revision 2805b95732a8d26015a397626b96049a6e6573e7
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * IPRT - Multiple Release Event Semaphore, Windows.
d05e58c15346e272284b3db3adae55a8fb8977davboxsync * @remarks This file is identical to semevent-win.cpp except for the 2nd
d05e58c15346e272284b3db3adae55a8fb8977davboxsync * CreateEvent parameter, the reset function and the "Multi" infix.
d05e58c15346e272284b3db3adae55a8fb8977davboxsync * Copyright (C) 2006-2010 Sun Microsystems, Inc.
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * available from http://www.virtualbox.org. This file is free software;
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * you can redistribute it and/or modify it under the terms of the GNU
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * General Public License (GPL) as published by the Free Software
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * The contents of this file may alternatively be used under the terms
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * of the Common Development and Distribution License Version 1.0
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * VirtualBox OSE distribution, in which case the provisions of the
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * CDDL are applicable instead of those of the GPL.
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * You may elect to license modified versions of this file under the
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * terms and conditions of either the GPL or the CDDL or both.
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * additional information or have any questions.
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync/*******************************************************************************
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync* Header Files *
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync*******************************************************************************/
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync/*******************************************************************************
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync* Defined Constants And Macros *
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync*******************************************************************************/
d05e58c15346e272284b3db3adae55a8fb8977davboxsync /** Magic value (RTSEMEVENTMULTI_MAGIC). */
d05e58c15346e272284b3db3adae55a8fb8977davboxsync /** The event handle. */
d05e58c15346e272284b3db3adae55a8fb8977davboxsync /** Signallers. */
d05e58c15346e272284b3db3adae55a8fb8977davboxsync /** Indicates that lock validation should be performed. */
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync/* Undefine debug mappings. */
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsyncRTDECL(int) RTSemEventMultiCreate(PRTSEMEVENTMULTI pEventMultiSem)
d05e58c15346e272284b3db3adae55a8fb8977davboxsync struct RTSEMEVENTMULTIINTERNAL *pThis = (struct RTSEMEVENTMULTIINTERNAL *)RTMemAlloc(sizeof(*pThis));
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * Create the semaphore.
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * (Manual reset, not signaled, private event object.)
d05e58c15346e272284b3db3adae55a8fb8977davboxsync if (pThis->hev != NULL) /* not INVALID_HANDLE_VALUE */
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsyncRTDECL(int) RTSemEventMultiDestroy(RTSEMEVENTMULTI EventMultiSem)
d05e58c15346e272284b3db3adae55a8fb8977davboxsync struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem;
d05e58c15346e272284b3db3adae55a8fb8977davboxsync AssertReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, VERR_INVALID_HANDLE);
d05e58c15346e272284b3db3adae55a8fb8977davboxsync * Invalidate the handle and close the semaphore.
d05e58c15346e272284b3db3adae55a8fb8977davboxsync AssertReturn(ASMAtomicCmpXchgU32(&pThis->u32Magic, ~RTSEMEVENTMULTI_MAGIC, RTSEMEVENTMULTI_MAGIC), VERR_INVALID_HANDLE);
d05e58c15346e272284b3db3adae55a8fb8977davboxsync RTLockValidatorRecSharedDelete(&pThis->Signallers);
d05e58c15346e272284b3db3adae55a8fb8977davboxsync AssertMsgFailed(("Destroy EventMultiSem %p failed, lasterr=%u (%Rrc)\n", pThis, dwErr, rc));
d05e58c15346e272284b3db3adae55a8fb8977davboxsync /* Leak it. */
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsyncRTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI EventMultiSem)
d05e58c15346e272284b3db3adae55a8fb8977davboxsync * Validate input.
d05e58c15346e272284b3db3adae55a8fb8977davboxsync struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem;
d05e58c15346e272284b3db3adae55a8fb8977davboxsync AssertReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, VERR_INVALID_HANDLE);
d05e58c15346e272284b3db3adae55a8fb8977davboxsync int rc9 = RTLockValidatorRecSharedCheckSignaller(&pThis->Signallers, NIL_RTTHREAD);
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * Signal the object.
d05e58c15346e272284b3db3adae55a8fb8977davboxsync AssertMsgFailed(("Signaling EventMultiSem %p failed, lasterr=%d\n", pThis, dwErr));
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsyncRTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI EventMultiSem)
d05e58c15346e272284b3db3adae55a8fb8977davboxsync * Validate input.
d05e58c15346e272284b3db3adae55a8fb8977davboxsync struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem;
d05e58c15346e272284b3db3adae55a8fb8977davboxsync AssertReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, VERR_INVALID_HANDLE);
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * Reset the object.
d05e58c15346e272284b3db3adae55a8fb8977davboxsync AssertMsgFailed(("Resetting EventMultiSem %p failed, lasterr=%d\n", pThis, dwErr));
3e39de9ed8b88fa8907468a77bef44d10049b12avboxsync/** Goto avoidance. */
3e39de9ed8b88fa8907468a77bef44d10049b12avboxsyncDECL_FORCE_INLINE(int) rtSemEventWaitHandleStatus(struct RTSEMEVENTMULTIINTERNAL *pThis, DWORD rc)
3e39de9ed8b88fa8907468a77bef44d10049b12avboxsync AssertMsgFailed(("Wait on EventMultiSem %p failed, rc=%d lasterr=%d\n", pThis, rc, GetLastError()));
3e39de9ed8b88fa8907468a77bef44d10049b12avboxsync AssertMsgFailed(("WaitForSingleObject(event) -> rc=%d while converted lasterr=%d\n", rc, rc2));
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsyncRTDECL(int) RTSemEventMultiWaitNoResume(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies)
d05e58c15346e272284b3db3adae55a8fb8977davboxsync * Validate input.
d05e58c15346e272284b3db3adae55a8fb8977davboxsync struct RTSEMEVENTMULTIINTERNAL *pThis = EventMultiSem;
d05e58c15346e272284b3db3adae55a8fb8977davboxsync AssertReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, VERR_INVALID_HANDLE);
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * Wait for condition.
3e39de9ed8b88fa8907468a77bef44d10049b12avboxsync 0 /*Timeout*/,
d05e58c15346e272284b3db3adae55a8fb8977davboxsync int rc9 = RTLockValidatorRecSharedCheckBlocking(&pThis->Signallers, hThreadSelf, pSrcPos, false,
d05e58c15346e272284b3db3adae55a8fb8977davboxsync RTThreadBlocking(hThreadSelf, RTTHREADSTATE_EVENT_MULTI, true);
d05e58c15346e272284b3db3adae55a8fb8977davboxsync cMillies == RT_INDEFINITE_WAIT ? INFINITE : cMillies,
d05e58c15346e272284b3db3adae55a8fb8977davboxsync RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_EVENT_MULTI);
333e7ab9cd83b32080826d06ac7b1951c684ccb5vboxsyncRTDECL(void) RTSemEventMultiSetSignaller(RTSEMEVENTMULTI hEventMultiSem, RTTHREAD hThread)
d05e58c15346e272284b3db3adae55a8fb8977davboxsync struct RTSEMEVENTMULTIINTERNAL *pThis = hEventMultiSem;
d05e58c15346e272284b3db3adae55a8fb8977davboxsync AssertReturnVoid(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC);
d05e58c15346e272284b3db3adae55a8fb8977davboxsync ASMAtomicWriteBool(&pThis->fEverHadSignallers, true);
d05e58c15346e272284b3db3adae55a8fb8977davboxsync RTLockValidatorRecSharedResetOwner(&pThis->Signallers, hThread, NULL);
333e7ab9cd83b32080826d06ac7b1951c684ccb5vboxsyncRTDECL(void) RTSemEventMultiAddSignaller(RTSEMEVENTMULTI hEventMultiSem, RTTHREAD hThread)
d05e58c15346e272284b3db3adae55a8fb8977davboxsync struct RTSEMEVENTMULTIINTERNAL *pThis = hEventMultiSem;
d05e58c15346e272284b3db3adae55a8fb8977davboxsync AssertReturnVoid(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC);
d05e58c15346e272284b3db3adae55a8fb8977davboxsync ASMAtomicWriteBool(&pThis->fEverHadSignallers, true);
d05e58c15346e272284b3db3adae55a8fb8977davboxsync RTLockValidatorRecSharedAddOwner(&pThis->Signallers, hThread, NULL);
333e7ab9cd83b32080826d06ac7b1951c684ccb5vboxsyncRTDECL(void) RTSemEventMultiRemoveSignaller(RTSEMEVENTMULTI hEventMultiSem, RTTHREAD hThread)
d05e58c15346e272284b3db3adae55a8fb8977davboxsync struct RTSEMEVENTMULTIINTERNAL *pThis = hEventMultiSem;
d05e58c15346e272284b3db3adae55a8fb8977davboxsync AssertReturnVoid(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC);