[1] | 1 | /* $Id: semmutex-r0drv-darwin.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[28503] | 3 | * IPRT - Mutex Semaphores, Ring-0 Driver, Darwin.
|
---|
[1] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[1] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
[5999] | 11 | *
|
---|
[96407] | 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
[5999] | 25 | * The contents of this file may alternatively be used under the terms
|
---|
| 26 | * of the Common Development and Distribution License Version 1.0
|
---|
[96407] | 27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
| 28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
[5999] | 29 | * CDDL are applicable instead of those of the GPL.
|
---|
| 30 | *
|
---|
| 31 | * You may elect to license modified versions of this file under the
|
---|
| 32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
[96407] | 33 | *
|
---|
| 34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
[1] | 35 | */
|
---|
| 36 |
|
---|
| 37 |
|
---|
[57358] | 38 | /*********************************************************************************************************************************
|
---|
| 39 | * Header Files *
|
---|
| 40 | *********************************************************************************************************************************/
|
---|
[36192] | 41 | #define RTSEMMUTEX_WITHOUT_REMAPPING
|
---|
[1] | 42 | #include "the-darwin-kernel.h"
|
---|
[22052] | 43 | #include "internal/iprt.h"
|
---|
| 44 | #include <iprt/semaphore.h>
|
---|
[1816] | 45 |
|
---|
[28515] | 46 | #include <iprt/asm.h>
|
---|
[29255] | 47 | #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
|
---|
| 48 | # include <iprt/asm-amd64-x86.h>
|
---|
| 49 | #endif
|
---|
[1] | 50 | #include <iprt/assert.h>
|
---|
| 51 | #include <iprt/err.h>
|
---|
[28515] | 52 | #include <iprt/mem.h>
|
---|
[22052] | 53 | #include <iprt/thread.h>
|
---|
[1] | 54 |
|
---|
[1816] | 55 | #include "internal/magics.h"
|
---|
[1] | 56 |
|
---|
[1816] | 57 |
|
---|
[57358] | 58 | /*********************************************************************************************************************************
|
---|
| 59 | * Structures and Typedefs *
|
---|
| 60 | *********************************************************************************************************************************/
|
---|
[1] | 61 | /**
|
---|
| 62 | * Darwin mutex semaphore.
|
---|
| 63 | */
|
---|
| 64 | typedef struct RTSEMMUTEXINTERNAL
|
---|
| 65 | {
|
---|
| 66 | /** Magic value (RTSEMMUTEX_MAGIC). */
|
---|
| 67 | uint32_t volatile u32Magic;
|
---|
[28515] | 68 | /** The number of waiting threads. */
|
---|
| 69 | uint32_t cWaiters;
|
---|
| 70 | /** The number of references. */
|
---|
| 71 | uint32_t volatile cRefs;
|
---|
| 72 | /** The number of recursions. */
|
---|
| 73 | uint32_t cRecursions;
|
---|
| 74 | /** The handle of the owner thread. */
|
---|
| 75 | RTNATIVETHREAD hNativeOwner;
|
---|
| 76 | /** The spinlock protecting us. */
|
---|
| 77 | lck_spin_t *pSpinlock;
|
---|
[1] | 78 | } RTSEMMUTEXINTERNAL, *PRTSEMMUTEXINTERNAL;
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 |
|
---|
[28515] | 82 | RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX phMutexSem)
|
---|
| 83 | {
|
---|
| 84 | return RTSemMutexCreateEx(phMutexSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, NULL);
|
---|
| 85 | }
|
---|
[1] | 86 |
|
---|
| 87 |
|
---|
[28515] | 88 | RTDECL(int) RTSemMutexCreateEx(PRTSEMMUTEX phMutexSem, uint32_t fFlags,
|
---|
| 89 | RTLOCKVALCLASS hClass, uint32_t uSubClass, const char *pszNameFmt, ...)
|
---|
[1] | 90 | {
|
---|
[63509] | 91 | RT_NOREF(hClass, uSubClass, pszNameFmt);
|
---|
[28515] | 92 | AssertReturn(!(fFlags & ~RTSEMMUTEX_FLAGS_NO_LOCK_VAL), VERR_INVALID_PARAMETER);
|
---|
[22052] | 93 | RT_ASSERT_PREEMPTIBLE();
|
---|
[57246] | 94 | IPRT_DARWIN_SAVE_EFL_AC();
|
---|
[28515] | 95 |
|
---|
[1] | 96 | AssertCompile(sizeof(RTSEMMUTEXINTERNAL) > sizeof(void *));
|
---|
[25720] | 97 | PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)RTMemAlloc(sizeof(*pThis));
|
---|
| 98 | if (pThis)
|
---|
[1] | 99 | {
|
---|
[28515] | 100 | pThis->u32Magic = RTSEMMUTEX_MAGIC;
|
---|
| 101 | pThis->cWaiters = 0;
|
---|
| 102 | pThis->cRefs = 1;
|
---|
| 103 | pThis->cRecursions = 0;
|
---|
| 104 | pThis->hNativeOwner = NIL_RTNATIVETHREAD;
|
---|
[1] | 105 | Assert(g_pDarwinLockGroup);
|
---|
[28515] | 106 | pThis->pSpinlock = lck_spin_alloc_init(g_pDarwinLockGroup, LCK_ATTR_NULL);
|
---|
| 107 | if (pThis->pSpinlock)
|
---|
[1] | 108 | {
|
---|
[28515] | 109 | *phMutexSem = pThis;
|
---|
[57246] | 110 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
[1] | 111 | return VINF_SUCCESS;
|
---|
| 112 | }
|
---|
[28515] | 113 |
|
---|
[25720] | 114 | RTMemFree(pThis);
|
---|
[1] | 115 | }
|
---|
[57246] | 116 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
[1] | 117 | return VERR_NO_MEMORY;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 |
|
---|
[28515] | 121 | /**
|
---|
| 122 | * Called when the refcount reaches zero.
|
---|
| 123 | */
|
---|
| 124 | static void rtSemMutexDarwinFree(PRTSEMMUTEXINTERNAL pThis)
|
---|
| 125 | {
|
---|
[57246] | 126 | IPRT_DARWIN_SAVE_EFL_AC();
|
---|
| 127 |
|
---|
[28515] | 128 | lck_spin_unlock(pThis->pSpinlock);
|
---|
| 129 | lck_spin_destroy(pThis->pSpinlock, g_pDarwinLockGroup);
|
---|
| 130 | RTMemFree(pThis);
|
---|
[57246] | 131 |
|
---|
| 132 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
[28515] | 133 | }
|
---|
| 134 |
|
---|
| 135 |
|
---|
[25721] | 136 | RTDECL(int) RTSemMutexDestroy(RTSEMMUTEX hMutexSem)
|
---|
[1] | 137 | {
|
---|
| 138 | /*
|
---|
| 139 | * Validate input.
|
---|
| 140 | */
|
---|
[25721] | 141 | PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)hMutexSem;
|
---|
[54374] | 142 | if (pThis == NIL_RTSEMMUTEX)
|
---|
[1] | 143 | return VERR_INVALID_PARAMETER;
|
---|
[25720] | 144 | AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
|
---|
[28515] | 145 | AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
|
---|
[22052] | 146 | RT_ASSERT_INTS_ON();
|
---|
[57246] | 147 | IPRT_DARWIN_SAVE_EFL_AC();
|
---|
[1] | 148 |
|
---|
| 149 | /*
|
---|
[28515] | 150 | * Kill it, wake up all waiting threads and release the reference.
|
---|
[1] | 151 | */
|
---|
[28515] | 152 | AssertReturn(ASMAtomicCmpXchgU32(&pThis->u32Magic, ~RTSEMMUTEX_MAGIC, RTSEMMUTEX_MAGIC), VERR_INVALID_HANDLE);
|
---|
| 153 | lck_spin_lock(pThis->pSpinlock);
|
---|
[1] | 154 |
|
---|
[28515] | 155 | if (pThis->cWaiters > 0)
|
---|
| 156 | thread_wakeup_prim((event_t)pThis, FALSE /* one_thread */, THREAD_RESTART);
|
---|
[1] | 157 |
|
---|
[28515] | 158 | if (ASMAtomicDecU32(&pThis->cRefs) == 0)
|
---|
| 159 | rtSemMutexDarwinFree(pThis);
|
---|
| 160 | else
|
---|
| 161 | lck_spin_unlock(pThis->pSpinlock);
|
---|
| 162 |
|
---|
[57246] | 163 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
[1] | 164 | return VINF_SUCCESS;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 |
|
---|
[28515] | 168 | /**
|
---|
| 169 | * Internal worker for the sleep scenario.
|
---|
| 170 | *
|
---|
| 171 | * Called owning the spinlock, returns without it.
|
---|
| 172 | *
|
---|
| 173 | * @returns IPRT status code.
|
---|
| 174 | * @param pThis The mutex instance.
|
---|
| 175 | * @param cMillies The timeout.
|
---|
| 176 | * @param fInterruptible Whether it's interruptible
|
---|
| 177 | * (RTSemMutexRequestNoResume) or not
|
---|
| 178 | * (RTSemMutexRequest).
|
---|
| 179 | * @param hNativeSelf The thread handle of the caller.
|
---|
| 180 | */
|
---|
| 181 | static int rtR0SemMutexDarwinRequestSleep(PRTSEMMUTEXINTERNAL pThis, RTMSINTERVAL cMillies,
|
---|
| 182 | wait_interrupt_t fInterruptible, RTNATIVETHREAD hNativeSelf)
|
---|
[1] | 183 | {
|
---|
| 184 | /*
|
---|
[28515] | 185 | * Grab a reference and indicate that we're waiting.
|
---|
[1] | 186 | */
|
---|
[28515] | 187 | pThis->cWaiters++;
|
---|
| 188 | ASMAtomicIncU32(&pThis->cRefs);
|
---|
[1] | 189 |
|
---|
| 190 | /*
|
---|
[28515] | 191 | * Go to sleep, use the address of the mutex instance as sleep/blocking/event id.
|
---|
[1] | 192 | */
|
---|
[28515] | 193 | wait_result_t rcWait;
|
---|
[1] | 194 | if (cMillies == RT_INDEFINITE_WAIT)
|
---|
[28515] | 195 | rcWait = lck_spin_sleep(pThis->pSpinlock, LCK_SLEEP_DEFAULT, (event_t)pThis, fInterruptible);
|
---|
[1] | 196 | else
|
---|
| 197 | {
|
---|
[28515] | 198 | uint64_t u64AbsTime;
|
---|
| 199 | nanoseconds_to_absolutetime(cMillies * UINT64_C(1000000), &u64AbsTime);
|
---|
| 200 | u64AbsTime += mach_absolute_time();
|
---|
| 201 |
|
---|
| 202 | rcWait = lck_spin_sleep_deadline(pThis->pSpinlock, LCK_SLEEP_DEFAULT,
|
---|
| 203 | (event_t)pThis, fInterruptible, u64AbsTime);
|
---|
[1] | 204 | }
|
---|
[57074] | 205 |
|
---|
[28515] | 206 | /*
|
---|
| 207 | * Translate the rc.
|
---|
| 208 | */
|
---|
| 209 | int rc;
|
---|
| 210 | switch (rcWait)
|
---|
[1] | 211 | {
|
---|
[28515] | 212 | case THREAD_AWAKENED:
|
---|
| 213 | if (RT_LIKELY(pThis->u32Magic == RTSEMMUTEX_MAGIC))
|
---|
| 214 | {
|
---|
| 215 | if (RT_LIKELY( pThis->cRecursions == 0
|
---|
| 216 | && pThis->hNativeOwner == NIL_RTNATIVETHREAD))
|
---|
| 217 | {
|
---|
| 218 | pThis->cRecursions = 1;
|
---|
| 219 | pThis->hNativeOwner = hNativeSelf;
|
---|
| 220 | rc = VINF_SUCCESS;
|
---|
| 221 | }
|
---|
| 222 | else
|
---|
| 223 | {
|
---|
| 224 | Assert(pThis->cRecursions == 0);
|
---|
| 225 | Assert(pThis->hNativeOwner == NIL_RTNATIVETHREAD);
|
---|
| 226 | rc = VERR_INTERNAL_ERROR_3;
|
---|
| 227 | }
|
---|
| 228 | }
|
---|
| 229 | else
|
---|
| 230 | rc = VERR_SEM_DESTROYED;
|
---|
| 231 | break;
|
---|
| 232 |
|
---|
| 233 | case THREAD_TIMED_OUT:
|
---|
| 234 | Assert(cMillies != RT_INDEFINITE_WAIT);
|
---|
| 235 | rc = VERR_TIMEOUT;
|
---|
| 236 | break;
|
---|
| 237 |
|
---|
| 238 | case THREAD_INTERRUPTED:
|
---|
| 239 | Assert(fInterruptible);
|
---|
| 240 | rc = VERR_INTERRUPTED;
|
---|
| 241 | break;
|
---|
| 242 |
|
---|
| 243 | case THREAD_RESTART:
|
---|
| 244 | Assert(pThis->u32Magic == ~RTSEMMUTEX_MAGIC);
|
---|
| 245 | rc = VERR_SEM_DESTROYED;
|
---|
| 246 | break;
|
---|
| 247 |
|
---|
[1] | 248 | default:
|
---|
[28515] | 249 | AssertMsgFailed(("rcWait=%d\n", rcWait));
|
---|
| 250 | rc = VERR_GENERAL_FAILURE;
|
---|
| 251 | break;
|
---|
[1] | 252 | }
|
---|
[28515] | 253 |
|
---|
| 254 | /*
|
---|
| 255 | * Dereference it and quit the lock.
|
---|
| 256 | */
|
---|
| 257 | Assert(pThis->cWaiters > 0);
|
---|
| 258 | pThis->cWaiters--;
|
---|
| 259 |
|
---|
| 260 | Assert(pThis->cRefs > 0);
|
---|
| 261 | if (RT_UNLIKELY(ASMAtomicDecU32(&pThis->cRefs) == 0))
|
---|
| 262 | rtSemMutexDarwinFree(pThis);
|
---|
| 263 | else
|
---|
| 264 | lck_spin_unlock(pThis->pSpinlock);
|
---|
| 265 | return rc;
|
---|
[1] | 266 | }
|
---|
| 267 |
|
---|
| 268 |
|
---|
[28515] | 269 | /**
|
---|
| 270 | * Internal worker for RTSemMutexRequest and RTSemMutexRequestNoResume
|
---|
| 271 | *
|
---|
| 272 | * @returns IPRT status code.
|
---|
| 273 | * @param hMutexSem The mutex handle.
|
---|
| 274 | * @param cMillies The timeout.
|
---|
| 275 | * @param fInterruptible Whether it's interruptible
|
---|
| 276 | * (RTSemMutexRequestNoResume) or not
|
---|
| 277 | * (RTSemMutexRequest).
|
---|
| 278 | */
|
---|
| 279 | DECLINLINE(int) rtR0SemMutexDarwinRequest(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies, wait_interrupt_t fInterruptible)
|
---|
| 280 | {
|
---|
| 281 | /*
|
---|
| 282 | * Validate input.
|
---|
| 283 | */
|
---|
| 284 | PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)hMutexSem;
|
---|
| 285 | AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
|
---|
| 286 | AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
|
---|
| 287 | RT_ASSERT_PREEMPTIBLE();
|
---|
[57246] | 288 | IPRT_DARWIN_SAVE_EFL_AC();
|
---|
[28515] | 289 |
|
---|
| 290 | /*
|
---|
| 291 | * Grab the lock and check out the state.
|
---|
| 292 | */
|
---|
| 293 | RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf();
|
---|
| 294 | int rc = VINF_SUCCESS;
|
---|
| 295 | lck_spin_lock(pThis->pSpinlock);
|
---|
| 296 |
|
---|
| 297 | /* Recursive call? */
|
---|
| 298 | if (pThis->hNativeOwner == hNativeSelf)
|
---|
| 299 | {
|
---|
| 300 | Assert(pThis->cRecursions > 0);
|
---|
| 301 | Assert(pThis->cRecursions < 256);
|
---|
| 302 | pThis->cRecursions++;
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | /* Is it free and nobody ahead of us in the queue? */
|
---|
| 306 | else if ( pThis->hNativeOwner == NIL_RTNATIVETHREAD
|
---|
| 307 | && pThis->cWaiters == 0)
|
---|
| 308 | {
|
---|
| 309 | pThis->hNativeOwner = hNativeSelf;
|
---|
| 310 | pThis->cRecursions = 1;
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 | /* Polling call? */
|
---|
| 314 | else if (cMillies == 0)
|
---|
| 315 | rc = VERR_TIMEOUT;
|
---|
| 316 |
|
---|
| 317 | /* Yawn, time for a nap... */
|
---|
| 318 | else
|
---|
[57246] | 319 | {
|
---|
| 320 | rc = rtR0SemMutexDarwinRequestSleep(pThis, cMillies, fInterruptible, hNativeSelf);
|
---|
| 321 | IPRT_DARWIN_RESTORE_EFL_ONLY_AC();
|
---|
| 322 | return rc;
|
---|
| 323 | }
|
---|
[28515] | 324 |
|
---|
| 325 | lck_spin_unlock(pThis->pSpinlock);
|
---|
[57246] | 326 | IPRT_DARWIN_RESTORE_EFL_ONLY_AC();
|
---|
[28515] | 327 | return rc;
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 |
|
---|
| 331 | RTDECL(int) RTSemMutexRequest(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies)
|
---|
| 332 | {
|
---|
| 333 | return rtR0SemMutexDarwinRequest(hMutexSem, cMillies, THREAD_UNINT);
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 |
|
---|
| 337 | RTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
|
---|
| 338 | {
|
---|
[63509] | 339 | RT_SRC_POS_NOREF(); RT_NOREF(uId);
|
---|
[28515] | 340 | return RTSemMutexRequest(hMutexSem, cMillies);
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 |
|
---|
| 344 | RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies)
|
---|
| 345 | {
|
---|
| 346 | return rtR0SemMutexDarwinRequest(hMutexSem, cMillies, THREAD_ABORTSAFE);
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 |
|
---|
| 350 | RTDECL(int) RTSemMutexRequestNoResumeDebug(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
|
---|
| 351 | {
|
---|
[63509] | 352 | RT_SRC_POS_NOREF(); RT_NOREF(uId);
|
---|
[28515] | 353 | return RTSemMutexRequestNoResume(hMutexSem, cMillies);
|
---|
| 354 | }
|
---|
| 355 |
|
---|
| 356 |
|
---|
[25721] | 357 | RTDECL(int) RTSemMutexRelease(RTSEMMUTEX hMutexSem)
|
---|
[1] | 358 | {
|
---|
| 359 | /*
|
---|
| 360 | * Validate input.
|
---|
| 361 | */
|
---|
[25721] | 362 | PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)hMutexSem;
|
---|
[25720] | 363 | AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
|
---|
[28515] | 364 | AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
|
---|
[22052] | 365 | RT_ASSERT_PREEMPTIBLE();
|
---|
[57246] | 366 | IPRT_DARWIN_SAVE_EFL_AC();
|
---|
[1] | 367 |
|
---|
| 368 | /*
|
---|
[28515] | 369 | * Take the lock and do the job.
|
---|
[1] | 370 | */
|
---|
[28515] | 371 | RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf();
|
---|
| 372 | int rc = VINF_SUCCESS;
|
---|
| 373 | lck_spin_lock(pThis->pSpinlock);
|
---|
| 374 |
|
---|
| 375 | if (pThis->hNativeOwner == hNativeSelf)
|
---|
| 376 | {
|
---|
| 377 | Assert(pThis->cRecursions > 0);
|
---|
| 378 | if (--pThis->cRecursions == 0)
|
---|
| 379 | {
|
---|
| 380 | pThis->hNativeOwner = NIL_RTNATIVETHREAD;
|
---|
| 381 | if (pThis->cWaiters > 0)
|
---|
[57246] | 382 | thread_wakeup_prim((event_t)pThis, TRUE /* one_thread */, THREAD_AWAKENED);
|
---|
[28515] | 383 |
|
---|
| 384 | }
|
---|
| 385 | }
|
---|
| 386 | else
|
---|
| 387 | rc = VERR_NOT_OWNER;
|
---|
| 388 |
|
---|
| 389 | lck_spin_unlock(pThis->pSpinlock);
|
---|
| 390 |
|
---|
| 391 | AssertRC(rc);
|
---|
[57246] | 392 | IPRT_DARWIN_RESTORE_EFL_ONLY_AC();
|
---|
[1] | 393 | return VINF_SUCCESS;
|
---|
| 394 | }
|
---|
| 395 |
|
---|
| 396 |
|
---|
[28515] | 397 | RTDECL(bool) RTSemMutexIsOwned(RTSEMMUTEX hMutexSem)
|
---|
| 398 | {
|
---|
| 399 | /*
|
---|
| 400 | * Validate.
|
---|
| 401 | */
|
---|
| 402 | RTSEMMUTEXINTERNAL *pThis = hMutexSem;
|
---|
| 403 | AssertPtrReturn(pThis, false);
|
---|
| 404 | AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, false);
|
---|
[57246] | 405 | IPRT_DARWIN_SAVE_EFL_AC();
|
---|
[28515] | 406 |
|
---|
| 407 | /*
|
---|
| 408 | * Take the lock and do the check.
|
---|
| 409 | */
|
---|
| 410 | lck_spin_lock(pThis->pSpinlock);
|
---|
| 411 | bool fRc = pThis->hNativeOwner != NIL_RTNATIVETHREAD;
|
---|
| 412 | lck_spin_unlock(pThis->pSpinlock);
|
---|
| 413 |
|
---|
[57246] | 414 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
[28515] | 415 | return fRc;
|
---|
| 416 | }
|
---|
| 417 |
|
---|