1 | /** @file
|
---|
2 | * PDM - Pluggable Device Manager, Critical Sections.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef ___VBox_pdmcritsect_h
|
---|
27 | #define ___VBox_pdmcritsect_h
|
---|
28 |
|
---|
29 | #include <VBox/types.h>
|
---|
30 | #include <iprt/critsect.h>
|
---|
31 |
|
---|
32 | __BEGIN_DECLS
|
---|
33 |
|
---|
34 | /** @defgroup grp_pdm_critsect The PDM Critical Section
|
---|
35 | * @ingroup grp_pdm
|
---|
36 | * @{
|
---|
37 | */
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * A PDM critical section.
|
---|
41 | * Initialize using PDMDRVHLP::pfnCritSectInit().
|
---|
42 | */
|
---|
43 | typedef union PDMCRITSECT
|
---|
44 | {
|
---|
45 | /** Padding. */
|
---|
46 | uint8_t padding[HC_ARCH_BITS == 64 ? 0xb8 : 0x80];
|
---|
47 | #ifdef PDMCRITSECTINT_DECLARED
|
---|
48 | /** The internal structure (not normally visible). */
|
---|
49 | struct PDMCRITSECTINT s;
|
---|
50 | #endif
|
---|
51 | } PDMCRITSECT;
|
---|
52 | /** Pointer to a PDM critical section. */
|
---|
53 | typedef PDMCRITSECT *PPDMCRITSECT;
|
---|
54 | /** Pointer to a const PDM critical section. */
|
---|
55 | typedef const PDMCRITSECT *PCPDMCRITSECT;
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Initializes a PDM critical section for internal use.
|
---|
59 | *
|
---|
60 | * The PDM critical sections are derived from the IPRT critical sections, but
|
---|
61 | * works in GC as well.
|
---|
62 | *
|
---|
63 | * @returns VBox status code.
|
---|
64 | * @param pVM The VM handle.
|
---|
65 | * @param pDevIns Device instance.
|
---|
66 | * @param pCritSect Pointer to the critical section.
|
---|
67 | * @param pszName The name of the critical section (for statistics).
|
---|
68 | */
|
---|
69 | PDMR3DECL(int) PDMR3CritSectInit(PVM pVM, PPDMCRITSECT pCritSect, const char *pszName);
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Leaves a critical section entered with PDMCritSectEnter().
|
---|
73 | *
|
---|
74 | * @returns VINF_SUCCESS if entered successfully.
|
---|
75 | * @returns rcBusy when encountering a busy critical section in GC/R0.
|
---|
76 | * @returns VERR_SEM_DESTROYED if the critical section is dead.
|
---|
77 | *
|
---|
78 | * @param pCritSect The PDM critical section to enter.
|
---|
79 | * @param rcBusy The status code to return when we're in GC or R0
|
---|
80 | * and the section is busy.
|
---|
81 | */
|
---|
82 | PDMDECL(int) PDMCritSectEnter(PPDMCRITSECT pCritSect, int rcBusy);
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Leaves a critical section entered with PDMCritSectEnter().
|
---|
86 | *
|
---|
87 | * @param pCritSect The PDM critical section to leave.
|
---|
88 | */
|
---|
89 | PDMDECL(void) PDMCritSectLeave(PPDMCRITSECT pCritSect);
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * Checks the caller is the owner of the critical section.
|
---|
93 | *
|
---|
94 | * @returns true if owner.
|
---|
95 | * @returns false if not owner.
|
---|
96 | * @param pCritSect The critical section.
|
---|
97 | */
|
---|
98 | PDMDECL(bool) PDMCritSectIsOwner(PCPDMCRITSECT pCritSect);
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Checks if a critical section is initialized or not.
|
---|
102 | *
|
---|
103 | * @returns true if initialized.
|
---|
104 | * @returns false if not initialized.
|
---|
105 | * @param pCritSect The critical section.
|
---|
106 | */
|
---|
107 | PDMDECL(bool) PDMCritSectIsInitialized(PCPDMCRITSECT pCritSect);
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Try enter a critical section.
|
---|
111 | *
|
---|
112 | * @returns VINF_SUCCESS on success.
|
---|
113 | * @returns VERR_SEM_BUSY if the critsect was owned.
|
---|
114 | * @returns VERR_SEM_NESTED if nested enter on a no nesting section. (Asserted.)
|
---|
115 | * @returns VERR_SEM_DESTROYED if RTCritSectDelete was called while waiting.
|
---|
116 | * @param pCritSect The critical section.
|
---|
117 | */
|
---|
118 | PDMR3DECL(int) PDMR3CritSectTryEnter(PPDMCRITSECT pCritSect);
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Schedule a event semaphore for signalling upon critsect exit.
|
---|
122 | *
|
---|
123 | * @returns VINF_SUCCESS on success.
|
---|
124 | * @returns VERR_TOO_MANY_SEMAPHORES if an event was already scheduled.
|
---|
125 | * @returns VERR_NOT_OWNER if we're not the critsect owner.
|
---|
126 | * @returns VERR_SEM_DESTROYED if RTCritSectDelete was called while waiting.
|
---|
127 | * @param pCritSect The critical section.
|
---|
128 | * @param EventToSignal The semapore that should be signalled.
|
---|
129 | */
|
---|
130 | PDMR3DECL(int) PDMR3CritSectScheduleExitEvent(PPDMCRITSECT pCritSect, RTSEMEVENT EventToSignal);
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Deletes the critical section.
|
---|
134 | *
|
---|
135 | * @returns VBox status code.
|
---|
136 | * @param pCritSect The PDM critical section to destroy.
|
---|
137 | */
|
---|
138 | PDMR3DECL(int) PDMR3CritSectDelete(PPDMCRITSECT pCritSect);
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Deletes all remaining critical sections.
|
---|
142 | *
|
---|
143 | * This is called at the end of the termination process.
|
---|
144 | *
|
---|
145 | * @returns VBox status.
|
---|
146 | * First error code, rest is lost.
|
---|
147 | * @param pVM The VM handle.
|
---|
148 | * @remark Don't confuse this with PDMR3CritSectDelete.
|
---|
149 | */
|
---|
150 | PDMDECL(int) PDMR3CritSectTerm(PVM pVM);
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Process the critical sections queued for ring-3 'leave'.
|
---|
154 | *
|
---|
155 | * @param pVM The VM handle.
|
---|
156 | */
|
---|
157 | PDMR3DECL(void) PDMR3CritSectFF(PVM pVM);
|
---|
158 |
|
---|
159 | /** @} */
|
---|
160 |
|
---|
161 | __END_DECLS
|
---|
162 |
|
---|
163 | #endif
|
---|
164 |
|
---|