VirtualBox

source: vbox/trunk/include/VBox/pdmcritsect.h@ 4878

Last change on this file since 4878 was 4403, checked in by vboxsync, 17 years ago

PDMCritSectIsInitialized.

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