VirtualBox

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

Last change on this file since 8006 was 5999, checked in by vboxsync, 16 years ago

The Giant CDDL Dual-License Header Change.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use