VirtualBox

source: vbox/trunk/include/VBox/vmm/pdmthread.h@ 73768

Last change on this file since 73768 was 69475, checked in by vboxsync, 7 years ago

*: scm updates - header files should have 'svn:keywords=Id Revision' too (doesn't mean they have to use them).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 9.2 KB
Line 
1/** @file
2 * PDM - Pluggable Device Manager, Threads.
3 */
4
5/*
6 * Copyright (C) 2006-2017 Oracle Corporation
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_vmm_pdmthread_h
27#define ___VBox_vmm_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
35RT_C_DECLS_BEGIN
36
37/** @defgroup grp_pdm_thread The PDM Threads API
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 DECLCALLBACK(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 DECLCALLBACK(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 DECLCALLBACK(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 cross context VM structure.
124 * @param pThread The PDM thread data.
125 */
126typedef DECLCALLBACK(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 DECLCALLBACK(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 DECLCALLBACK(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 DECLCALLBACK(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 cross context VM structure.
180 * @param pThread The PDM thread data.
181 */
182typedef DECLCALLBACK(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 PDM_VERSION_MAKE(0xefff, 1, 0)
280
281#ifdef IN_RING3
282VMMR3DECL(int) PDMR3ThreadCreate(PVM pVM, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADINT pfnThread,
283 PFNPDMTHREADWAKEUPINT pfnWakeUp, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
284VMMR3DECL(int) PDMR3ThreadCreateExternal(PVM pVM, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADEXT pfnThread,
285 PFNPDMTHREADWAKEUPEXT pfnWakeUp, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
286VMMR3DECL(int) PDMR3ThreadDestroy(PPDMTHREAD pThread, int *pRcThread);
287VMMR3DECL(int) PDMR3ThreadIAmSuspending(PPDMTHREAD pThread);
288VMMR3DECL(int) PDMR3ThreadIAmRunning(PPDMTHREAD pThread);
289VMMR3DECL(int) PDMR3ThreadSleep(PPDMTHREAD pThread, RTMSINTERVAL cMillies);
290VMMR3DECL(int) PDMR3ThreadSuspend(PPDMTHREAD pThread);
291VMMR3DECL(int) PDMR3ThreadResume(PPDMTHREAD pThread);
292#endif /* IN_RING3 */
293
294/** @} */
295
296RT_C_DECLS_END
297
298#endif
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use