VirtualBox

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

Last change on this file since 5528 was 5222, checked in by vboxsync, 17 years ago

Split up r0drv/nt/semaphore-r0drv-nt.cpp.

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