VirtualBox

Ignore:
Timestamp:
Oct 27, 2020 9:10:35 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
141102
Message:

Shared Clipboard/X11: More work on untangling / cleaning up the threading code. bugref:9848

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-x11.cpp

    r86713 r86717  
    405405
    406406#ifndef TESTCASE
    407     XtAppAddTimeOut(pCtx->appContext, 0, (XtTimerCallbackProc)proc,
     407    XtAppAddTimeOut(pCtx->pAppContext, 0, (XtTimerCallbackProc)proc,
    408408                    (XtPointer)client_data);
    409409    ssize_t cbWritten = write(pCtx->wakeupPipeWrite, WAKE_UP_STRING, WAKE_UP_STRING_LEN);
     
    824824    } event = { { 0 } };
    825825
    826     if (XtAppPeekEvent(pCtx->appContext, &event.event))
     826    if (XtAppPeekEvent(pCtx->pAppContext, &event.event))
    827827    {
    828828        if (   (event.event.type == pCtx->fixesEventBase)
     
    847847static DECLCALLBACK(int) clipThreadMain(RTTHREAD hThreadSelf, void *pvUser)
    848848{
    849     RT_NOREF(hThreadSelf);
    850     AssertPtrReturn(pvUser, VERR_INVALID_POINTER);
    851 
    852     LogRel2(("Shared Clipboard: Starting X11 event thread\n"));
    853 
    854     PSHCLX11CTX pCtx = (SHCLX11CTX *)pvUser;
    855 
    856     clipInitInternal(pCtx);
    857 
    858     if (pCtx->fGrabClipboardOnStart)
    859         clipQueryX11Formats(pCtx);
    860 
    861     /* We're now ready to run, tell parent. */
    862     int rc2 = RTThreadUserSignal(hThreadSelf);
    863     AssertRC(rc2);
    864 
    865     while (XtAppGetExitFlag(pCtx->appContext) == FALSE)
    866     {
    867         clipPeekEventAndDoXFixesHandling(pCtx);
    868         XtAppProcessEvent(pCtx->appContext, XtIMAll);
    869     }
    870 
    871     clipUninitInternal(pCtx);
    872 
    873     LogRel2(("Shared Clipboard: X11 event thread terminated successfully\n"));
    874     return VINF_SUCCESS;
     849    PSHCLX11CTX pCtx = (PSHCLX11CTX)pvUser;
     850    AssertPtr(pCtx);
     851
     852    LogFlowFunc(("pCtx=%p\n", pCtx));
     853
     854    bool fSignalled = false; /* Whether we have signalled the parent already or not. */
     855
     856    int rc = clipInitInternal(pCtx);
     857    if (RT_SUCCESS(rc))
     858    {
     859        rc = clipRegisterContext(pCtx);
     860        if (RT_SUCCESS(rc))
     861        {
     862            if (pCtx->fGrabClipboardOnStart)
     863                clipQueryX11Formats(pCtx);
     864
     865            pCtx->fThreadStarted = true;
     866
     867            /* We're now ready to run, tell parent. */
     868            int rc2 = RTThreadUserSignal(hThreadSelf);
     869            AssertRC(rc2);
     870
     871            fSignalled = true;
     872
     873            while (XtAppGetExitFlag(pCtx->pAppContext) == FALSE)
     874            {
     875                clipPeekEventAndDoXFixesHandling(pCtx);
     876                XtAppProcessEvent(pCtx->pAppContext, XtIMAll);
     877            }
     878
     879            clipUnregisterContext(pCtx);
     880        }
     881
     882        clipUninitInternal(pCtx);
     883    }
     884
     885    if (!fSignalled) /* Signal parent if we didn't do so yet. */
     886    {
     887        int rc2 = RTThreadUserSignal(hThreadSelf);
     888        AssertRC(rc2);
     889    }
     890
     891    LogFlowFuncLeaveRC(rc);
     892    return rc;
    875893}
    876894
     
    891909     * reiterate that any outstanding requests from the X11 event loop to
    892910     * the VBox part *must* have returned before we do this. */
    893     XtAppSetExitFlag(pCtx->appContext);
     911    XtAppSetExitFlag(pCtx->pAppContext);
    894912}
    895913
     
    9901008    int rc = VINF_SUCCESS;
    9911009
    992     Assert(pCtx->appContext == NULL); /* No nested initialization. */
    993     pCtx->appContext = XtCreateApplicationContext();
    994     if (pCtx->appContext == NULL)
     1010    Assert(pCtx->pAppContext == NULL); /* No nested initialization. */
     1011    pCtx->pAppContext = XtCreateApplicationContext();
     1012    if (pCtx->pAppContext == NULL)
    9951013    {
    9961014        LogRel(("Shared Clipboard: Failed to create Xt application context\n"));
     
    10011019    int      cArgc  = 0;
    10021020    char    *pcArgv = 0;
    1003     Display *pDisplay = XtOpenDisplay(pCtx->appContext, 0, 0, "VBoxShCl", 0, 0, &cArgc, &pcArgv);
     1021    Display *pDisplay = XtOpenDisplay(pCtx->pAppContext, 0, 0, "VBoxShCl", 0, 0, &cArgc, &pcArgv);
    10041022    if (pDisplay == NULL)
    10051023    {
     
    10251043        if (pCtx->pWidget == NULL)
    10261044        {
    1027             LogRel(("Shared Clipboard: Failed to construct the X11 window\n"));
     1045            LogRel(("Shared Clipboard: Failed to create Xt app shell\n"));
    10281046            rc = VERR_NO_MEMORY; /** @todo r=andy Improve this. */
    10291047        }
    10301048        else
    1031             rc = clipRegisterContext(pCtx);
     1049        {
     1050#ifndef TESTCASE
     1051            if (!XtAppAddInput(pCtx->pAppContext, pCtx->wakeupPipeRead,
     1052                               (XtPointer) XtInputReadMask,
     1053                               clipThreadDrainWakeupPipe, (XtPointer) pCtx))
     1054            {
     1055                LogRel(("Shared Clipboard: Failed to add input to Xt app context\n"));
     1056                rc = VERR_ACCESS_DENIED; /** @todo r=andy Improve this. */
     1057            }
     1058#endif
     1059        }
    10321060    }
    10331061
     
    10711099    {
    10721100        /* Valid widget + invalid appcontext = bug.  But don't return yet. */
    1073         AssertPtr(pCtx->appContext);
    1074         clipUnregisterContext(pCtx);
     1101        AssertPtr(pCtx->pAppContext);
    10751102
    10761103        XtDestroyWidget(pCtx->pWidget);
     
    10781105    }
    10791106
    1080     if (pCtx->appContext)
    1081     {
    1082         XtDestroyApplicationContext(pCtx->appContext);
    1083         pCtx->appContext = NULL;
     1107    if (pCtx->pAppContext)
     1108    {
     1109        XtDestroyApplicationContext(pCtx->pAppContext);
     1110        pCtx->pAppContext = NULL;
    10841111    }
    10851112
     
    11331160        /** @todo The testcases currently do not utilize the threading code. So init stuff here. */
    11341161        rc = clipInitInternal(pCtx);
     1162        if (RT_SUCCESS(rc))
     1163            rc = clipRegisterContext(pCtx);
    11351164    }
    11361165#endif
     
    11551184    /** @todo The testcases currently do not utilize the threading code. So uninit stuff here. */
    11561185    clipUninitInternal(pCtx);
     1186    clipUnregisterContext(pCtx);
    11571187#endif
    11581188
     
    11971227    if (!pipe(pipes))
    11981228    {
    1199         pCtx->wakeupPipeRead = pipes[0];
     1229        pCtx->wakeupPipeRead  = pipes[0];
    12001230        pCtx->wakeupPipeWrite = pipes[1];
    1201         if (!XtAppAddInput(pCtx->appContext, pCtx->wakeupPipeRead,
    1202                            (XtPointer) XtInputReadMask,
    1203                            clipThreadDrainWakeupPipe, (XtPointer) pCtx))
    1204             rc = VERR_NO_MEMORY;  /* What failure means is not doc'ed. */
    1205         if (   RT_SUCCESS(rc)
    1206             && (fcntl(pCtx->wakeupPipeRead, F_SETFL, O_NONBLOCK) != 0))
     1231
     1232        if (!fcntl(pCtx->wakeupPipeRead, F_SETFL, O_NONBLOCK))
     1233        {
     1234            rc = VINF_SUCCESS;
     1235        }
     1236        else
    12071237            rc = RTErrConvertFromErrno(errno);
    1208         if (RT_FAILURE(rc))
    1209             LogRel(("Shared Clipboard: Failed to setup the termination mechanism\n"));
    12101238    }
    12111239    else
     
    12271255        }
    12281256        else
    1229             LogRel2(("Shared Clipboard: X11 event thread started\n"));
     1257        {
     1258            if (!pCtx->fThreadStarted)
     1259            {
     1260                LogRel(("Shared Clipboard: X11 event thread reported an error while starting\n"));
     1261            }
     1262            else
     1263                LogRel2(("Shared Clipboard: X11 event thread started\n"));
     1264        }
    12301265    }
    12311266
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette