VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/nt/semfastmutex-r0drv-nt.cpp@ 7331

Last change on this file since 7331 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1/* $Id: semfastmutex-r0drv-nt.cpp 5999 2007-12-07 15:05:06Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - Fast Mutex Semaphores, Ring-0 Driver, NT.
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 (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/*******************************************************************************
30* Header Files *
31*******************************************************************************/
32#include "the-nt-kernel.h"
33#include <iprt/semaphore.h>
34#include <iprt/alloc.h>
35#include <iprt/assert.h>
36#include <iprt/asm.h>
37#include <iprt/err.h>
38
39#include "internal/magics.h"
40
41
42/*******************************************************************************
43* Structures and Typedefs *
44*******************************************************************************/
45/**
46 * Wrapper for the linux semaphore structure.
47 */
48typedef struct RTSEMFASTMUTEXINTERNAL
49{
50 /** Magic value (RTSEMFASTMUTEX_MAGIC). */
51 uint32_t u32Magic;
52 /** the NT fast mutex. */
53 FAST_MUTEX Mutex;
54} RTSEMFASTMUTEXINTERNAL, *PRTSEMFASTMUTEXINTERNAL;
55
56
57
58RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX pMutexSem)
59{
60 /*
61 * Allocate.
62 */
63 PRTSEMFASTMUTEXINTERNAL pFastInt;
64 Assert(sizeof(*pFastInt) > sizeof(void *));
65 pFastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pFastInt));
66 if (!pFastInt)
67 return VERR_NO_MEMORY;
68
69 /*
70 * Initialize.
71 */
72 pFastInt->u32Magic = RTSEMFASTMUTEX_MAGIC;
73 ExInitializeFastMutex(&pFastInt->Mutex);
74 *pMutexSem = pFastInt;
75 return VINF_SUCCESS;
76}
77
78
79RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem)
80{
81 /*
82 * Validate.
83 */
84 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
85 if (!pFastInt)
86 return VERR_INVALID_PARAMETER;
87 if (pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC)
88 {
89 AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt->u32Magic, pFastInt));
90 return VERR_INVALID_PARAMETER;
91 }
92
93 ASMAtomicIncU32(&pFastInt->u32Magic);
94 RTMemFree(pFastInt);
95 return VINF_SUCCESS;
96}
97
98
99RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem)
100{
101 /*
102 * Validate.
103 */
104 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
105 if ( !pFastInt
106 || pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC)
107 {
108 AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt ? pFastInt->u32Magic : 0, pFastInt));
109 return VERR_INVALID_PARAMETER;
110 }
111
112 ExAcquireFastMutex(&pFastInt->Mutex);
113 return VINF_SUCCESS;
114}
115
116
117RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX MutexSem)
118{
119 /*
120 * Validate.
121 */
122 PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
123 if ( !pFastInt
124 || pFastInt->u32Magic != RTSEMFASTMUTEX_MAGIC)
125 {
126 AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt ? pFastInt->u32Magic : 0, pFastInt));
127 return VERR_INVALID_PARAMETER;
128 }
129
130 ExReleaseFastMutex(&pFastInt->Mutex);
131 return VINF_SUCCESS;
132}
133
Note: See TracBrowser for help on using the repository browser.

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