VirtualBox

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

Last change on this file since 89363 was 85121, checked in by vboxsync, 4 years ago

iprt/cdefs.h: Refactored the typedef use of DECLCALLBACK as well as DECLCALLBACKMEMBER to wrap the whole expression, similar to the DECLR?CALLBACKMEMBER macros. This allows adding a throw() at the end when compiling with the VC++ compiler to indicate that the callbacks won't throw anything, so we can stop supressing the C5039 warning about passing functions that can potential throw C++ exceptions to extern C code that can't necessarily cope with such (unwind,++). Introduced a few _EX variations that allows specifying different/no calling convention too, as that's handy when dynamically resolving host APIs. Fixed numerous places missing DECLCALLBACK and such. Left two angry @todos regarding use of CreateThread. bugref:9794

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