sems-win.cpp revision f53321a9e9d78b7745c5792e7f6e7058eb6efd5e
0f70ed40798198e1d9099c6ae3bdb239d2b8cf0dvboxsync * IPRT - Semaphores, implementation for Windows host platform.
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
82bcaaf8077ba892f39afb721dca149353c63d2cvboxsync * available from http://www.virtualbox.org. This file is free software;
82bcaaf8077ba892f39afb721dca149353c63d2cvboxsync * you can redistribute it and/or modify it under the terms of the GNU
82bcaaf8077ba892f39afb721dca149353c63d2cvboxsync * General Public License (GPL) as published by the Free Software
82bcaaf8077ba892f39afb721dca149353c63d2cvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
82bcaaf8077ba892f39afb721dca149353c63d2cvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
82bcaaf8077ba892f39afb721dca149353c63d2cvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * The contents of this file may alternatively be used under the terms
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * of the Common Development and Distribution License Version 1.0
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * VirtualBox OSE distribution, in which case the provisions of the
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * CDDL are applicable instead of those of the GPL.
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * You may elect to license modified versions of this file under the
2e2dec6e64c09dd7e3fe4ad0ee8bb5cf7d63762evboxsync * terms and conditions of either the GPL or the CDDL or both.
2e2dec6e64c09dd7e3fe4ad0ee8bb5cf7d63762evboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
2e2dec6e64c09dd7e3fe4ad0ee8bb5cf7d63762evboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
2e2dec6e64c09dd7e3fe4ad0ee8bb5cf7d63762evboxsync * additional information or have any questions.
2e2dec6e64c09dd7e3fe4ad0ee8bb5cf7d63762evboxsync/*******************************************************************************
2e2dec6e64c09dd7e3fe4ad0ee8bb5cf7d63762evboxsync* Header Files *
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync*******************************************************************************/
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync/*******************************************************************************
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync* Defined Constants And Macros *
e2843ed205192b88e54eef60ad541d00bbbc932avboxsync*******************************************************************************/
2e2dec6e64c09dd7e3fe4ad0ee8bb5cf7d63762evboxsync/** @def RTSEMMUTEX_STRICT
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * Enables strictness checks and lock accounting.
2622c26c6b4105d944a29c5e2c77b6ef26e10101vboxsync# if defined(RT_STRICT) || defined(RT_LOCK_STRICT) || defined(RTSEM_STRICT) || defined(DOXYGEN_RUNNING)
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync/** Converts semaphore to win32 handle. */
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * Create the semaphore.
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * (Auto reset, not signaled, private event object.)
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync HANDLE hev = CreateEvent(NULL, FALSE, FALSE, NULL);
e2843ed205192b88e54eef60ad541d00bbbc932avboxsync * Close semaphore handle.
e2843ed205192b88e54eef60ad541d00bbbc932avboxsync AssertMsgFailed(("Destroy EventSem %p failed, lasterr=%d\n", EventSem, GetLastError()));
2e2dec6e64c09dd7e3fe4ad0ee8bb5cf7d63762evboxsyncRTDECL(int) RTSemEventWaitNoResume(RTSEMEVENT EventSem, unsigned cMillies)
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * Wait for condition.
2e2dec6e64c09dd7e3fe4ad0ee8bb5cf7d63762evboxsync int rc = WaitForSingleObjectEx(SEM2HND(EventSem), cMillies == RT_INDEFINITE_WAIT ? INFINITE : cMillies, TRUE);
2e2dec6e64c09dd7e3fe4ad0ee8bb5cf7d63762evboxsync AssertMsgFailed(("Wait on EventSem %p failed, rc=%d lasterr=%d\n", EventSem, rc, GetLastError()));
2e2dec6e64c09dd7e3fe4ad0ee8bb5cf7d63762evboxsync AssertMsgFailed(("WaitForSingleObject(event) -> rc=%d while converted lasterr=%d\n", rc, rc2));
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * Signal the object.
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync AssertMsgFailed(("Signaling EventSem %p failed, lasterr=%d\n", EventSem, GetLastError()));
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsyncRTDECL(int) RTSemEventMultiCreate(PRTSEMEVENTMULTI pEventMultiSem)
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * Create the semaphore.
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * (Manual reset, not signaled, private event object.)
2e2dec6e64c09dd7e3fe4ad0ee8bb5cf7d63762evboxsyncRTDECL(int) RTSemEventMultiDestroy(RTSEMEVENTMULTI EventMultiSem)
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * Close semaphore handle.
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync AssertMsgFailed(("Destroy EventMultiSem %p failed, lasterr=%d\n", EventMultiSem, GetLastError()));
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsyncRTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI EventMultiSem)
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * Signal the object.
2622c26c6b4105d944a29c5e2c77b6ef26e10101vboxsync AssertMsgFailed(("Signaling EventMultiSem %p failed, lasterr=%d\n", EventMultiSem, GetLastError()));
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsyncRTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI EventMultiSem)
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * Reset the object.
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync AssertMsgFailed(("Resetting EventMultiSem %p failed, lasterr=%d\n", EventMultiSem, GetLastError()));
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsyncRTDECL(int) RTSemEventMultiWaitNoResume(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies)
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * Wait for condition.
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync int rc = WaitForSingleObjectEx(SEM2HND(EventMultiSem), cMillies == RT_INDEFINITE_WAIT ? INFINITE : cMillies, TRUE);
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync AssertMsgFailed(("Wait on EventMultiSem %p failed, rc=%d lasterr=%d\n", EventMultiSem, rc, GetLastError()));
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync AssertMsgFailed(("WaitForSingleObject(event) -> rc=%d while converted lasterr=%d\n", rc, rc2));
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * Create the semaphore.
7f67048412d241d45c0835b9c403a5bb1c879030vboxsync * Close semaphore handle.
e2843ed205192b88e54eef60ad541d00bbbc932avboxsync AssertMsgFailed(("Destroy MutexSem %p failed, lasterr=%d\n", MutexSem, GetLastError()));
e2843ed205192b88e54eef60ad541d00bbbc932avboxsyncRTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies)
e2843ed205192b88e54eef60ad541d00bbbc932avboxsync * Lock mutex semaphore.
e2843ed205192b88e54eef60ad541d00bbbc932avboxsync int rc = WaitForSingleObjectEx(SEM2HND(MutexSem), cMillies == RT_INDEFINITE_WAIT ? INFINITE : cMillies, TRUE);
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync AssertMsgFailed(("Wait on MutexSem %p failed, rc=%d lasterr=%d\n", MutexSem, rc, GetLastError()));
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync AssertMsgFailed(("WaitForSingleObject(event) -> rc=%d while converted lasterr=%d\n", rc, rc2));
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync * Unlock mutex semaphore.
d1a00c93378091ef28db9d959b2d692cc8143a07vboxsync AssertMsgFailed(("Release MutexSem %p failed, lasterr=%d\n", MutexSem, GetLastError()));