|
@@ -1,5 +1,8 @@
|
|
|
#include "mainwindow.h"
|
|
|
#include <QApplication>
|
|
|
+#include <QSharedMemory>
|
|
|
+#include <QMessageBox>
|
|
|
+
|
|
|
#include <string>
|
|
|
#include "ivlog.h"
|
|
|
|
|
@@ -11,10 +14,83 @@ std::string locateInfoPath;
|
|
|
iv::Ivlog * ivlog;
|
|
|
iv::Ivfault * ivfault;
|
|
|
|
|
|
+#define USE_ONEIVSYSMAN
|
|
|
+
|
|
|
+
|
|
|
+extern bool gbOneThreadRunning ;
|
|
|
+extern bool gbOneThreadRun ;
|
|
|
+void threadOne(QSharedMemory * pshare,int ncount)
|
|
|
+{
|
|
|
+ while(gbOneThreadRun)
|
|
|
+ {
|
|
|
+ pshare->lock();
|
|
|
+ int * pdata = (int *)pshare->data();
|
|
|
+ if(*pdata != ncount)
|
|
|
+ {
|
|
|
+ *pdata = ncount;
|
|
|
+ qDebug("another thread want running.");
|
|
|
+ }
|
|
|
+ pshare->unlock();
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
+ }
|
|
|
+
|
|
|
+ gbOneThreadRunning = false;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
int main(int argc, char *argv[])
|
|
|
{
|
|
|
QApplication a(argc, argv);
|
|
|
|
|
|
+#ifdef USE_ONEIVSYSMAN
|
|
|
+
|
|
|
+ QSharedMemory shareMem("IVSysMan_Count");
|
|
|
+
|
|
|
+ int ncount = 0;
|
|
|
+ bool bHaveAnother = false;
|
|
|
+ if(shareMem.attach())
|
|
|
+ {
|
|
|
+ shareMem.lock();
|
|
|
+ int * pdata = (int *)shareMem.data();
|
|
|
+ ncount = (*pdata)+1;
|
|
|
+ qDebug("now IVSysMan_Count is %d",ncount);
|
|
|
+ *pdata = ncount;
|
|
|
+ shareMem.unlock();
|
|
|
+
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
+ shareMem.lock();
|
|
|
+ pdata = (int *)shareMem.data();
|
|
|
+ if(*pdata != ncount)
|
|
|
+ {
|
|
|
+ qDebug("Another IVSysMan Running");
|
|
|
+ bHaveAnother = true;
|
|
|
+ }
|
|
|
+ *pdata = ncount;
|
|
|
+ shareMem.unlock();
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ shareMem.create(100);
|
|
|
+ shareMem.lock();
|
|
|
+ int * pdata = (int *)shareMem.data();
|
|
|
+ *pdata = 1;
|
|
|
+ qDebug("now IVSysMan_Count is %d",*pdata);
|
|
|
+ shareMem.unlock();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(bHaveAnother == true)
|
|
|
+ {
|
|
|
+ QMessageBox::warning(NULL,"Warning","Another IVSysMan Running.",QMessageBox::YesAll);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ void * ponethread = new std::thread(threadOne,&shareMem,ncount);
|
|
|
+ (void *)ponethread;
|
|
|
+
|
|
|
+
|
|
|
+#endif
|
|
|
+
|
|
|
RegisterIVBackTrace();
|
|
|
|
|
|
ivlog = new iv::Ivlog("IVSysMan");
|