Changeset 7821 in vbox
- Timestamp:
- Apr 9, 2008 8:41:27 AM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 29404
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/pdmasynccompletion.h
r6221 r7821 28 28 29 29 #include <VBox/types.h> 30 #include <VBox/err.h> 31 #include <iprt/assert.h> 30 32 31 33 __BEGIN_DECLS … … 42 44 43 45 /** Pointer to a PDM async completion task handle. */ 44 typedef struct PDMASYNCCOMPLETION *PPDMASYNCCOMPLETION;46 typedef struct PDMASYNCCOMPLETIONTASK *PPDMASYNCCOMPLETIONTASK; 45 47 /** Pointer to a PDM async completion task handle pointer. */ 46 typedef PPDMASYNCCOMPLETION *PPPDMASYNCCOMPLETION;48 typedef PPDMASYNCCOMPLETIONTASK *PPPDMASYNCCOMPLETIONTASK; 47 49 48 50 … … 58 60 * @param pvUser User argument. 59 61 */ 60 typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEDEV(PPDMDEVINS pDevIns, PPDMASYNCCOMPLETION pTask, void *pvCtx, void *pvUser);62 typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEDEV(PPDMDEVINS pDevIns, PPDMASYNCCOMPLETIONTASK pTask, void *pvCtx, void *pvUser); 61 63 /** Pointer to a FNPDMASYNCCOMPLETEDEV(). */ 62 64 typedef FNPDMASYNCCOMPLETEDEV *PFNPDMASYNCCOMPLETEDEV; … … 74 76 * @param pvUser User argument. 75 77 */ 76 typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEDRV(PPDMDRVINS pDrvIns, PPDMASYNCCOMPLETION pTask, void *pvCtx, void *pvUser);78 typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEDRV(PPDMDRVINS pDrvIns, PPDMASYNCCOMPLETIONTASK pTask, void *pvCtx, void *pvUser); 77 79 /** Pointer to a FNPDMASYNCCOMPLETEDRV(). */ 78 80 typedef FNPDMASYNCCOMPLETEDRV *PFNPDMASYNCCOMPLETEDRV; … … 90 92 * @param pvUser User argument. 91 93 */ 92 typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEUSB(PPDMUSBINS pUsbIns, PPDMASYNCCOMPLETION pTask, void *pvCtx, void *pvUser);94 typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEUSB(PPDMUSBINS pUsbIns, PPDMASYNCCOMPLETIONTASK pTask, void *pvCtx, void *pvUser); 93 95 /** Pointer to a FNPDMASYNCCOMPLETEUSB(). */ 94 96 typedef FNPDMASYNCCOMPLETEUSB *PFNPDMASYNCCOMPLETEUSB; … … 107 109 * @param pvUser2 User argument for the template. 108 110 */ 109 typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEINT(PVM pVM, PPDMASYNCCOMPLETION pTask, void *pvCtx, void *pvUser, void *pvUser2);111 typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEINT(PVM pVM, PPDMASYNCCOMPLETIONTASK pTask, void *pvCtx, void *pvUser, void *pvUser2); 110 112 /** Pointer to a FNPDMASYNCCOMPLETEINT(). */ 111 113 typedef FNPDMASYNCCOMPLETEINT *PFNPDMASYNCCOMPLETEINT; … … 215 217 PDMR3DECL(int) PDMR3AsyncCompletionTemplateDestroyUsb(PVM pVM, PPDMUSBINS pUsbIns); 216 218 219 /** 220 * Async completion task type 221 */ 222 typedef enum PDMASYNCCOMPLETIONTASKTYPE 223 { 224 /** Socket. */ 225 PDMASYNCCOMPLETIONTASKTYPE_SOCKET = 0, 226 /** Host OS specific. */ 227 PDMASYNCCOMPLETIONTASKTYPE_HOST, 228 /** Number of supported backends. This has to be last entry! */ 229 PDMASYNCCOMPLETIONTASKTYPE_SUPPORTED 230 } PDMASYNCCOMPLETIONTASKTYPE; 231 232 /** 233 * Get the backend name of a task type. 234 * 235 * @returns Name of the backend. 236 * @param enmTaskType The task type to get the backend name from. 237 */ 238 PDMR3DECL(const char *) PDMR3AsyncCompletionGetBackendName(PDMASYNCCOMPLETIONTASKTYPE enmTaskType); 239 240 /** 241 * Creates a completion task. 242 * 243 * @returns VBox status code. 244 * @param ppTask Where to store the task handle on success. 245 * @param pTemplate The async completion template. 246 * @param enmType The type of the task. 247 * @param pvCtx The task specific context. 248 * @param pvUser The user argument for the callback. 249 */ 250 PDMR3DECL(int) PDMR3AsyncCompletionTaskCreate(PPPDMASYNCCOMPLETIONTASK ppTask, PPDMASYNCCOMPLETIONTEMPLATE pTemplate, PDMASYNCCOMPLETIONTASKTYPE enmType, void *pvCtx, void *pvUser); 251 252 /** 253 * Associate a task with a type specific context. 254 * 255 * @returns VBox status code. 256 * @param pTask The task to associate the context with. 257 * @param pvCtx Pointer to the context. 258 */ 259 PDMR3DECL(int) PDMR3AsyncCompletionTaskAssociate(PPDMASYNCCOMPLETIONTASK pTask, void *pvCtx); 260 261 /** 262 * Start processing the task handle. 263 * The task must have a type specific context. 264 * 265 * @returns VBox status code. 266 * @param pTask Pointer to the task which should be submited. 267 */ 268 PDMR3DECL(int) PDMR3AsyncCompletionTaskSubmit(PPDMASYNCCOMPLETIONTASK pTask); 269 270 /** 271 * Sets the user argument of a completion task. 272 * 273 * @returns VBox status code. 274 * @param pTask The async completion task. 275 * @param pvUser The user argument for the callback. 276 */ 277 PDMR3DECL(int) PDMR3AsyncCompletionTaskSetUserArg(PPDMASYNCCOMPLETIONTASK pTask, void *pvUser); 278 279 /** 280 * Suspends a async completion task. 281 * 282 * @returns VBox status codes: 283 * @retval VINF_SUCCESS on success. 284 * @retval VERR_PDM_ASYNC_COMPLETION_ALREADY_SUSPENDED if already suspended. 285 * @retval VERR_INVALID_HANDLE if pTask is invalid (asserts). 286 * @param pTask The async completion task. 287 */ 288 PDMR3DECL(int) PDMR3AsyncCompletionTaskSuspend(PPDMASYNCCOMPLETIONTASK pTask); 289 290 /** 291 * Suspends a async completion task. 292 * 293 * @returns VBox status codes: 294 * @retval VINF_SUCCESS on success. 295 * @retval VERR_PDM_ASYNC_COMPLETION_NOT_SUSPENDED if not suspended. 296 * @retval VERR_INVALID_HANDLE if pTask is invalid (asserts). 297 * @param pTask The async completion task. 298 */ 299 PDMR3DECL(int) PDMR3AsyncCompletionTaskResume(PPDMASYNCCOMPLETIONTASK pTask); 300 301 /** 302 * Cancels a async completion task. 303 * The task doesn't have to be suspended. 304 * 305 * @returns VBox status code 306 * @param pTask The Task to cancel. 307 */ 308 PDMR3DECL(int) PDMR3AsyncCompletionTaskCancel(PPDMASYNCCOMPLETIONTASK pTask); 309 310 /** 311 * Destroys a async completion task. 312 * 313 * The task doesn't have to be suspended or anything. 314 * 315 * @returns VBox status codes: 316 * @retval VINF_SUCCESS on success. 317 * @retval VERR_INVALID_HANDLE if pTask is invalid but not NIL (asserts). 318 * @param pTask The async completion task. 319 */ 320 PDMR3DECL(int) PDMR3AsyncCompletionTaskDestroy(PPDMASYNCCOMPLETIONTASK pTask); 321 322 /* 323 * Host specific wrapper functions for the above API 324 */ 325 #if defined(RT_OS_LINUX) 326 327 struct iocb; 328 329 /** 330 * Creates a completion task for an IO operation on Linux. 331 * 332 * The pvCtx callback argument will be pIoCB. 333 * 334 * @returns VBox status code. 335 * @param ppTask Where to store the task handle on success. 336 * @param pTemplate The async completion template. 337 * @param pIoCB The asynchronous I/O control block to wait for. 338 * @param pvUser The user argument for the callback. 339 */ 340 DECLINLINE(int) PDMR3AsyncCompletionCreateLnxIO(PPPDMASYNCCOMPLETIONTASK ppTask, PPDMASYNCCOMPLETIONTEMPLATE pTemplate, const struct iocb *pIoCB, void *pvUser) 341 { 342 int rc = VINF_SUCCESS; 343 PPDMASYNCCOMPLETIONTASK pTask; 344 345 rc = PDMR3AsyncCompletionTaskCreate(&pTask, pTemplate, PDMASYNCCOMPLETIONTASKTYPE_HOST, (void *)pIoCB, pvUser); 346 if (VBOX_FAILURE(rc)) 347 { 348 AssertMsgFailed(("Creating Linux task failed\n")); 349 return rc; 350 } 351 352 rc = PDMR3AsyncCompletionTaskSubmit(pTask); 353 if (VBOX_FAILURE(rc)) 354 { 355 AssertMsgFailed(("Submitting Linux task failed\n")); 356 PDMR3AsyncCompletionTaskDestroy(pTask); 357 return rc; 358 } 359 360 *ppTask = pTask; 361 362 return rc; 363 } 364 #endif /* RT_OS_LINUX */ 365 366 #if defined(RT_OS_SOLARIS) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) 367 368 struct aiocb; 369 370 /** 371 * Creates a completion task for an AIO operation on Unix like systems like Solaris, Darwin or FreeBSD. 372 * This method must be used too on Linux if the real asynchronous solution is not available. 373 * 374 * The pvCtx callback argument will be pAioCB. 375 * 376 * @returns VBox status code. 377 * @param ppTask Where to store the task handle on success. 378 * @param pTemplate The async completion template. 379 * @param pIoCB The asynchronous I/O control block to wait for. 380 * @param pvUser The user argument for the callback. 381 */ 382 DECLINLINE(int) PDMR3AsyncCompletionCreateUnxAIO(PPPDMASYNCCOMPLETIONTASK ppTask, PPDMASYNCCOMPLETIONTEMPLATE pTemplate, const struct aiocb *pAioCB, void *pvUser) 383 { 384 int rc = VINF_SUCCESS; 385 PPDMASYNCCOMPLETIONTASK pTask; 386 387 rc = PDMR3AsyncCompletionTaskCreate(&pTask, pTemplate, PDMASYNCCOMPLETIONTASKTYPE_HOST, (void *)pAioCB, pvUser); 388 if (VBOX_FAILURE(rc)) 389 { 390 AssertMsgFailed(("Creating AIO task failed\n")); 391 return rc; 392 } 393 394 rc = PDMR3AsyncCompletionTaskSubmit(pTask); 395 if (VBOX_FAILURE(rc)) 396 { 397 AssertMsgFailed(("Submitting AIO task failed\n")); 398 PDMR3AsyncCompletionTaskDestroy(pTask); 399 return rc; 400 } 401 402 *ppTask = pTask; 403 404 return rc; 405 } 406 #endif /* RT_OS_SOLARIS || RT_OS_DARWIN || RT_OS_FREEBSD || RT_OS_LINUX */ 407 408 #ifdef RT_OS_OS2 409 /** 410 * Creates a completion task for an event semaphore on OS/2. 411 * 412 * The pvCtx callback argument will be hev. 413 * 414 * @returns VBox status code. 415 * @param ppTask Where to store the task handle on success. 416 * @param pTemplate The async completion template. 417 * @param hev The handle of the event semaphore to wait on. 418 * @param pvUser The user argument for the callback. 419 */ 420 DECLINLINE(int) PDMR3AsyncCompletionCreateOs2Event(PPPDMASYNCCOMPLETIONTASK ppTask, PPDMASYNCCOMPLETIONTEMPLATE pTemplate, unsigned long hev, void *pvUser) 421 { 422 int rc = VINF_SUCCESS; 423 PPDMASYNCCOMPLETIONTASK pTask; 424 425 rc = PDMR3AsyncCompletionTaskCreate(&pTask, pTemplate, PDMASYNCCOMPLETIONTASKTYPE_HOST, (void *)&hev, pvUser); 426 if (VBOX_FAILURE(rc)) 427 { 428 AssertMsgFailed(("Creating OS/2 task failed\n")); 429 return rc; 430 } 431 432 rc = PDMR3AsyncCompletionTaskSubmit(pTask); 433 if (VBOX_FAILURE(rc)) 434 { 435 AssertMsgFailed(("Submitting OS/2 task failed\n")); 436 PDMR3AsyncCompletionTaskDestroy(pTask); 437 return rc; 438 } 439 440 *ppTask = pTask; 441 442 return rc; 443 } 444 #endif /* RT_OS_OS2 */ 445 446 #ifdef RT_OS_WINDOWS 447 /** 448 * Creates a completion task for an object on Windows. 449 * 450 * The pvCtx callback argument will be hObject. 451 * 452 * @returns VBox status code. 453 * @param ppTask Where to store the task handle on success. 454 * @param pTemplate The async completion template. 455 * @param hObject The object to wait for. 456 * @param pvUser The user argument for the callback. 457 */ 458 DECLINLINE(int) PDMR3AsyncCompletionCreateWinObject(PPPDMASYNCCOMPLETIONTASK ppTask, PPDMASYNCCOMPLETIONTEMPLATE pTemplate, void *hObject, void *pvUser) 459 { 460 int rc = VINF_SUCCESS; 461 PPDMASYNCCOMPLETIONTASK pTask; 462 463 rc = PDMR3AsyncCompletionTaskCreate(&pTask, pTemplate, PDMASYNCCOMPLETIONTASKTYPE_HOST, (void *)hObject, pvUser); 464 if (VBOX_FAILURE(rc)) 465 { 466 AssertMsgFailed(("Creating Windows task failed\n")); 467 return rc; 468 } 469 470 rc = PDMR3AsyncCompletionTaskSubmit(pTask); 471 if (VBOX_FAILURE(rc)) 472 { 473 AssertMsgFailed(("Submitting Windows task failed\n")); 474 PDMR3AsyncCompletionTaskDestroy(pTask); 475 return rc; 476 } 477 478 *ppTask = pTask; 479 480 return rc; 481 } 482 #endif /* RT_OS_WINDOWS */ 217 483 218 484 /** … … 233 499 typedef PDMASYNCCOMPLETIONSOCKET *PPDMASYNCCOMPLETIONSOCKET; 234 500 235 236 501 /** 237 502 * Creates a completion task for a socket. … … 248 513 * @param pvUser The user argument for the callback. 249 514 */ 250 PDMR3DECL(int) PDMR3AsyncCompletionCreateSocket(PPPDMASYNCCOMPLETION ppTask, PPDMASYNCCOMPLETIONTEMPLATE pTemplate, RTSOCKET Socket, bool fReadable, bool fWriteable, bool fXcpt, void *pvUser); 515 DECLINLINE(int) PDMR3AsyncCompletionCreateSocket(PPPDMASYNCCOMPLETIONTASK ppTask, PPDMASYNCCOMPLETIONTEMPLATE pTemplate, RTSOCKET Socket, bool fReadable, bool fWriteable, bool fXcpt, void *pvUser) 516 { 517 int rc = VINF_SUCCESS; 518 PPDMASYNCCOMPLETIONTASK pTask; 519 PDMASYNCCOMPLETIONSOCKET SocketContext; 520 521 SocketContext.Socket = Socket; 522 SocketContext.fReadable = fReadable; 523 SocketContext.fWriteable = fWriteable; 524 SocketContext.fXcpt = fXcpt; 525 526 rc = PDMR3AsyncCompletionTaskCreate(&pTask, pTemplate, PDMASYNCCOMPLETIONTASKTYPE_SOCKET, (void *)&SocketContext, pvUser); 527 if (VBOX_FAILURE(rc)) 528 { 529 AssertMsgFailed(("Creating Socket task failed\n")); 530 return rc; 531 } 532 533 rc = PDMR3AsyncCompletionTaskSubmit(pTask); 534 if (VBOX_FAILURE(rc)) 535 { 536 AssertMsgFailed(("Submitting Socket task failed\n")); 537 PDMR3AsyncCompletionTaskDestroy(pTask); 538 return rc; 539 } 540 541 *ppTask = pTask; 542 543 return rc; 544 } 251 545 252 546 /** … … 257 551 * @retval VERR_NOT_SUPPORTED if the task isn't a socket task. 258 552 * @param pTemplate The async completion template. 553 * @param Socket The socket 259 554 * @param fReadable Whether to callback when the socket becomes readable. 260 555 * @param fWriteable Whether to callback when the socket becomes writable. 261 556 * @param fXcpt Whether to callback on exception. 262 557 */ 263 PDMR3DECL(int) PDMR3AsyncCompletionModifySocket(PPDMASYNCCOMPLETION pTask, bool fReadable, bool fWriteable, bool fXcpt); 264 265 266 #if defined(RT_OS_LINUX) /*&& defined(_AIO_H)*/ 267 268 struct aiocb; 269 270 /** 271 * Creates a completion task for an AIO operation on Linux. 272 * 273 * The pvCtx callback argument will be pAioCB. 274 * 275 * @returns VBox status code. 276 * @param ppTask Where to store the task handle on success. 277 * @param pTemplate The async completion template. 278 * @param pAioCB The asynchronous I/O control block to wait for. 279 * @param pvUser The user argument for the callback. 280 */ 281 PDMR3DECL(int) PDMR3AsyncCompletionCreateLnxAIO(PPPDMASYNCCOMPLETION ppTask, PPDMASYNCCOMPLETIONTEMPLATE pTemplate, const struct aiocb *pAioCB, void *pvUser); 282 #endif /* RT_OS_LINUX */ 283 284 #ifdef RT_OS_OS2 285 /** 286 * Creates a completion task for an event semaphore on OS/2. 287 * 288 * The pvCtx callback argument will be hev. 289 * 290 * @returns VBox status code. 291 * @param ppTask Where to store the task handle on success. 292 * @param pTemplate The async completion template. 293 * @param hev The handle of the event semaphore to wait on. 294 * @param pvUser The user argument for the callback. 295 */ 296 PDMR3DECL(int) PDMR3AsyncCompletionCreateOs2Event(PPPDMASYNCCOMPLETION ppTask, PPDMASYNCCOMPLETIONTEMPLATE pTemplate, unsigned long hev, void *pvUser); 297 #endif /* RT_OS_OS2 */ 298 299 #ifdef RT_OS_WINDOWS 300 /** 301 * Creates a completion task for an object on Windows. 302 * 303 * The pvCtx callback argument will be hObject. 304 * 305 * @returns VBox status code. 306 * @param ppTask Where to store the task handle on success. 307 * @param pTemplate The async completion template. 308 * @param hObject The object to wait for. 309 * @param pvUser The user argument for the callback. 310 */ 311 PDMR3DECL(int) PDMR3AsyncCompletionCreateWinObject(PPPDMASYNCCOMPLETION ppTask, PPDMASYNCCOMPLETIONTEMPLATE pTemplate, void *hObject, void *pvUser); 312 #endif /* RT_OS_WINDOWS */ 313 314 315 316 /** 317 * Sets the user argument of a completion task. 318 * 319 * @returns VBox status code. 320 * @param pTask The async completion task. 321 * @param pvUser The user argument for the callback. 322 */ 323 PDMR3DECL(int) PDMR3AsyncCompletionSetUserArg(PPDMASYNCCOMPLETION pTask, void *pvUser); 324 325 /** 326 * Suspends a async completion task. 327 * 328 * @returns VBox status codes: 329 * @retval VINF_SUCCESS on success. 330 * @retval VERR_PDM_ASYNC_COMPLETION_ALREADY_SUSPENDED if already suspended. 331 * @retval VERR_INVALID_HANDLE if pTask is invalid (asserts). 332 * @param pTask The async completion task. 333 */ 334 PDMR3DECL(int) PDMR3AsyncCompletionSuspend(PPDMASYNCCOMPLETION pTask); 335 336 /** 337 * Suspends a async completion task. 338 * 339 * @returns VBox status codes: 340 * @retval VINF_SUCCESS on success. 341 * @retval VERR_PDM_ASYNC_COMPLETION_NOT_SUSPENDED if not suspended. 342 * @retval VERR_INVALID_HANDLE if pTask is invalid (asserts). 343 * @param pTask The async completion task. 344 */ 345 PDMR3DECL(int) PDMR3AsyncCompletionResume(PPDMASYNCCOMPLETION pTask); 346 347 /** 348 * Destroys a async completion task. 349 * 350 * The task doesn't have to be suspended or anything. 351 * 352 * @returns VBox status codes: 353 * @retval VINF_SUCCESS on success. 354 * @retval VERR_INVALID_HANDLE if pTask is invalid but not NIL (asserts). 355 * @param pTask The async completion task. 356 */ 357 PDMR3DECL(int) PDMR3AsyncCompletionDestroy(PPDMASYNCCOMPLETION pTask); 558 DECLINLINE(int) PDMR3AsyncCompletionModifySocket(PPDMASYNCCOMPLETIONTASK pTask, RTSOCKET Socket, bool fReadable, bool fWriteable, bool fXcpt) 559 { 560 int rc = VINF_SUCCESS; 561 PDMASYNCCOMPLETIONSOCKET SocketContext; 562 563 SocketContext.Socket = Socket; 564 SocketContext.fReadable = fReadable; 565 SocketContext.fWriteable = fWriteable; 566 SocketContext.fXcpt = fXcpt; 567 568 rc = PDMR3AsyncCompletionTaskAssociate(pTask, &SocketContext); 569 if (VBOX_FAILURE(rc)) 570 { 571 AssertMsgFailed(("Modifying Socket task failed\n")); 572 return rc; 573 } 574 575 return rc; 576 } 358 577 359 578 /** @} */ -
trunk/src/VBox/VMM/Makefile.kmk
r6996 r7821 148 148 VMMR3_DEFS.linux += __USE_FILE_OFFSET64 __USE_LARGEFILE64 149 149 VMMR3_SOURCES += PDMAsyncCompletion.cpp 150 VMMR3_SOURCES.linux += \ 151 PDMAsyncCompletionSocketPosix.cpp \ 152 PDMAsyncCompletionHostLinux.cpp \ 153 PDMAsyncCompletionHostPosix.cpp 154 155 VMMR3_SOURCES.win += \ 156 PDMAsyncCompletionSocketWin.cpp \ 157 PDMAsyncCompletionHostWin.cpp 158 159 VMMR3_SOURCES.solaris += \ 160 PDMAsyncCompletionSocketPosix.cpp \ 161 PDMAsyncCompletionHostSolaris.cpp 162 163 VMMR3_SOURCES.darwin += \ 164 PDMAsyncCompletionSocketPosix.cpp \ 165 PDMAsyncCompletionHostDarwin.cpp 166 167 VMMR3_SOURCES.freebsd += \ 168 PDMAsyncCompletionSocketPosix.cpp \ 169 PDMAsyncCompletionHostDarwin.cpp 170 150 171 endif 151 172 … … 175 196 VBoxVMM_LDFLAGS.darwin = -install_name @executable_path/VBoxVMM.dylib 176 197 VBoxVMM_LDFLAGS.solaris = -mimpure-text 177 198 ifdef VBOX_WITH_PDM_ASYNC_COMPLETION 199 ifeq ($(BUILD_PLATFORM), linux) 200 VBoxVMM_LIBS += aio 201 endif 202 endif 178 203 179 204 ifneq ($(filter pe lx,$(VBOX_LDR_FMT32)),)
Note:
See TracChangeset
for help on using the changeset viewer.