Improved IPC behavior when the running instance does not respond for whatever reason.

This commit is contained in:
LoRd_MuldeR 2012-02-21 01:59:44 +01:00
parent ff3f5516d8
commit 72a9145a5d
4 changed files with 19 additions and 22 deletions

View File

@ -57,6 +57,7 @@ bool IPCThread::initialize(bool *firstInstance)
if(m_sharedMem->create(sizeof(DWORD), QSharedMemory::ReadWrite)) if(m_sharedMem->create(sizeof(DWORD), QSharedMemory::ReadWrite))
{ {
m_firstInstance = m_ipcReady = true; m_firstInstance = m_ipcReady = true;
memset(m_sharedMem->data(), 0, sizeof(DWORD));
} }
else else
{ {
@ -76,17 +77,6 @@ bool IPCThread::initialize(bool *firstInstance)
return m_ipcReady; return m_ipcReady;
} }
void IPCThread::notifyOtherInstance(void)
{
if(!m_firstInstance)
{
m_semaphore_w->acquire();
DWORD *pidPtr = reinterpret_cast<DWORD*>(m_sharedMem->data());
*pidPtr = GetCurrentProcessId();
m_semaphore_r->release();
}
}
void IPCThread::start(Priority priority) void IPCThread::start(Priority priority)
{ {
m_abort = false; m_abort = false;
@ -96,12 +86,6 @@ void IPCThread::start(Priority priority)
throw "IPC not initialized yet !!!"; throw "IPC not initialized yet !!!";
return; return;
} }
if(!m_firstInstance)
{
qWarning("This is NOT the first instance!");
return;
}
QThread::start(priority); QThread::start(priority);
} }
@ -117,6 +101,15 @@ void IPCThread::setAbort(void)
void IPCThread::run(void) void IPCThread::run(void)
{ {
if(!m_firstInstance)
{
m_semaphore_w->acquire();
DWORD *pidPtr = reinterpret_cast<DWORD*>(m_sharedMem->data());
*pidPtr = GetCurrentProcessId();
m_semaphore_r->release();
return;
}
forever forever
{ {
if(!m_semaphore_r->acquire()) if(!m_semaphore_r->acquire())

View File

@ -37,7 +37,6 @@ public:
void setAbort(void); void setAbort(void);
bool initialize(bool *firstInstance = NULL); bool initialize(bool *firstInstance = NULL);
void notifyOtherInstance(void);
signals: signals:
void instanceCreated(DWORD pid); void instanceCreated(DWORD pid);

View File

@ -22,7 +22,7 @@
#define VER_X264_MAJOR 2 #define VER_X264_MAJOR 2
#define VER_X264_MINOR 0 #define VER_X264_MINOR 0
#define VER_X264_PATCH 2 #define VER_X264_PATCH 2
#define VER_X264_BUILD 238 #define VER_X264_BUILD 243
#define VER_X264_MINIMUM_REV 2146 #define VER_X264_MINIMUM_REV 2146
#define VER_X264_CURRENT_API 120 #define VER_X264_CURRENT_API 120

View File

@ -638,12 +638,17 @@ void MainWindow::init(void)
bool firstInstance = false; bool firstInstance = false;
if(m_ipcThread->initialize(&firstInstance)) if(m_ipcThread->initialize(&firstInstance))
{ {
m_ipcThread->start();
if(!firstInstance) if(!firstInstance)
{ {
m_ipcThread->notifyOtherInstance(); if(!m_ipcThread->wait(5000))
{
QMessageBox::warning(this, tr("Not Responding"), tr("<nobr>Another instance of this application is already running, but did not respond in time.<br>If the problem persists, please kill the running instance from the task manager!</nobr>"), tr("Quit"));
m_ipcThread->terminate();
m_ipcThread->wait();
}
close(); qApp->exit(-1); return; close(); qApp->exit(-1); return;
} }
m_ipcThread->start();
} }
//Check all binaries //Check all binaries
@ -831,7 +836,7 @@ void MainWindow::handleDroppedFiles(void)
void MainWindow::instanceCreated(DWORD pid) void MainWindow::instanceCreated(DWORD pid)
{ {
qDebug("Notification from other instance received!"); qDebug("Notification from other instance (PID=0x%X) received!", pid);
FLASHWINFO flashWinInfo; FLASHWINFO flashWinInfo;
memset(&flashWinInfo, 0, sizeof(FLASHWINFO)); memset(&flashWinInfo, 0, sizeof(FLASHWINFO));