VirtualBox

source: vbox/trunk/include/VBox/pdmthread.h@ 4041

Last change on this file since 4041 was 4012, checked in by vboxsync, 17 years ago

Hooked up the PDMThread stuff.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.9 KB
Line 
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 */
40typedef 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. */
77typedef R3PTRTYPE(struct PDMTHREAD *) PPDMTHREAD;
78/** A pointer to a pointer to a PDM thread. */
79typedef 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 */
88typedef int FNPDMTHREADDEV(PPDMDEVINS pDevIns, PPDMTHREAD pThread);
89/** Pointer to a FNPDMTHREADDEV(). */
90typedef 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 */
99typedef int FNPDMTHREADUSB(PPDMUSBINS pUsbIns, PPDMTHREAD pThread);
100/** Pointer to a FNPDMTHREADUSB(). */
101typedef 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 */
110typedef int FNPDMTHREADDRV(PPDMDRVINS pDrvIns, PPDMTHREAD pThread);
111/** Pointer to a FNPDMTHREADDRV(). */
112typedef 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 */
121typedef int FNPDMTHREADINT(PVM pVM, PPDMTHREAD pThread);
122/** Pointer to a FNPDMTHREADINT(). */
123typedef FNPDMTHREADINT *PFNPDMTHREADINT;
124
125/**
126 * PDM thread, driver variation.
127 *
128 * @returns VBox status code.
129 * @param pThread The PDM thread data.
130 */
131typedef int FNPDMTHREADEXT(PPDMTHREAD pThread);
132/** Pointer to a FNPDMTHREADEXT(). */
133typedef 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 */
144typedef int FNPDMTHREADWAKEUPDEV(PPDMDEVINS pDevIns, PPDMTHREAD pThread);
145/** Pointer to a FNPDMTHREADDEV(). */
146typedef 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 */
155typedef int FNPDMTHREADWAKEUPUSB(PPDMUSBINS pUsbIns, PPDMTHREAD pThread);
156/** Pointer to a FNPDMTHREADUSB(). */
157typedef 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 */
166typedef int FNPDMTHREADWAKEUPDRV(PPDMDRVINS pDrvIns, PPDMTHREAD pThread);
167/** Pointer to a FNPDMTHREADDRV(). */
168typedef 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 */
177typedef int FNPDMTHREADWAKEUPINT(PVM pVM, PPDMTHREAD pThread);
178/** Pointer to a FNPDMTHREADWAKEUPINT(). */
179typedef 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 */
187typedef int FNPDMTHREADWAKEUPEXT(PPDMTHREAD pThread);
188/** Pointer to a FNPDMTHREADEXT(). */
189typedef FNPDMTHREADWAKEUPEXT *PFNPDMTHREADWAKEUPEXT;
190
191
192/**
193 * PDM Thread instance data.
194 */
195typedef 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#ifdef IN_RING3
277/**
278 * Creates a PDM thread for internal use in the VM.
279 *
280 * @returns VBox status code.
281 * @param pVM The VM handle.
282 * @param ppThread Where to store the thread 'handle'.
283 * @param pvUser The user argument to the thread function.
284 * @param pfnThread The thread function.
285 * @param pfnWakeup The wakup callback. This is called on the EMT thread when
286 * a state change is pending.
287 * @param cbStack See RTThreadCreate.
288 * @param enmType See RTThreadCreate.
289 * @param pszName See RTThreadCreate.
290 */
291PDMR3DECL(int) PDMR3ThreadCreate(PVM pVM, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADINT pfnThread,
292 PFNPDMTHREADWAKEUPINT pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
293
294/**
295 * Creates a PDM thread for VM use by some external party.
296 *
297 * @returns VBox status code.
298 * @param pVM The VM handle.
299 * @param ppThread Where to store the thread 'handle'.
300 * @param pvUser The user argument to the thread function.
301 * @param pfnThread The thread function.
302 * @param pfnWakeup The wakup callback. This is called on the EMT thread when
303 * a state change is pending.
304 * @param cbStack See RTThreadCreate.
305 * @param enmType See RTThreadCreate.
306 * @param pszName See RTThreadCreate.
307 */
308PDMR3DECL(int) PDMR3ThreadCreateExternal(PVM pVM, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADEXT pfnThread,
309 PFNPDMTHREADWAKEUPEXT pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
310
311/**
312 * Destroys a PDM thread.
313 *
314 * This will wakeup the thread, tell it to terminate, and wait for it terminate.
315 *
316 * @returns VBox status code.
317 * This reflects the success off destroying the thread and not the exit code
318 * of the thread as this is stored in *pRcThread.
319 * @param pThread The thread to destroy.
320 * @param pRcThread Where to store the thread exit code. Optional.
321 * @thread The emulation thread (EMT).
322 */
323PDMR3DECL(int) PDMR3ThreadDestroy(PPDMTHREAD pThread, int *pRcThread);
324
325/**
326 * Called by the PDM thread in response to a wakeup call with
327 * suspending as the new state.
328 *
329 * The thread will block in side this call until the state is changed in
330 * response to a VM state change or to the device/driver/whatever calling the
331 * PDMR3ThreadResume API.
332 *
333 * @returns VBox status code.
334 * On failure, terminate the thread.
335 * @param pThread The PDM thread.
336 */
337PDMR3DECL(int) PDMR3ThreadIAmSuspending(PPDMTHREAD pThread);
338
339/**
340 * Called by the PDM thread in response to a resuming state.
341 *
342 * The purpose of this API is to tell the PDMR3ThreadResume caller that
343 * the the PDM thread has successfully resumed. It will also do the
344 * state transition from the resuming to the running state.
345 *
346 * @returns VBox status code.
347 * On failure, terminate the thread.
348 * @param pThread The PDM thread.
349 */
350PDMR3DECL(int) PDMR3ThreadIAmRunning(PPDMTHREAD pThread);
351
352/**
353 * Suspends the thread.
354 *
355 * This can be called at the power off / suspend notifications to suspend the
356 * PDM thread a bit early. The thread will be automatically suspend upon
357 * completion of the device/driver notification cycle.
358 *
359 * The caller is responsible for serializing the control operations on the
360 * thread. That basically means, always do these calls from the EMT.
361 *
362 * @returns VBox status code.
363 * @param pThread The PDM thread.
364 */
365PDMR3DECL(int) PDMR3ThreadSuspend(PPDMTHREAD pThread);
366
367/**
368 * Resumes the thread.
369 *
370 * This can be called the power on / resume notifications to resume the
371 * PDM thread a bit early. The thread will be automatically resumed upon
372 * return from these two notification callbacks (devices/drivers).
373 *
374 * The caller is responsible for serializing the control operations on the
375 * thread. That basically means, always do these calls from the EMT.
376 *
377 * @returns VBox status code.
378 * @param pThread The PDM thread.
379 */
380PDMR3DECL(int) PDMR3ThreadResume(PPDMTHREAD pThread);
381#endif /* IN_RING3 */
382
383/** @} */
384
385__END_DECLS
386
387#endif
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