[Libreoffice-commits] core.git: vcl/unx
Pierre-Eric Pelloux-Prayer
pierre-eric at lanedo.com
Tue Jul 9 08:36:14 PDT 2013
vcl/unx/generic/dtrans/X11_selection.cxx | 42 +++++++++++++++++++++++++------
vcl/unx/generic/dtrans/X11_selection.hxx | 1
2 files changed, 36 insertions(+), 7 deletions(-)
New commits:
commit ec5a7256ca549d358b9c5380194ea2d1b991a73e
Author: Pierre-Eric Pelloux-Prayer <pierre-eric at lanedo.com>
Date: Fri Jul 5 14:44:38 2013 +0200
x11/unx: don't use a fixed 1sec timeout when polling X events
This commit replaces the 1 sec timeout by an infinite wait.
To properly handle application closing, a pipe is created and the
poll also waits for POLLIN event on it.
This allows to abort the infinite wait of poll by simply writing
a dummy byte to the pipe.
Change-Id: Ib340891f244a1b7bfb43b7c6ad866adfe260ec95
Reviewed-on: https://gerrit.libreoffice.org/4778
Reviewed-by: Petr Mladek <pmladek at suse.cz>
Tested-by: Petr Mladek <pmladek at suse.cz>
diff --git a/vcl/unx/generic/dtrans/X11_selection.cxx b/vcl/unx/generic/dtrans/X11_selection.cxx
index db613f3..871580f 100644
--- a/vcl/unx/generic/dtrans/X11_selection.cxx
+++ b/vcl/unx/generic/dtrans/X11_selection.cxx
@@ -453,6 +453,13 @@ void SelectionManager::initialize( const Sequence< Any >& arguments ) throw (::c
else
fprintf( stderr, "SelectionManager::initialize: creation of dispatch thread failed !\n" );
#endif
+
+ if (pipe(m_EndThreadPipe) != 0) {
+ #if OSL_DEBUG_LEVEL > 1
+ fprintf(stderr, "Failed to create endThreadPipe\n");
+ #endif
+ m_EndThreadPipe[0] = m_EndThreadPipe[1] = 0;
+ }
}
}
}
@@ -3711,14 +3718,26 @@ void SelectionManager::dispatchEvent( int millisec )
osl::ResettableMutexGuard aGuard(m_aMutex);
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;
+ {
+ int nfds = 1;
+ // wait for any events if none are already queued
+ pollfd aPollFD[2];
+ aPollFD[0].fd = XConnectionNumber( m_pDisplay );
+ aPollFD[0].events = POLLIN;
+ aPollFD[0].revents = 0;
+
+ // on infinite timeout we need endthreadpipe monitoring too
+ if (millisec < 0)
+ {
+ aPollFD[1].fd = m_EndThreadPipe[0];
+ aPollFD[1].events = POLLIN | POLLERR;
+ aPollFD[1].revents = 0;
+ nfds = 2;
+ }
+
// release mutex for the time of waiting for possible data
aGuard.clear();
- if( poll( &aPollFD, 1, millisec ) <= 0 )
+ if( poll( aPollFD, nfds, millisec ) <= 0 )
return;
aGuard.reset();
}
@@ -3750,9 +3769,13 @@ void SelectionManager::run( void* pThis )
This->m_xDesktop.set( Desktop::create(xContext) );
This->m_xDesktop->addTerminateListener(This);
+ // if end thread pipe properly initialized, allow infinite wait in poll
+ // otherwise, fallback on 1 sec timeout
+ const int timeout = (This->m_EndThreadPipe[0] != This->m_EndThreadPipe[1]) ? -1 : 1000;
+
while( osl_scheduleThread(This->m_aThread) )
{
- This->dispatchEvent( 1000 );
+ This->dispatchEvent( timeout );
timeval aNow;
gettimeofday( &aNow, 0 );
@@ -3832,9 +3855,14 @@ void SelectionManager::shutdown() throw()
{
SolarMutexGuard guard2;
Application::Reschedule();
+ // trigger poll()'s wait end by writing a dummy value
+ int dummy=0;
+ dummy = write(m_EndThreadPipe[1], &dummy, 1);
}
osl_joinWithThread( m_aThread );
osl_destroyThread( m_aThread );
+ close(m_EndThreadPipe[0]);
+ close(m_EndThreadPipe[1]);
m_aThread = NULL;
aGuard.reset();
}
diff --git a/vcl/unx/generic/dtrans/X11_selection.hxx b/vcl/unx/generic/dtrans/X11_selection.hxx
index f6982e7..84b6c0a 100644
--- a/vcl/unx/generic/dtrans/X11_selection.hxx
+++ b/vcl/unx/generic/dtrans/X11_selection.hxx
@@ -250,6 +250,7 @@ namespace x11 {
// internal data
Display* m_pDisplay;
oslThread m_aThread;
+ int m_EndThreadPipe[2];
oslThread m_aDragExecuteThread;
::osl::Condition m_aDragRunning;
XLIB_Window m_aWindow;
More information about the Libreoffice-commits
mailing list