Changeset 92653 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Nov 30, 2021 5:28:01 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/x11/VBoxClient/display-drm.cpp
r92623 r92653 48 48 #include <iprt/initterm.h> 49 49 #include <iprt/message.h> 50 #include <iprt/thread.h> 51 #include <iprt/asm.h> 50 52 #include <unistd.h> 51 53 #include <stdio.h> 52 54 #include <limits.h> 55 #include <signal.h> 53 56 54 57 #ifdef RT_OS_LINUX … … 77 80 * context structure. */ 78 81 #define VMW_MAX_HEADS (32) 82 83 /** Name of DRM resize thread. */ 84 #define DRM_RESIZE_THREAD_NAME "DrmResizeThread" 85 86 /* Time in milliseconds to wait for host events. */ 87 #define DRM_HOST_EVENT_RX_TIMEOUT_MS (500) 79 88 80 89 /** DRM version structure. */ … … 119 128 /** Path to the PID file. */ 120 129 static const char g_szPidFile[RTPATH_MAX] = "/var/run/VBoxDRMClient"; 130 131 /** Global flag which is triggered when service requested to shutdown. */ 132 static bool volatile g_fShutdown; 121 133 122 134 /** … … 415 427 } 416 428 417 418 static void drmMainLoop(RTFILE hDevice)429 /** Worker thread for resize task. */ 430 static DECLCALLBACK(int) drmResizeWorker(RTTHREAD ThreadSelf, void *pvUser) 419 431 { 420 432 int rc; 433 RTFILE hDevice = (RTFILE)pvUser; 434 435 RT_NOREF1(ThreadSelf); 436 437 AssertReturn(hDevice, VERR_INVALID_PARAMETER); 421 438 422 439 for (;;) … … 472 489 do 473 490 { 474 rc = VbglR3WaitEvent(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, RT_INDEFINITE_WAIT, &events); 475 } while (rc == VERR_INTERRUPTED); 476 if (RT_FAILURE(rc)) 491 rc = VbglR3WaitEvent(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, DRM_HOST_EVENT_RX_TIMEOUT_MS, &events); 492 } while (rc == VERR_TIMEOUT && !ASMAtomicReadBool(&g_fShutdown)); 493 494 if (ASMAtomicReadBool(&g_fShutdown)) 495 { 496 VBClLogInfo("VBoxDRMClient: exitting resize thread: shutdown requested\n"); 497 break; 498 } 499 else if (RT_FAILURE(rc)) 500 { 477 501 VBClLogFatalError("Failure waiting for event, rc=%Rrc\n", rc); 478 } 502 } 503 } 504 505 return 0; 506 } 507 508 static void drmRequestShutdown(int sig) 509 { 510 RT_NOREF1(sig); 511 512 ASMAtomicWriteBool(&g_fShutdown, true); 479 513 } 480 514 … … 483 517 RTFILE hDevice = NIL_RTFILE; 484 518 RTFILE hPidFile; 519 520 RTTHREAD drmResizeThread; 521 int rcDrmResizeThread = 0; 485 522 486 523 int rc = RTR3InitExe(argc, &argv, 0); … … 523 560 hDevice = drmOpenVmwgfx(); 524 561 if (hDevice == NIL_RTFILE) 525 return VERR_OPEN_FAILED;562 return RTEXITCODE_FAILURE; 526 563 527 564 rc = VbglR3CtlFilterMask(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, 0); … … 529 566 { 530 567 VBClLogFatalError("Failed to request display change events, rc=%Rrc\n", rc); 531 return VERR_INVALID_HANDLE;568 return RTEXITCODE_FAILURE; 532 569 } 533 570 rc = VbglR3AcquireGuestCaps(VMMDEV_GUEST_SUPPORTS_GRAPHICS, 0, false); 534 571 if (rc == VERR_RESOURCE_BUSY) /* Someone else has already acquired it. */ 535 572 { 536 return VERR_RESOURCE_BUSY;573 return RTEXITCODE_FAILURE; 537 574 } 538 575 if (RT_FAILURE(rc)) 539 576 { 540 577 VBClLogFatalError("Failed to register resizing support, rc=%Rrc\n", rc); 541 return VERR_INVALID_HANDLE; 542 } 543 544 drmMainLoop(hDevice); 545 546 /** @todo this code never executed since we do not have yet a clean way to exit 547 * main event loop above. */ 578 return RTEXITCODE_FAILURE; 579 } 580 581 /* Setup signals: gracefully terminate on SIGINT, SIGTERM. */ 582 if ( signal(SIGINT, drmRequestShutdown) == SIG_ERR 583 || signal(SIGTERM, drmRequestShutdown) == SIG_ERR) 584 { 585 VBClLogError("VBoxDRMClient: unable to setup signals\n"); 586 return RTEXITCODE_FAILURE; 587 } 588 589 /* Attempt to start DRM resize task. */ 590 rc = RTThreadCreate(&drmResizeThread, drmResizeWorker, (void *)hDevice, 0, 591 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, DRM_RESIZE_THREAD_NAME); 592 if (RT_SUCCESS(rc)) 593 { 594 rc = RTThreadWait(drmResizeThread, RT_INDEFINITE_WAIT, &rcDrmResizeThread); 595 VBClLogInfo("VBoxDRMClient: %s thread exitted with status %Rrc\n", DRM_RESIZE_THREAD_NAME, rcDrmResizeThread); 596 rc |= rcDrmResizeThread; 597 } 548 598 549 599 RTFileClose(hDevice); … … 552 602 VbglR3ClosePidFile(g_szPidFile, hPidFile); 553 603 554 return 0;555 } 604 return rc == 0 ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 605 }
Note:
See TracChangeset
for help on using the changeset viewer.