OSDN Git Service

Improved IPC behavior when the running instance does not respond for whatever reason.
authorlordmulder <mulder2@gmx.de>
Tue, 21 Feb 2012 00:59:44 +0000 (01:59 +0100)
committerlordmulder <mulder2@gmx.de>
Tue, 21 Feb 2012 00:59:44 +0000 (01:59 +0100)
src/thread_ipc.cpp
src/thread_ipc.h
src/version.h
src/win_main.cpp

index 7a2b8ca..45fe4e3 100644 (file)
@@ -57,6 +57,7 @@ bool IPCThread::initialize(bool *firstInstance)
                        if(m_sharedMem->create(sizeof(DWORD), QSharedMemory::ReadWrite))
                        {
                                m_firstInstance = m_ipcReady = true;
+                               memset(m_sharedMem->data(), 0, sizeof(DWORD));
                        }
                        else
                        {
@@ -76,17 +77,6 @@ bool IPCThread::initialize(bool *firstInstance)
        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)
 {
        m_abort = false;
@@ -96,12 +86,6 @@ void IPCThread::start(Priority priority)
                throw "IPC not initialized yet !!!";
                return;
        }
-       
-       if(!m_firstInstance)
-       {
-               qWarning("This is NOT the first instance!");
-               return;
-       }
 
        QThread::start(priority);
 }
@@ -117,6 +101,15 @@ void IPCThread::setAbort(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
        {
                if(!m_semaphore_r->acquire())
index 25f4d10..e054e5f 100644 (file)
@@ -37,7 +37,6 @@ public:
 
        void setAbort(void);
        bool initialize(bool *firstInstance = NULL);
-       void notifyOtherInstance(void);
 
 signals:
        void instanceCreated(DWORD pid);
index bdc738b..f44eceb 100644 (file)
@@ -22,7 +22,7 @@
 #define VER_X264_MAJOR 2
 #define VER_X264_MINOR 0
 #define VER_X264_PATCH 2
-#define VER_X264_BUILD 238
+#define VER_X264_BUILD 243
 
 #define VER_X264_MINIMUM_REV 2146
 #define VER_X264_CURRENT_API 120
index fcb3b0f..daf37a7 100644 (file)
@@ -638,12 +638,17 @@ void MainWindow::init(void)
        bool firstInstance = false;
        if(m_ipcThread->initialize(&firstInstance))
        {
+               m_ipcThread->start();
                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;
                }
-               m_ipcThread->start();
        }
 
        //Check all binaries
@@ -831,7 +836,7 @@ void MainWindow::handleDroppedFiles(void)
 
 void MainWindow::instanceCreated(DWORD pid)
 {
-       qDebug("Notification from other instance received!");
+       qDebug("Notification from other instance (PID=0x%X) received!", pid);
        
        FLASHWINFO flashWinInfo;
        memset(&flashWinInfo, 0, sizeof(FLASHWINFO));