VirtualBox

Changeset 50639 in vbox


Ignore:
Timestamp:
Feb 27, 2014 8:16:44 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
92533
Message:

Additions/x11/VBoxClient: fix busy waiting in the drag and drop X11 thread.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/VBoxClient/draganddrop.cpp

    r50593 r50639  
    1414 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    1515 */
     16
     17#include <errno.h>
     18#include <poll.h>
    1619
    1720#include <X11/Xlib.h>
     
    416419      , m_hEventSem(NIL_RTSEMEVENT)
    417420      , m_pCurDnD(0)
    418       , m_fSrvStopping(false)
    419421    {}
    420422
     
    465467    RTSEMEVENT           m_hEventSem;
    466468    DragInstance        *m_pCurDnD;
    467     bool                 m_fSrvStopping;
    468469
    469470    friend class DragInstance;
     
    17491750                }
    17501751            }
    1751         } while (!ASMAtomicReadBool(&m_fSrvStopping));
     1752            XFlush(m_pDisplay);
     1753        } while (1);
    17521754    } while (0);
    17531755
     
    18391841        }
    18401842
    1841     } while (!ASMAtomicReadBool(&pThis->m_fSrvStopping));
     1843    } while (1);
    18421844
    18431845    VbglR3DnDDisconnect(uClientID);
     
    18541856    do
    18551857    {
    1856         /* Wait for new events. We can't use XIfEvent here, cause this locks
     1858        /* Wait for new events. We can't use XIfEvent here, because this locks
    18571859         * the window connection with a mutex and if no X11 events occurs this
    1858          * blocks any other calls we made to X11. So instead check for new
    1859          * events and if there are not any new one, sleep for a certain amount
    1860          * of time. */
     1860         * blocks any other calls we made to X11. So instead poll for new events
     1861         * on the connection file descriptor. */
     1862        /** @todo Make sure the locking is right - Xlib displays should never be
     1863         * used from two threads at once. */
    18611864        if (XEventsQueued(pThis->m_pDisplay, QueuedAfterFlush) > 0)
    18621865        {
     
    18731876        }
    18741877        else
    1875             RTThreadSleep(25);
    1876     } while (!ASMAtomicReadBool(&pThis->m_fSrvStopping));
     1878        {
     1879            struct pollfd pollFD;
     1880
     1881            pollFD.fd = ConnectionNumber(pThis->m_pDisplay);
     1882            pollFD.events = POLLIN | POLLPRI;
     1883            if (   (poll(&pollFD, 1, -1) < 0 && errno != EINTR)
     1884                || pollFD.revents & POLLNVAL)
     1885            {
     1886                LogRel(("X11 event thread: poll failed, stopping.\n"));
     1887                /** @todo Just stop the whole service.  What use is it just
     1888                 *        to stop one thread? */
     1889                return RTErrConvertFromErrno(errno);
     1890            }
     1891        }
     1892    } while (1);
    18771893
    18781894    return VINF_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.

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