[Libreoffice-commits] .: Branch 'libreoffice-3-4' - vcl/unx

Lubos Lunak llunak at kemper.freedesktop.org
Wed Apr 6 06:54:38 PDT 2011


 vcl/unx/source/dtrans/X11_selection.cxx |   54 ++++++++++++--------------------
 1 file changed, 21 insertions(+), 33 deletions(-)

New commits:
commit ee39d120e7730970e8f5ce57ec6ec3abee37efed
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Tue Apr 5 18:25:22 2011 +0200

    rework confused and racy clipboard event polling (bnc#683941)
    
    It does not work reliably to just poll on the X connection fd,
    as there may be already incoming events in the Xlib queue (removed
    from the fd connection). So XPending() call is necessary; which
    additionally ensures the output queue is flushed before polling.
    The second poll() seems to have been just introduced as a result
    of failing to understand this, and the strange XPending() nesting
    later is no longer needed either.

diff --git a/vcl/unx/source/dtrans/X11_selection.cxx b/vcl/unx/source/dtrans/X11_selection.cxx
index 5a27af6..dda0aeb 100644
--- a/vcl/unx/source/dtrans/X11_selection.cxx
+++ b/vcl/unx/source/dtrans/X11_selection.cxx
@@ -3729,41 +3729,29 @@ bool SelectionManager::handleXEvent( XEvent& rEvent )
 
 void SelectionManager::dispatchEvent( int millisec )
 {
-    pollfd aPollFD;
-    XEvent event;
-
-    // query socket handle to poll on
-    aPollFD.fd      = ConnectionNumber( m_pDisplay );
-    aPollFD.events  = POLLIN;
-    aPollFD.revents = 0;
+    // acquire the mutex to prevent other threads
+    // from using the same X connection
+    osl::ResettableMutexGuard aGuard(m_aMutex);
 
-    // wait for activity (outside the xlib)
-    if( poll( &aPollFD, 1, millisec ) > 0 )
+    if( !XPending( m_pDisplay ))
+    { // wait for any events if none are already queued
+        pollfd aPollFD;
+        aPollFD.fd      = XConnectionNumber( m_pDisplay );
+        aPollFD.events  = POLLIN;
+        aPollFD.revents = 0;
+        // release mutex for the time of waiting for possible data
+        aGuard.clear();
+        if( poll( &aPollFD, 1, millisec ) <= 0 )
+            return;
+        aGuard.reset();
+    }
+    while( XPending( m_pDisplay ))
     {
-        // now acquire the mutex to prevent other threads
-        // from using the same X connection
-        osl::ResettableMutexGuard aGuard(m_aMutex);
-
-        // prevent that another thread already ate the input
-        // this can happen if e.g. another thread does
-        // an X request getting a response. the response
-        // would be removed from the queue and we would end up
-        // with an empty socket here
-        if( poll( &aPollFD, 1, 0 ) > 0 )
-        {
-            int nPending = 1;
-            while( nPending )
-            {
-                nPending = XPending( m_pDisplay );
-                if( nPending )
-                {
-                    XNextEvent( m_pDisplay, &event );
-                    aGuard.clear();
-                    handleXEvent( event );
-                    aGuard.reset();
-                }
-            }
-        }
+        XEvent event;
+        XNextEvent( m_pDisplay, &event );
+        aGuard.clear();
+        handleXEvent( event );
+        aGuard.reset();
     }
 }
 


More information about the Libreoffice-commits mailing list