VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/solaris/spinlock-r0drv-solaris.c@ 4072

Last change on this file since 4072 was 4071, checked in by vboxsync, 18 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1/* $Id: spinlock-r0drv-solaris.c 4071 2007-08-07 17:07:59Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - Spinlocks, 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* Header Files *
20*******************************************************************************/
21#include "the-solaris-kernel.h"
22
23#include <iprt/spinlock.h>
24#include <iprt/err.h>
25#include <iprt/alloc.h>
26#include <iprt/assert.h>
27#include <iprt/asm.h>
28
29#include "internal/magics.h"
30
31
32/*******************************************************************************
33* Structures and Typedefs *
34*******************************************************************************/
35/**
36 * Wrapper for the struct mutex type.
37 */
38typedef struct RTSPINLOCKINTERNAL
39{
40 /** Spinlock magic value (RTSPINLOCK_MAGIC). */
41 uint32_t volatile u32Magic;
42 /** A Solaris spinlock. */
43 struct mutex Mtx;
44} RTSPINLOCKINTERNAL, *PRTSPINLOCKINTERNAL;
45
46
47RTDECL(int) RTSpinlockCreate(PRTSPINLOCK pSpinlock)
48{
49 /*
50 * Allocate.
51 */
52 AssertCompile(sizeof(RTSPINLOCKINTERNAL) > sizeof(void *));
53 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)RTMemAlloc(sizeof(*pSpinlockInt));
54 if (!pSpinlockInt)
55 return VERR_NO_MEMORY;
56
57 /*
58 * Initialize & return.
59 */
60 pSpinlockInt->u32Magic = RTSPINLOCK_MAGIC;
61 mutex_init(&pSpinlockInt->Mtx, "iprt-spinlock", MUTEX_SPIN, NULL);
62 *pSpinlock = pSpinlockInt;
63 return VINF_SUCCESS;
64}
65
66
67RTDECL(int) RTSpinlockDestroy(RTSPINLOCK Spinlock)
68{
69 /*
70 * Validate input.
71 */
72 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
73 if (!pSpinlockInt)
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);
78
79 /*
80 * Make the lock invalid and release the memory.
81 */
82 ASMAtomicIncU32(&pSpinlockInt->u32Magic);
83 mutex_destroy(&pSpinlockInt->Mtx);
84 RTMemFree(pSpinlockInt);
85 return VINF_SUCCESS;
86}
87
88
89RTDECL(void) RTSpinlockAcquireNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
90{
91 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
92 AssertPtr(pSpinlockInt);
93 Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
94 NOREF(pTmp);
95
96 mutex_enter(&pSpinlockInt->Mtx);
97}
98
99
100RTDECL(void) RTSpinlockReleaseNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
101{
102 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
103 AssertPtr(pSpinlockInt);
104 Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
105 NOREF(pTmp);
106
107 mutex_exit(&pSpinlockInt->Mtx);
108}
109
110
111RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
112{
113 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
114 AssertPtr(pSpinlockInt);
115 Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
116 NOREF(pTmp);
117
118 mutex_enter(&pSpinlockInt->Mtx);
119}
120
121
122RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
123{
124 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
125 AssertPtr(pSpinlockInt);
126 Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
127 NOREF(pTmp);
128
129 mutex_exit(&pSpinlockInt->Mtx);
130}
131
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette