1 | /* $Id: semfastmutex-r0drv-solaris.c 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Fast Mutex Semaphores, Ring-0 Driver, Solaris.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2022 Oracle Corporation
|
---|
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 (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*********************************************************************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *********************************************************************************************************************************/
|
---|
31 | #include "the-solaris-kernel.h"
|
---|
32 | #include "internal/iprt.h"
|
---|
33 | #include <iprt/semaphore.h>
|
---|
34 |
|
---|
35 | #include <iprt/asm.h>
|
---|
36 | #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
|
---|
37 | # include <iprt/asm-amd64-x86.h>
|
---|
38 | #endif
|
---|
39 | #include <iprt/assert.h>
|
---|
40 | #include <iprt/errcore.h>
|
---|
41 | #include <iprt/mem.h>
|
---|
42 | #include <iprt/thread.h>
|
---|
43 | #include "internal/magics.h"
|
---|
44 |
|
---|
45 |
|
---|
46 | /*********************************************************************************************************************************
|
---|
47 | * Structures and Typedefs *
|
---|
48 | *********************************************************************************************************************************/
|
---|
49 | /**
|
---|
50 | * Wrapper for the Solaris mutex.
|
---|
51 | */
|
---|
52 | typedef struct RTSEMFASTMUTEXINTERNAL
|
---|
53 | {
|
---|
54 | /** Magic value (RTSEMFASTMUTEX_MAGIC). */
|
---|
55 | uint32_t u32Magic;
|
---|
56 | /** The Solaris mutex. */
|
---|
57 | krwlock_t Mtx;
|
---|
58 | } RTSEMFASTMUTEXINTERNAL, *PRTSEMFASTMUTEXINTERNAL;
|
---|
59 |
|
---|
60 |
|
---|
61 |
|
---|
62 | RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx)
|
---|
63 | {
|
---|
64 | AssertCompile(sizeof(RTSEMFASTMUTEXINTERNAL) > sizeof(void *));
|
---|
65 | AssertPtrReturn(phFastMtx, VERR_INVALID_POINTER);
|
---|
66 | RT_ASSERT_PREEMPTIBLE();
|
---|
67 |
|
---|
68 | PRTSEMFASTMUTEXINTERNAL pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pThis));
|
---|
69 | if (pThis)
|
---|
70 | {
|
---|
71 | pThis->u32Magic = RTSEMFASTMUTEX_MAGIC;
|
---|
72 | rw_init (&pThis->Mtx, "RWLOCK", RW_DRIVER, NULL);
|
---|
73 |
|
---|
74 | *phFastMtx = pThis;
|
---|
75 | return VINF_SUCCESS;
|
---|
76 | }
|
---|
77 | return VERR_NO_MEMORY;
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 | RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx)
|
---|
82 | {
|
---|
83 | PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
|
---|
84 | if (pThis == NIL_RTSEMFASTMUTEX)
|
---|
85 | return VINF_SUCCESS;
|
---|
86 | AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
|
---|
87 | AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
|
---|
88 | RT_ASSERT_INTS_ON();
|
---|
89 |
|
---|
90 | ASMAtomicXchgU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);
|
---|
91 | rw_destroy(&pThis->Mtx);
|
---|
92 | RTMemFree(pThis);
|
---|
93 |
|
---|
94 | return VINF_SUCCESS;
|
---|
95 | }
|
---|
96 |
|
---|
97 |
|
---|
98 | RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx)
|
---|
99 | {
|
---|
100 | PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
|
---|
101 | AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
|
---|
102 | AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
|
---|
103 | RT_ASSERT_PREEMPTIBLE();
|
---|
104 |
|
---|
105 | rw_enter(&pThis->Mtx, RW_WRITER);
|
---|
106 | return VINF_SUCCESS;
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx)
|
---|
111 | {
|
---|
112 | PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
|
---|
113 | AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
|
---|
114 | AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
|
---|
115 | RT_ASSERT_INTS_ON();
|
---|
116 |
|
---|
117 | rw_exit(&pThis->Mtx);
|
---|
118 | return VINF_SUCCESS;
|
---|
119 | }
|
---|
120 |
|
---|