1 | /* $Id: semfastmutex-r0drv-solaris.c 4178 2007-08-16 15:07:51Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * innotek Portable Runtime - Fast Mutex Semaphores, Ring-0 Driver, Solaris.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*******************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *******************************************************************************/
|
---|
22 | #include "the-solaris-kernel.h"
|
---|
23 |
|
---|
24 | #include <iprt/semaphore.h>
|
---|
25 | #include <iprt/err.h>
|
---|
26 | #include <iprt/alloc.h>
|
---|
27 | #include <iprt/assert.h>
|
---|
28 | #include <iprt/asm.h>
|
---|
29 |
|
---|
30 | #include "internal/magics.h"
|
---|
31 |
|
---|
32 |
|
---|
33 | /*******************************************************************************
|
---|
34 | * Structures and Typedefs *
|
---|
35 | *******************************************************************************/
|
---|
36 | /**
|
---|
37 | * Wrapper for the FreeBSD (sleep) mutex.
|
---|
38 | */
|
---|
39 | typedef struct RTSEMFASTMUTEXINTERNAL
|
---|
40 | {
|
---|
41 | /** Magic value (RTSEMFASTMUTEX_MAGIC). */
|
---|
42 | uint32_t u32Magic;
|
---|
43 | /** The Solaris mutex. */
|
---|
44 | kmutex_t Mtx;
|
---|
45 | } RTSEMFASTMUTEXINTERNAL, *PRTSEMFASTMUTEXINTERNAL;
|
---|
46 |
|
---|
47 |
|
---|
48 | RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX pMutexSem)
|
---|
49 | {
|
---|
50 | AssertCompile(sizeof(RTSEMFASTMUTEXINTERNAL) > sizeof(void *));
|
---|
51 | AssertPtrReturn(pMutexSem, VERR_INVALID_POINTER);
|
---|
52 |
|
---|
53 | PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pFastInt));
|
---|
54 | if (pFastInt)
|
---|
55 | {
|
---|
56 | pFastInt->u32Magic = RTSEMFASTMUTEX_MAGIC;
|
---|
57 | mutex_init (&pFastInt->Mtx, "IPRT Fast Mutex Semaphore", MUTEX_DEFAULT, NULL);
|
---|
58 | *pMutexSem = pFastInt;
|
---|
59 | return VINF_SUCCESS;
|
---|
60 | }
|
---|
61 | return VERR_NO_MEMORY;
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem)
|
---|
66 | {
|
---|
67 | if (MutexSem == NIL_RTSEMFASTMUTEX)
|
---|
68 | return VERR_INVALID_PARAMETER;
|
---|
69 | PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
|
---|
70 | AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER);
|
---|
71 | AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
|
---|
72 | ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),
|
---|
73 | VERR_INVALID_PARAMETER);
|
---|
74 |
|
---|
75 | ASMAtomicXchgU32(&pFastInt->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);
|
---|
76 | mutex_destroy(&pFastInt->Mtx);
|
---|
77 | RTMemFree(pFastInt);
|
---|
78 |
|
---|
79 | return VINF_SUCCESS;
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem)
|
---|
84 | {
|
---|
85 | PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
|
---|
86 | AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER);
|
---|
87 | AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
|
---|
88 | ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),
|
---|
89 | VERR_INVALID_PARAMETER);
|
---|
90 |
|
---|
91 | mutex_enter(&pFastInt->Mtx);
|
---|
92 | return VINF_SUCCESS;
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|
96 | RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX MutexSem)
|
---|
97 | {
|
---|
98 | PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
|
---|
99 | AssertPtrReturn(pFastInt, VERR_INVALID_PARAMETER);
|
---|
100 | AssertMsgReturn(pFastInt->u32Magic == RTSEMFASTMUTEX_MAGIC,
|
---|
101 | ("pFastInt->u32Magic=%RX32 pFastInt=%p\n", pFastInt->u32Magic, pFastInt),
|
---|
102 | VERR_INVALID_PARAMETER);
|
---|
103 |
|
---|
104 | mutex_exit(&pFastInt->Mtx);
|
---|
105 | return VINF_SUCCESS;
|
---|
106 | }
|
---|
107 |
|
---|