semfastmutex-r0drv-os2.cpp revision d1c5a03c19683c719b94496bb998fde2f2e5e622
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * InnoTek Portable Runtime - Fast Mutex Semaphores, Ring-0 Driver, OS/2.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Permission is hereby granted, free of charge, to any person
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * obtaining a copy of this software and associated documentation
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * files (the "Software"), to deal in the Software without
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * restriction, including without limitation the rights to use,
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * copy, modify, merge, publish, distribute, sublicense, and/or sell
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * copies of the Software, and to permit persons to whom the
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Software is furnished to do so, subject to the following
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * conditions:
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * The above copyright notice and this permission notice shall be
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * included in all copies or substantial portions of the Software.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * OTHER DEALINGS IN THE SOFTWARE.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/*******************************************************************************
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync* Header Files *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync*******************************************************************************/
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/*******************************************************************************
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync* Structures and Typedefs *
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync*******************************************************************************/
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync * Wrapper for the OS/2 KEE mutex semaphore.
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /** Magic value (RTSEMFASTMUTEX_MAGIC). */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync /** The KEE mutex. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/** Magic value for RTSEMFASTMUTEXINTERNAL::u32Magic (John Ronald Reuel Tolkien). */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync/** Dead magic value. */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync#define RTSEMFASTMUTEX_MAGIC_DEAD 0x0000000 /// @todo
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncRTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX pMutexSem)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync AssertCompile(sizeof(RTSEMFASTMUTEXINTERNAL) > sizeof(void *));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pFastInt));
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncRTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync if (MutexSem == NIL_RTSEMFASTMUTEX) /* don't bitch */
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync ASMAtomicXchgU32(&pFastInt->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncRTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsyncRTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX MutexSem)
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
d1c5a03c19683c719b94496bb998fde2f2e5e622vboxsync ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),