~ubuntu-branches/ubuntu/gutsy/virtualbox-ose/gutsy

« back to all changes in this revision

Viewing changes to src/VBox/Runtime/r0drv/solaris/spinlock-r0drv-solaris.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-09-08 16:44:58 UTC
  • Revision ID: james.westby@ubuntu.com-20070908164458-wao29470vqtr8ksy
Tags: upstream-1.5.0-dfsg2
ImportĀ upstreamĀ versionĀ 1.5.0-dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: spinlock-r0drv-solaris.c 4178 2007-08-16 15:07:51Z 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
 */
 
38
typedef struct RTSPINLOCKINTERNAL
 
39
{
 
40
    /** Spinlock magic value (RTSPINLOCK_MAGIC). */
 
41
    uint32_t volatile   u32Magic;
 
42
    /** A Solaris spinlock. */
 
43
    kmutex_t            Mtx;
 
44
} RTSPINLOCKINTERNAL, *PRTSPINLOCKINTERNAL;
 
45
 
 
46
 
 
47
RTDECL(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
 
 
67
RTDECL(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
 
 
89
RTDECL(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
 
 
100
RTDECL(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
 
 
111
RTDECL(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
 
 
122
RTDECL(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