semevent-r0drv-solaris.c revision 8c99dcd207cf5b7bee01f95fbe19728a94076f94
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * IPRT - Semaphores, Ring-0 Driver, Solaris.
0cde281779e97ead3181bbd3b628451fa2b1efe1vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * available from http://www.virtualbox.org. This file is free software;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * you can redistribute it and/or modify it under the terms of the GNU
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * General Public License (GPL) as published by the Free Software
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * The contents of this file may alternatively be used under the terms
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * of the Common Development and Distribution License Version 1.0
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * VirtualBox OSE distribution, in which case the provisions of the
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * CDDL are applicable instead of those of the GPL.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * You may elect to license modified versions of this file under the
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * terms and conditions of either the GPL or the CDDL or both.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * additional information or have any questions.
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsync/*******************************************************************************
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync* Header Files *
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync*******************************************************************************/
0cde281779e97ead3181bbd3b628451fa2b1efe1vboxsync/*******************************************************************************
0cde281779e97ead3181bbd3b628451fa2b1efe1vboxsync* Structures and Typedefs *
0cde281779e97ead3181bbd3b628451fa2b1efe1vboxsync*******************************************************************************/
0cde281779e97ead3181bbd3b628451fa2b1efe1vboxsync * Solaris event semaphore.
0cde281779e97ead3181bbd3b628451fa2b1efe1vboxsync /** Magic value (RTSEMEVENT_MAGIC). */
619824b60d668e6e43f385ef78cf06e13d43aab6vboxsync /** The number of waiting threads. */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /** Set if the event object is signaled. */
2c95722bb302f4ce9454d04324b09314c0ccc038vboxsync /** The number of threads in the process of waking up. */
0cde281779e97ead3181bbd3b628451fa2b1efe1vboxsync /** The Solaris mutex protecting this structure and pairing up the with the cv. */
0cde281779e97ead3181bbd3b628451fa2b1efe1vboxsync /** The Solaris condition variable. */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync Assert(sizeof(RTSEMEVENTINTERNAL) > sizeof(void *));
d68336e34409fd767807d5ef641a305de4d9ee59vboxsync PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)RTMemAlloc(sizeof(*pEventInt));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync mutex_init(&pEventInt->Mtx, "IPRT Event Semaphore", MUTEX_DRIVER, (void *)ipltospl(DISP_LEVEL));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync cv_init(&pEventInt->Cnd, "IPRT CV", CV_DRIVER, NULL);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgReturn(pEventInt->u32Magic == RTSEMEVENT_MAGIC,
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync ("pEventInt=%p u32Magic=%#x\n", pEventInt, pEventInt->u32Magic),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync ASMAtomicIncU32(&pEventInt->u32Magic); /* make the handle invalid */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /* abort waiting thread, last man cleans up. */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync ASMAtomicXchgU32(&pEventInt->cWaking, pEventInt->cWaking + pEventInt->cWaiters);
0cde281779e97ead3181bbd3b628451fa2b1efe1vboxsync /* the last waking thread is gonna do the cleanup */
0cde281779e97ead3181bbd3b628451fa2b1efe1vboxsync PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;
0cde281779e97ead3181bbd3b628451fa2b1efe1vboxsync AssertMsgReturn(pEventInt->u32Magic == RTSEMEVENT_MAGIC,
0cde281779e97ead3181bbd3b628451fa2b1efe1vboxsync ("pEventInt=%p u32Magic=%#x\n", pEventInt, pEventInt->u32Magic),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsyncstatic int rtSemEventWait(RTSEMEVENT EventSem, unsigned cMillies, bool fInterruptible)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PRTSEMEVENTINTERNAL pEventInt = (PRTSEMEVENTINTERNAL)EventSem;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgReturn(pEventInt->u32Magic == RTSEMEVENT_MAGIC,
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync ("pEventInt=%p u32Magic=%#x\n", pEventInt, pEventInt->u32Magic),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Translate milliseconds into ticks and go to sleep.
0cde281779e97ead3181bbd3b628451fa2b1efe1vboxsync clock_t cTicks = drv_usectohz((clock_t)(cMillies * 1000L));
4aafb1203580a5c145a7bdae57ebf69a36fa4f01vboxsync rc = cv_timedwait_sig(&pEventInt->Cnd, &pEventInt->Mtx, timeout);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = cv_timedwait(&pEventInt->Cnd, &pEventInt->Mtx, timeout);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = cv_wait_sig(&pEventInt->Cnd, &pEventInt->Mtx);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /* Retured due to call to cv_signal() or cv_broadcast() */
0780b79e94db3b60fb4a3057df7c64ba8b1cb75dvboxsync /* Returned due to timeout being reached */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /* Returned due to pending signal */
4aafb1203580a5c145a7bdae57ebf69a36fa4f01vboxsyncRTDECL(int) RTSemEventWait(RTSEMEVENT EventSem, unsigned cMillies)
4aafb1203580a5c145a7bdae57ebf69a36fa4f01vboxsync return rtSemEventWait(EventSem, cMillies, false /* not interruptible */);
4aafb1203580a5c145a7bdae57ebf69a36fa4f01vboxsyncRTDECL(int) RTSemEventWaitNoResume(RTSEMEVENT EventSem, unsigned cMillies)
4aafb1203580a5c145a7bdae57ebf69a36fa4f01vboxsync return rtSemEventWait(EventSem, cMillies, true /* interruptible */);