VirtualBox

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

Last change on this file since 4693 was 4421, checked in by vboxsync, 17 years ago

Fixed bugs found during testing. Wakeup -> WakeUp.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.7 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
17#ifndef ___VBox_pdmthread_h
18#define ___VBox_pdmthread_h
19
20#include <VBox/cdefs.h>
21#include <VBox/types.h>
22#ifdef IN_RING3
23# include <iprt/thread.h>
24#endif
25
26__BEGIN_DECLS
27
28/** @group grp_pdm_thread Threads
29 * @ingroup grp_pdm
30 * @{
31 */
32
33/**
34 * The thread state
35 */
36typedef enum PDMTHREADSTATE
37{
38 /** The usual invalid 0 entry. */
39 PDMTHREADSTATE_INVALID = 0,
40 /** The thread is initializing.
41 * Prev state: none
42 * Next state: suspended, terminating (error) */
43 PDMTHREADSTATE_INITIALIZING,
44 /** The thread has been asked to suspend.
45 * Prev state: running
46 * Next state: suspended */
47 PDMTHREADSTATE_SUSPENDING,
48 /** The thread is supended.
49 * Prev state: suspending, initializing
50 * Next state: resuming, terminated. */
51 PDMTHREADSTATE_SUSPENDED,
52 /** The thread is active.
53 * Prev state: suspended
54 * Next state: running, terminating. */
55 PDMTHREADSTATE_RESUMING,
56 /** The thread is active.
57 * Prev state: resuming
58 * Next state: suspending, terminating. */
59 PDMTHREADSTATE_RUNNING,
60 /** The thread has been asked to terminate.
61 * Prev state: initializing, suspended, resuming, running
62 * Next state: terminated. */
63 PDMTHREADSTATE_TERMINATING,
64 /** The thread is terminating / has terminated.
65 * Prev state: terminating
66 * Next state: none */
67 PDMTHREADSTATE_TERMINATED,
68 /** The usual 32-bit hack. */
69 PDMTHREADSTATE_32BIT_HACK = 0x7fffffff
70} PDMTHREADSTATE;
71
72/** A pointer to a PDM thread. */
73typedef R3PTRTYPE(struct PDMTHREAD *) PPDMTHREAD;
74/** A pointer to a pointer to a PDM thread. */
75typedef PPDMTHREAD *PPPDMTHREAD;
76
77/**
78 * PDM thread, device variation.
79 *
80 * @returns VBox status code.
81 * @param pDevIns The device instance.
82 * @param pThread The PDM thread data.
83 */
84typedef int FNPDMTHREADDEV(PPDMDEVINS pDevIns, PPDMTHREAD pThread);
85/** Pointer to a FNPDMTHREADDEV(). */
86typedef FNPDMTHREADDEV *PFNPDMTHREADDEV;
87
88/**
89 * PDM thread, USB device variation.
90 *
91 * @returns VBox status code.
92 * @param pUsbIns The USB device instance.
93 * @param pThread The PDM thread data.
94 */
95typedef int FNPDMTHREADUSB(PPDMUSBINS pUsbIns, PPDMTHREAD pThread);
96/** Pointer to a FNPDMTHREADUSB(). */
97typedef FNPDMTHREADUSB *PFNPDMTHREADUSB;
98
99/**
100 * PDM thread, driver variation.
101 *
102 * @returns VBox status code.
103 * @param pDrvIns The driver instance.
104 * @param pThread The PDM thread data.
105 */
106typedef int FNPDMTHREADDRV(PPDMDRVINS pDrvIns, PPDMTHREAD pThread);
107/** Pointer to a FNPDMTHREADDRV(). */
108typedef FNPDMTHREADDRV *PFNPDMTHREADDRV;
109
110/**
111 * PDM thread, driver variation.
112 *
113 * @returns VBox status code.
114 * @param pVM The VM handle.
115 * @param pThread The PDM thread data.
116 */
117typedef int FNPDMTHREADINT(PVM pVM, PPDMTHREAD pThread);
118/** Pointer to a FNPDMTHREADINT(). */
119typedef FNPDMTHREADINT *PFNPDMTHREADINT;
120
121/**
122 * PDM thread, driver variation.
123 *
124 * @returns VBox status code.
125 * @param pThread The PDM thread data.
126 */
127typedef int FNPDMTHREADEXT(PPDMTHREAD pThread);
128/** Pointer to a FNPDMTHREADEXT(). */
129typedef FNPDMTHREADEXT *PFNPDMTHREADEXT;
130
131
132
133/**
134 * PDM thread wakeup call, device variation.
135 *
136 * @returns VBox status code.
137 * @param pDevIns The device instance.
138 * @param pThread The PDM thread data.
139 */
140typedef int FNPDMTHREADWAKEUPDEV(PPDMDEVINS pDevIns, PPDMTHREAD pThread);
141/** Pointer to a FNPDMTHREADDEV(). */
142typedef FNPDMTHREADWAKEUPDEV *PFNPDMTHREADWAKEUPDEV;
143
144/**
145 * PDM thread wakeup call, device variation.
146 *
147 * @returns VBox status code.
148 * @param pUsbIns The USB device instance.
149 * @param pThread The PDM thread data.
150 */
151typedef int FNPDMTHREADWAKEUPUSB(PPDMUSBINS pUsbIns, PPDMTHREAD pThread);
152/** Pointer to a FNPDMTHREADUSB(). */
153typedef FNPDMTHREADWAKEUPUSB *PFNPDMTHREADWAKEUPUSB;
154
155/**
156 * PDM thread wakeup call, driver variation.
157 *
158 * @returns VBox status code.
159 * @param pDrvIns The driver instance.
160 * @param pThread The PDM thread data.
161 */
162typedef int FNPDMTHREADWAKEUPDRV(PPDMDRVINS pDrvIns, PPDMTHREAD pThread);
163/** Pointer to a FNPDMTHREADDRV(). */
164typedef FNPDMTHREADWAKEUPDRV *PFNPDMTHREADWAKEUPDRV;
165
166/**
167 * PDM thread wakeup call, internal variation.
168 *
169 * @returns VBox status code.
170 * @param pVM The VM handle.
171 * @param pThread The PDM thread data.
172 */
173typedef int FNPDMTHREADWAKEUPINT(PVM pVM, PPDMTHREAD pThread);
174/** Pointer to a FNPDMTHREADWAKEUPINT(). */
175typedef FNPDMTHREADWAKEUPINT *PFNPDMTHREADWAKEUPINT;
176
177/**
178 * PDM thread wakeup call, external variation.
179 *
180 * @returns VBox status code.
181 * @param pThread The PDM thread data.
182 */
183typedef int FNPDMTHREADWAKEUPEXT(PPDMTHREAD pThread);
184/** Pointer to a FNPDMTHREADEXT(). */
185typedef FNPDMTHREADWAKEUPEXT *PFNPDMTHREADWAKEUPEXT;
186
187
188/**
189 * PDM Thread instance data.
190 */
191typedef struct PDMTHREAD
192{
193 /** PDMTHREAD_VERSION. */
194 uint32_t u32Version;
195 /** The thread state. */
196 PDMTHREADSTATE volatile enmState;
197 /** The thread handle. */
198 RTTHREAD Thread;
199 /** The user parameter. */
200 R3PTRTYPE(void *) pvUser;
201 /** Data specific to the kind of thread.
202 * This should really be in PDMTHREADINT, but is placed here because of the
203 * function pointer typedefs. So, don't touch these, please.
204 */
205 union
206 {
207 /** PDMTHREADTYPE_DEVICE data. */
208 struct
209 {
210 /** The device instance. */
211 PPDMDEVINSR3 pDevIns;
212 /** The thread function. */
213 R3PTRTYPE(PFNPDMTHREADDEV) pfnThread;
214 /** Thread. */
215 R3PTRTYPE(PFNPDMTHREADWAKEUPDEV) pfnWakeUp;
216 } Dev;
217
218 /** PDMTHREADTYPE_USB data. */
219 struct
220 {
221 /** The device instance. */
222 PPDMUSBINS pUsbIns;
223 /** The thread function. */
224 R3PTRTYPE(PFNPDMTHREADUSB) pfnThread;
225 /** Thread. */
226 R3PTRTYPE(PFNPDMTHREADWAKEUPUSB) pfnWakeUp;
227 } Usb;
228
229 /** PDMTHREADTYPE_DRIVER data. */
230 struct
231 {
232 /** The driver instance. */
233 R3PTRTYPE(PPDMDRVINS) pDrvIns;
234 /** The thread function. */
235 R3PTRTYPE(PFNPDMTHREADDRV) pfnThread;
236 /** Thread. */
237 R3PTRTYPE(PFNPDMTHREADWAKEUPDRV) pfnWakeUp;
238 } Drv;
239
240 /** PDMTHREADTYPE_INTERNAL data. */
241 struct
242 {
243 /** The thread function. */
244 R3PTRTYPE(PFNPDMTHREADINT) pfnThread;
245 /** Thread. */
246 R3PTRTYPE(PFNPDMTHREADWAKEUPINT) pfnWakeUp;
247 } Int;
248
249 /** PDMTHREADTYPE_EXTERNAL data. */
250 struct
251 {
252 /** The thread function. */
253 R3PTRTYPE(PFNPDMTHREADEXT) pfnThread;
254 /** Thread. */
255 R3PTRTYPE(PFNPDMTHREADWAKEUPEXT) pfnWakeUp;
256 } Ext;
257 } u;
258
259 /** Internal data. */
260 union
261 {
262#ifdef PDMTHREADINT_DECLARED
263 PDMTHREADINT s;
264#endif
265 uint8_t padding[64];
266 } Internal;
267} PDMTHREAD;
268
269/** PDMTHREAD::u32Version value. */
270#define PDMTHREAD_VERSION 0xef010000
271
272#ifdef IN_RING3
273/**
274 * Creates a PDM thread for internal use in the VM.
275 *
276 * @returns VBox status code.
277 * @param pVM The VM handle.
278 * @param ppThread Where to store the thread 'handle'.
279 * @param pvUser The user argument to the thread function.
280 * @param pfnThread The thread function.
281 * @param pfnWakeUp The wakup callback. This is called on the EMT thread when
282 * a state change is pending.
283 * @param cbStack See RTThreadCreate.
284 * @param enmType See RTThreadCreate.
285 * @param pszName See RTThreadCreate.
286 */
287PDMR3DECL(int) PDMR3ThreadCreate(PVM pVM, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADINT pfnThread,
288 PFNPDMTHREADWAKEUPINT pfnWakeUp, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
289
290/**
291 * Creates a PDM thread for VM use by some external party.
292 *
293 * @returns VBox status code.
294 * @param pVM The VM handle.
295 * @param ppThread Where to store the thread 'handle'.
296 * @param pvUser The user argument to the thread function.
297 * @param pfnThread The thread function.
298 * @param pfnWakeUp The wakup callback. This is called on the EMT thread when
299 * a state change is pending.
300 * @param cbStack See RTThreadCreate.
301 * @param enmType See RTThreadCreate.
302 * @param pszName See RTThreadCreate.
303 */
304PDMR3DECL(int) PDMR3ThreadCreateExternal(PVM pVM, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADEXT pfnThread,
305 PFNPDMTHREADWAKEUPEXT pfnWakeUp, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
306
307/**
308 * Destroys a PDM thread.
309 *
310 * This will wakeup the thread, tell it to terminate, and wait for it terminate.
311 *
312 * @returns VBox status code.
313 * This reflects the success off destroying the thread and not the exit code
314 * of the thread as this is stored in *pRcThread.
315 * @param pThread The thread to destroy.
316 * @param pRcThread Where to store the thread exit code. Optional.
317 * @thread The emulation thread (EMT).
318 */
319PDMR3DECL(int) PDMR3ThreadDestroy(PPDMTHREAD pThread, int *pRcThread);
320
321/**
322 * Called by the PDM thread in response to a wakeup call with
323 * suspending as the new state.
324 *
325 * The thread will block in side this call until the state is changed in
326 * response to a VM state change or to the device/driver/whatever calling the
327 * PDMR3ThreadResume API.
328 *
329 * @returns VBox status code.
330 * On failure, terminate the thread.
331 * @param pThread The PDM thread.
332 */
333PDMR3DECL(int) PDMR3ThreadIAmSuspending(PPDMTHREAD pThread);
334
335/**
336 * Called by the PDM thread in response to a resuming state.
337 *
338 * The purpose of this API is to tell the PDMR3ThreadResume caller that
339 * the the PDM thread has successfully resumed. It will also do the
340 * state transition from the resuming to the running state.
341 *
342 * @returns VBox status code.
343 * On failure, terminate the thread.
344 * @param pThread The PDM thread.
345 */
346PDMR3DECL(int) PDMR3ThreadIAmRunning(PPDMTHREAD pThread);
347
348/**
349 * Suspends the thread.
350 *
351 * This can be called at the power off / suspend notifications to suspend the
352 * PDM thread a bit early. The thread will be automatically suspend upon
353 * completion of the device/driver notification cycle.
354 *
355 * The caller is responsible for serializing the control operations on the
356 * thread. That basically means, always do these calls from the EMT.
357 *
358 * @returns VBox status code.
359 * @param pThread The PDM thread.
360 */
361PDMR3DECL(int) PDMR3ThreadSuspend(PPDMTHREAD pThread);
362
363/**
364 * Resumes the thread.
365 *
366 * This can be called the power on / resume notifications to resume the
367 * PDM thread a bit early. The thread will be automatically resumed upon
368 * return from these two notification callbacks (devices/drivers).
369 *
370 * The caller is responsible for serializing the control operations on the
371 * thread. That basically means, always do these calls from the EMT.
372 *
373 * @returns VBox status code.
374 * @param pThread The PDM thread.
375 */
376PDMR3DECL(int) PDMR3ThreadResume(PPDMTHREAD pThread);
377#endif /* IN_RING3 */
378
379/** @} */
380
381__END_DECLS
382
383#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