semfastmutex-r0drv-freebsd.c revision 47c238f82281a3771c8bfb66858da823ecf03dbc
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * IPRT - Fast Mutex Semaphores, Ring-0 Driver, FreeBSD.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * Permission is hereby granted, free of charge, to any person
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * obtaining a copy of this software and associated documentation
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * files (the "Software"), to deal in the Software without
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * restriction, including without limitation the rights to use,
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * copy, modify, merge, publish, distribute, sublicense, and/or sell
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * copies of the Software, and to permit persons to whom the
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * Software is furnished to do so, subject to the following
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * conditions:
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * The above copyright notice and this permission notice shall be
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * included in all copies or substantial portions of the Software.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * OTHER DEALINGS IN THE SOFTWARE.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/*******************************************************************************
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync* Header Files *
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync*******************************************************************************/
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync/*******************************************************************************
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync* Structures and Typedefs *
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync*******************************************************************************/
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync * Wrapper for the FreeBSD (sleep) mutex.
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync /** Magic value (RTSEMFASTMUTEX_MAGIC). */
94e4227f21b6d46df0f75f5cd1f2edf16b71ef26vboxsync /** The FreeBSD shared/exclusive lock mutex. */
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsyncRTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx)
1f1986470af9f0bb750dd859b142dc2e952deb20vboxsync AssertCompile(sizeof(RTSEMFASTMUTEXINTERNAL) > sizeof(void *));
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync PRTSEMFASTMUTEXINTERNAL pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAllocZ(sizeof(*pThis));
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync sx_init(&pThis->SxLock, "IPRT Fast Mutex Semaphore");
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsyncRTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx)
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync ASMAtomicWriteU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsyncRTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx)
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsyncRTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx)
47c238f82281a3771c8bfb66858da823ecf03dbcvboxsync AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);