[Libreoffice-commits] .: 2 commits - desktop/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Thu Dec 13 06:58:30 PST 2012
desktop/source/app/officeipcthread.cxx | 64 ++++++++++++++-------------------
desktop/source/app/officeipcthread.hxx | 2 -
2 files changed, 28 insertions(+), 38 deletions(-)
New commits:
commit 4ce2602befd59e69264d8e4ced8730b40c2b947c
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Dec 13 15:41:10 2012 +0100
Related fdo#33484: Terminate OfficeIPCThread by closing the accepting pipe
... (and setting mbDowning to indicate an error returned from accept() is due to
termination) instead of setting up an extra pipe connection to send an
"InternalIPC::TerminateThread" message (which allegedly caused deadlocks, see
<https://gerrit.libreoffice.org/#/c/1311/> "Change Idf933915: office ipc: use
timeout pipe feature when connecting to self").
Change-Id: Id302ca13112fc409685e7665b38f1030704a0ccf
diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx
index e287d2b..8828311 100644
--- a/desktop/source/app/officeipcthread.cxx
+++ b/desktop/source/app/officeipcthread.cxx
@@ -51,8 +51,6 @@ using ::rtl::OString;
using ::rtl::OUString;
using ::rtl::OUStringBuffer;
-const char *OfficeIPCThread::sc_aTerminationSequence = "InternalIPC::TerminateThread";
-const int OfficeIPCThread::sc_nTSeqLength = 28;
const char *OfficeIPCThread::sc_aShowSequence = "-tofront";
const int OfficeIPCThread::sc_nShSeqLength = 5;
const char *OfficeIPCThread::sc_aConfirmationSequence = "InternalIPC::ProcessingDone";
@@ -427,8 +425,6 @@ OfficeIPCThread::Status OfficeIPCThread::EnableOfficeIPCThread()
rtl::Reference< OfficeIPCThread > pThread(new OfficeIPCThread);
- pThread->maPipeIdent = OUString( "SingleOfficeIPC_" );
-
// The name of the named pipe is created with the hashcode of the user installation directory (without /user). We have to retrieve
// this information from a unotools implementation.
::utl::Bootstrap::PathStatus aLocateResult = ::utl::Bootstrap::locateUserInstallation( aUserInstallPath );
@@ -485,19 +481,19 @@ OfficeIPCThread::Status OfficeIPCThread::EnableOfficeIPCThread()
if ( aUserInstallPathHashCode.isEmpty() )
return IPC_STATUS_BOOTSTRAP_ERROR; // Something completely broken, we cannot create a valid hash code!
- pThread->maPipeIdent = pThread->maPipeIdent + aUserInstallPathHashCode;
+ OUString aPipeIdent( "SingleOfficeIPC_" + aUserInstallPathHashCode );
PipeMode nPipeMode = PIPEMODE_DONTKNOW;
do
{
osl::Security &rSecurity = Security::get();
// Try to create pipe
- if ( pThread->maPipe.create( pThread->maPipeIdent.getStr(), osl_Pipe_CREATE, rSecurity ))
+ if ( pThread->maPipe.create( aPipeIdent.getStr(), osl_Pipe_CREATE, rSecurity ))
{
// Pipe created
nPipeMode = PIPEMODE_CREATED;
}
- else if( pThread->maPipe.create( pThread->maPipeIdent.getStr(), osl_Pipe_OPEN, rSecurity )) // Creation not successfull, now we try to connect
+ else if( pThread->maPipe.create( aPipeIdent.getStr(), osl_Pipe_OPEN, rSecurity )) // Creation not successfull, now we try to connect
{
osl::StreamPipe aStreamPipe(pThread->maPipe.getHandle());
char pReceiveBuffer[sc_nCSASeqLength + 1];
@@ -601,18 +597,8 @@ void OfficeIPCThread::DisableOfficeIPCThread(bool join)
pGlobalOfficeIPCThread);
pGlobalOfficeIPCThread.clear();
- // send thread a termination message
- // this is done so the subsequent join will not hang
- // because the thread hangs in accept of pipe
- osl::StreamPipe aPipe ( pOfficeIPCThread->maPipeIdent, osl_Pipe_OPEN, Security::get() );
- if (aPipe.is())
- {
- aPipe.send( sc_aTerminationSequence, sc_nTSeqLength+1 ); // also send 0-byte
-
- // close the pipe so that the streampipe on the other
- // side produces EOF
- aPipe.close();
- }
+ pOfficeIPCThread->mbDowning = true;
+ pOfficeIPCThread->maPipe.close();
// release mutex to avoid deadlocks
aMutex.clear();
@@ -680,22 +666,23 @@ void OfficeIPCThread::execute()
// down during wait
osl::ClearableMutexGuard aGuard( GetMutex() );
- if (!mbDowning)
+ if ( mbDowning )
{
- // notify client we're ready to process its args
- int nBytes = 0;
- int nResult = 0;
- while (
- (nResult = aStreamPipe.send(sc_aSendArgumentsSequence+nBytes, sc_nCSASeqLength-nBytes))>0 &&
- ((nBytes += nResult) < sc_nCSASeqLength) ) ;
+ break;
}
+
+ // notify client we're ready to process its args
+ int nBytes = 0;
+ int nResult;
+ while (
+ (nResult = aStreamPipe.send(sc_aSendArgumentsSequence+nBytes, sc_nCSASeqLength-nBytes))>0 &&
+ ((nBytes += nResult) < sc_nCSASeqLength) ) ;
aStreamPipe.write("\0", 1);
// test byte by byte
const int nBufSz = 2048;
char pBuf[nBufSz];
- int nBytes = 0;
- int nResult = 0;
+ nBytes = 0;
rtl::OStringBuffer aBuf;
// read into pBuf until '\0' is read or read-error
while ((nResult=aStreamPipe.recv( pBuf+nBytes, nBufSz-nBytes))>0) {
@@ -713,9 +700,6 @@ void OfficeIPCThread::execute()
if (aArguments.isEmpty())
continue;
- // is this a termination message ? if so, terminate
- if (aArguments.equalsL(sc_aTerminationSequence, sc_nTSeqLength) || mbDowning)
- return;
std::auto_ptr< CommandLineArgs > aCmdLineArgs;
try
{
@@ -932,6 +916,14 @@ void OfficeIPCThread::execute()
}
else
{
+ {
+ osl::MutexGuard aGuard( GetMutex() );
+ if ( mbDowning )
+ {
+ break;
+ }
+ }
+
#if (OSL_DEBUG_LEVEL > 1) || defined DBG_UTIL
fprintf( stderr, "Error on accept: %d\n", (int)nError );
#endif
diff --git a/desktop/source/app/officeipcthread.hxx b/desktop/source/app/officeipcthread.hxx
index c07da3d..440fd24 100644
--- a/desktop/source/app/officeipcthread.hxx
+++ b/desktop/source/app/officeipcthread.hxx
@@ -72,7 +72,6 @@ class OfficeIPCThread : public salhelper::Thread
static rtl::Reference< OfficeIPCThread > pGlobalOfficeIPCThread;
osl::Pipe maPipe;
- rtl::OUString maPipeIdent;
bool mbDowning;
bool mbRequestsEnabled;
int mnPendingRequests;
commit e956803c8fbd8d432b860a55c3ba8399bcd03361
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Dec 13 15:08:30 2012 +0100
Reduce scope of OfficeIPCThread::maStreamPipe
(Also, its destructor will close it when it goes out of scope.)
Change-Id: Iaa9bebce3c0bda780f4c80c193ce619c2e6d5768
diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx
index 7d477a7..e287d2b 100644
--- a/desktop/source/app/officeipcthread.cxx
+++ b/desktop/source/app/officeipcthread.cxx
@@ -643,7 +643,6 @@ OfficeIPCThread::~OfficeIPCThread()
if ( mpDispatchWatcher )
mpDispatchWatcher->release();
maPipe.close();
- maStreamPipe.close();
pGlobalOfficeIPCThread.clear();
}
@@ -662,7 +661,8 @@ void OfficeIPCThread::execute()
{
do
{
- oslPipeError nError = maPipe.accept( maStreamPipe );
+ osl::StreamPipe aStreamPipe;
+ oslPipeError nError = maPipe.accept( aStreamPipe );
if( nError == osl_Pipe_E_None )
@@ -686,10 +686,10 @@ void OfficeIPCThread::execute()
int nBytes = 0;
int nResult = 0;
while (
- (nResult = maStreamPipe.send(sc_aSendArgumentsSequence+nBytes, sc_nCSASeqLength-nBytes))>0 &&
+ (nResult = aStreamPipe.send(sc_aSendArgumentsSequence+nBytes, sc_nCSASeqLength-nBytes))>0 &&
((nBytes += nResult) < sc_nCSASeqLength) ) ;
}
- maStreamPipe.write("\0", 1);
+ aStreamPipe.write("\0", 1);
// test byte by byte
const int nBufSz = 2048;
@@ -698,7 +698,7 @@ void OfficeIPCThread::execute()
int nResult = 0;
rtl::OStringBuffer aBuf;
// read into pBuf until '\0' is read or read-error
- while ((nResult=maStreamPipe.recv( pBuf+nBytes, nBufSz-nBytes))>0) {
+ while ((nResult=aStreamPipe.recv( pBuf+nBytes, nBufSz-nBytes))>0) {
nBytes += nResult;
if (pBuf[nBytes-1]=='\0') {
aBuf.append(pBuf);
@@ -927,7 +927,7 @@ void OfficeIPCThread::execute()
// processing finished, inform the requesting end
nBytes = 0;
while (
- (nResult = maStreamPipe.send(sc_aConfirmationSequence+nBytes, sc_nCSeqLength-nBytes))>0 &&
+ (nResult = aStreamPipe.send(sc_aConfirmationSequence+nBytes, sc_nCSeqLength-nBytes))>0 &&
((nBytes += nResult) < sc_nCSeqLength) ) ;
}
else
diff --git a/desktop/source/app/officeipcthread.hxx b/desktop/source/app/officeipcthread.hxx
index 3dd7eac..c07da3d 100644
--- a/desktop/source/app/officeipcthread.hxx
+++ b/desktop/source/app/officeipcthread.hxx
@@ -72,7 +72,6 @@ class OfficeIPCThread : public salhelper::Thread
static rtl::Reference< OfficeIPCThread > pGlobalOfficeIPCThread;
osl::Pipe maPipe;
- osl::StreamPipe maStreamPipe;
rtl::OUString maPipeIdent;
bool mbDowning;
bool mbRequestsEnabled;
More information about the Libreoffice-commits
mailing list