1
/* $Id: spinlock-r0drv-solaris.c 4178 2007-08-16 15:07:51Z vboxsync $ */
3
* innotek Portable Runtime - Spinlocks, Ring-0 Driver, Solaris.
7
* Copyright (C) 2006-2007 innotek GmbH
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.
18
/*******************************************************************************
20
*******************************************************************************/
21
#include "the-solaris-kernel.h"
23
#include <iprt/spinlock.h>
25
#include <iprt/alloc.h>
26
#include <iprt/assert.h>
29
#include "internal/magics.h"
32
/*******************************************************************************
33
* Structures and Typedefs *
34
*******************************************************************************/
36
* Wrapper for the struct mutex type.
38
typedef struct RTSPINLOCKINTERNAL
40
/** Spinlock magic value (RTSPINLOCK_MAGIC). */
41
uint32_t volatile u32Magic;
42
/** A Solaris spinlock. */
44
} RTSPINLOCKINTERNAL, *PRTSPINLOCKINTERNAL;
47
RTDECL(int) RTSpinlockCreate(PRTSPINLOCK pSpinlock)
52
AssertCompile(sizeof(RTSPINLOCKINTERNAL) > sizeof(void *));
53
PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)RTMemAlloc(sizeof(*pSpinlockInt));
55
return VERR_NO_MEMORY;
58
* Initialize & return.
60
pSpinlockInt->u32Magic = RTSPINLOCK_MAGIC;
61
mutex_init(&pSpinlockInt->Mtx, "IPRT Spinlock", MUTEX_SPIN, NULL);
62
*pSpinlock = pSpinlockInt;
67
RTDECL(int) RTSpinlockDestroy(RTSPINLOCK Spinlock)
72
PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
74
return VERR_INVALID_PARAMETER;
75
AssertMsgReturn(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC,
76
("Invalid spinlock %p magic=%#x\n", pSpinlockInt, pSpinlockInt->u32Magic),
77
VERR_INVALID_PARAMETER);
80
* Make the lock invalid and release the memory.
82
ASMAtomicIncU32(&pSpinlockInt->u32Magic);
83
mutex_destroy(&pSpinlockInt->Mtx);
84
RTMemFree(pSpinlockInt);
89
RTDECL(void) RTSpinlockAcquireNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
91
PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
92
AssertPtr(pSpinlockInt);
93
Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
96
mutex_enter(&pSpinlockInt->Mtx);
100
RTDECL(void) RTSpinlockReleaseNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
102
PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
103
AssertPtr(pSpinlockInt);
104
Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
107
mutex_exit(&pSpinlockInt->Mtx);
111
RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
113
PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
114
AssertPtr(pSpinlockInt);
115
Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
118
mutex_enter(&pSpinlockInt->Mtx);
122
RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
124
PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
125
AssertPtr(pSpinlockInt);
126
Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
129
mutex_exit(&pSpinlockInt->Mtx);