1 | /** @file
|
---|
2 | * PDM - Pluggable Device Manager, Threads.
|
---|
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_pdmthread_h
|
---|
22 | #define ___VBox_pdmthread_h
|
---|
23 |
|
---|
24 | #include <VBox/cdefs.h>
|
---|
25 | #include <VBox/types.h>
|
---|
26 | #ifdef IN_RING3
|
---|
27 | # include <iprt/thread.h>
|
---|
28 | #endif
|
---|
29 |
|
---|
30 | __BEGIN_DECLS
|
---|
31 |
|
---|
32 | /** @group grp_pdm_thread Threads
|
---|
33 | * @ingroup grp_pdm
|
---|
34 | * @{
|
---|
35 | */
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * The thread state
|
---|
39 | */
|
---|
40 | typedef enum PDMTHREADSTATE
|
---|
41 | {
|
---|
42 | /** The usual invalid 0 entry. */
|
---|
43 | PDMTHREADSTATE_INVALID = 0,
|
---|
44 | /** The thread is initializing.
|
---|
45 | * Prev state: none
|
---|
46 | * Next state: suspended, terminating (error) */
|
---|
47 | PDMTHREADSTATE_INITIALIZING,
|
---|
48 | /** The thread has been asked to suspend.
|
---|
49 | * Prev state: running
|
---|
50 | * Next state: suspended */
|
---|
51 | PDMTHREADSTATE_SUSPENDING,
|
---|
52 | /** The thread is supended.
|
---|
53 | * Prev state: suspending, initializing
|
---|
54 | * Next state: resuming, terminated. */
|
---|
55 | PDMTHREADSTATE_SUSPENDED,
|
---|
56 | /** The thread is active.
|
---|
57 | * Prev state: suspended
|
---|
58 | * Next state: running, terminating. */
|
---|
59 | PDMTHREADSTATE_RESUMING,
|
---|
60 | /** The thread is active.
|
---|
61 | * Prev state: resuming
|
---|
62 | * Next state: suspending, terminating. */
|
---|
63 | PDMTHREADSTATE_RUNNING,
|
---|
64 | /** The thread has been asked to terminate.
|
---|
65 | * Prev state: initializing, suspended, resuming, running
|
---|
66 | * Next state: terminated. */
|
---|
67 | PDMTHREADSTATE_TERMINATING,
|
---|
68 | /** The thread is terminating / has terminated.
|
---|
69 | * Prev state: terminating
|
---|
70 | * Next state: none */
|
---|
71 | PDMTHREADSTATE_TERMINATED,
|
---|
72 | /** The usual 32-bit hack. */
|
---|
73 | PDMTHREADSTATE_32BIT_HACK = 0x7fffffff
|
---|
74 | } PDMTHREADSTATE;
|
---|
75 |
|
---|
76 | /** A pointer to a PDM thread. */
|
---|
77 | typedef R3PTRTYPE(struct PDMTHREAD *) PPDMTHREAD;
|
---|
78 | /** A pointer to a pointer to a PDM thread. */
|
---|
79 | typedef PPDMTHREAD *PPPDMTHREAD;
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * PDM thread, device variation.
|
---|
83 | *
|
---|
84 | * @returns VBox status code.
|
---|
85 | * @param pDevIns The device instance.
|
---|
86 | * @param pThread The PDM thread data.
|
---|
87 | */
|
---|
88 | typedef int FNPDMTHREADDEV(PPDMDEVINS pDevIns, PPDMTHREAD pThread);
|
---|
89 | /** Pointer to a FNPDMTHREADDEV(). */
|
---|
90 | typedef FNPDMTHREADDEV *PFNPDMTHREADDEV;
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * PDM thread, USB device variation.
|
---|
94 | *
|
---|
95 | * @returns VBox status code.
|
---|
96 | * @param pUsbIns The USB device instance.
|
---|
97 | * @param pThread The PDM thread data.
|
---|
98 | */
|
---|
99 | typedef int FNPDMTHREADUSB(PPDMUSBINS pUsbIns, PPDMTHREAD pThread);
|
---|
100 | /** Pointer to a FNPDMTHREADUSB(). */
|
---|
101 | typedef FNPDMTHREADUSB *PFNPDMTHREADUSB;
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * PDM thread, driver variation.
|
---|
105 | *
|
---|
106 | * @returns VBox status code.
|
---|
107 | * @param pDrvIns The driver instance.
|
---|
108 | * @param pThread The PDM thread data.
|
---|
109 | */
|
---|
110 | typedef int FNPDMTHREADDRV(PPDMDRVINS pDrvIns, PPDMTHREAD pThread);
|
---|
111 | /** Pointer to a FNPDMTHREADDRV(). */
|
---|
112 | typedef FNPDMTHREADDRV *PFNPDMTHREADDRV;
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * PDM thread, driver variation.
|
---|
116 | *
|
---|
117 | * @returns VBox status code.
|
---|
118 | * @param pVM The VM handle.
|
---|
119 | * @param pThread The PDM thread data.
|
---|
120 | */
|
---|
121 | typedef int FNPDMTHREADINT(PVM pVM, PPDMTHREAD pThread);
|
---|
122 | /** Pointer to a FNPDMTHREADINT(). */
|
---|
123 | typedef FNPDMTHREADINT *PFNPDMTHREADINT;
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * PDM thread, driver variation.
|
---|
127 | *
|
---|
128 | * @returns VBox status code.
|
---|
129 | * @param pThread The PDM thread data.
|
---|
130 | */
|
---|
131 | typedef int FNPDMTHREADEXT(PPDMTHREAD pThread);
|
---|
132 | /** Pointer to a FNPDMTHREADEXT(). */
|
---|
133 | typedef FNPDMTHREADEXT *PFNPDMTHREADEXT;
|
---|
134 |
|
---|
135 |
|
---|
136 |
|
---|
137 | /**
|
---|
138 | * PDM thread wakeup call, device variation.
|
---|
139 | *
|
---|
140 | * @returns VBox status code.
|
---|
141 | * @param pDevIns The device instance.
|
---|
142 | * @param pThread The PDM thread data.
|
---|
143 | */
|
---|
144 | typedef int FNPDMTHREADWAKEUPDEV(PPDMDEVINS pDevIns, PPDMTHREAD pThread);
|
---|
145 | /** Pointer to a FNPDMTHREADDEV(). */
|
---|
146 | typedef FNPDMTHREADWAKEUPDEV *PFNPDMTHREADWAKEUPDEV;
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * PDM thread wakeup call, device variation.
|
---|
150 | *
|
---|
151 | * @returns VBox status code.
|
---|
152 | * @param pUsbIns The USB device instance.
|
---|
153 | * @param pThread The PDM thread data.
|
---|
154 | */
|
---|
155 | typedef int FNPDMTHREADWAKEUPUSB(PPDMUSBINS pUsbIns, PPDMTHREAD pThread);
|
---|
156 | /** Pointer to a FNPDMTHREADUSB(). */
|
---|
157 | typedef FNPDMTHREADWAKEUPUSB *PFNPDMTHREADWAKEUPUSB;
|
---|
158 |
|
---|
159 | /**
|
---|
160 | * PDM thread wakeup call, driver variation.
|
---|
161 | *
|
---|
162 | * @returns VBox status code.
|
---|
163 | * @param pDrvIns The driver instance.
|
---|
164 | * @param pThread The PDM thread data.
|
---|
165 | */
|
---|
166 | typedef int FNPDMTHREADWAKEUPDRV(PPDMDRVINS pDrvIns, PPDMTHREAD pThread);
|
---|
167 | /** Pointer to a FNPDMTHREADDRV(). */
|
---|
168 | typedef FNPDMTHREADWAKEUPDRV *PFNPDMTHREADWAKEUPDRV;
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * PDM thread wakeup call, internal variation.
|
---|
172 | *
|
---|
173 | * @returns VBox status code.
|
---|
174 | * @param pVM The VM handle.
|
---|
175 | * @param pThread The PDM thread data.
|
---|
176 | */
|
---|
177 | typedef int FNPDMTHREADWAKEUPINT(PVM pVM, PPDMTHREAD pThread);
|
---|
178 | /** Pointer to a FNPDMTHREADWAKEUPINT(). */
|
---|
179 | typedef FNPDMTHREADWAKEUPINT *PFNPDMTHREADWAKEUPINT;
|
---|
180 |
|
---|
181 | /**
|
---|
182 | * PDM thread wakeup call, external variation.
|
---|
183 | *
|
---|
184 | * @returns VBox status code.
|
---|
185 | * @param pThread The PDM thread data.
|
---|
186 | */
|
---|
187 | typedef int FNPDMTHREADWAKEUPEXT(PPDMTHREAD pThread);
|
---|
188 | /** Pointer to a FNPDMTHREADEXT(). */
|
---|
189 | typedef FNPDMTHREADWAKEUPEXT *PFNPDMTHREADWAKEUPEXT;
|
---|
190 |
|
---|
191 |
|
---|
192 | /**
|
---|
193 | * PDM Thread instance data.
|
---|
194 | */
|
---|
195 | typedef struct PDMTHREAD
|
---|
196 | {
|
---|
197 | /** PDMTHREAD_VERSION. */
|
---|
198 | uint32_t u32Version;
|
---|
199 | /** The thread state. */
|
---|
200 | PDMTHREADSTATE volatile enmState;
|
---|
201 | /** The thread handle. */
|
---|
202 | RTTHREAD Thread;
|
---|
203 | /** The user parameter. */
|
---|
204 | R3PTRTYPE(void *) pvUser;
|
---|
205 | /** Data specific to the kind of thread.
|
---|
206 | * This should really be in PDMTHREADINT, but is placed here because of the
|
---|
207 | * function pointer typedefs. So, don't touch these, please.
|
---|
208 | */
|
---|
209 | union
|
---|
210 | {
|
---|
211 | /** PDMTHREADTYPE_DEVICE data. */
|
---|
212 | struct
|
---|
213 | {
|
---|
214 | /** The device instance. */
|
---|
215 | PPDMDEVINSR3 pDevIns;
|
---|
216 | /** The thread function. */
|
---|
217 | R3PTRTYPE(PFNPDMTHREADDEV) pfnThread;
|
---|
218 | /** Thread. */
|
---|
219 | R3PTRTYPE(PFNPDMTHREADWAKEUPDEV) pfnWakeup;
|
---|
220 | } Dev;
|
---|
221 |
|
---|
222 | /** PDMTHREADTYPE_USB data. */
|
---|
223 | struct
|
---|
224 | {
|
---|
225 | /** The device instance. */
|
---|
226 | PPDMUSBINS pUsbIns;
|
---|
227 | /** The thread function. */
|
---|
228 | R3PTRTYPE(PFNPDMTHREADUSB) pfnThread;
|
---|
229 | /** Thread. */
|
---|
230 | R3PTRTYPE(PFNPDMTHREADWAKEUPUSB) pfnWakeup;
|
---|
231 | } Usb;
|
---|
232 |
|
---|
233 | /** PDMTHREADTYPE_DRIVER data. */
|
---|
234 | struct
|
---|
235 | {
|
---|
236 | /** The driver instance. */
|
---|
237 | R3PTRTYPE(PPDMDRVINS) pDrvIns;
|
---|
238 | /** The thread function. */
|
---|
239 | R3PTRTYPE(PFNPDMTHREADDRV) pfnThread;
|
---|
240 | /** Thread. */
|
---|
241 | R3PTRTYPE(PFNPDMTHREADWAKEUPDRV) pfnWakeup;
|
---|
242 | } Drv;
|
---|
243 |
|
---|
244 | /** PDMTHREADTYPE_INTERNAL data. */
|
---|
245 | struct
|
---|
246 | {
|
---|
247 | /** The thread function. */
|
---|
248 | R3PTRTYPE(PFNPDMTHREADINT) pfnThread;
|
---|
249 | /** Thread. */
|
---|
250 | R3PTRTYPE(PFNPDMTHREADWAKEUPINT) pfnWakeup;
|
---|
251 | } Int;
|
---|
252 |
|
---|
253 | /** PDMTHREADTYPE_EXTERNAL data. */
|
---|
254 | struct
|
---|
255 | {
|
---|
256 | /** The thread function. */
|
---|
257 | R3PTRTYPE(PFNPDMTHREADEXT) pfnThread;
|
---|
258 | /** Thread. */
|
---|
259 | R3PTRTYPE(PFNPDMTHREADWAKEUPEXT) pfnWakeup;
|
---|
260 | } Ext;
|
---|
261 | } u;
|
---|
262 |
|
---|
263 | /** Internal data. */
|
---|
264 | union
|
---|
265 | {
|
---|
266 | #ifdef PDMTHREADINT_DECLARED
|
---|
267 | PDMTHREADINT s;
|
---|
268 | #endif
|
---|
269 | uint8_t padding[64];
|
---|
270 | } Internal;
|
---|
271 | } PDMTHREAD;
|
---|
272 |
|
---|
273 | /** PDMTHREAD::u32Version value. */
|
---|
274 | #define PDMTHREAD_VERSION 0xef010000
|
---|
275 |
|
---|
276 |
|
---|
277 | /** @} */
|
---|
278 |
|
---|
279 | __END_DECLS
|
---|
280 |
|
---|
281 | #endif
|
---|