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