Selaa lähdekoodia

修正共享内存会保留最后一帧message的bug

sunjiacheng 2 vuotta sitten
vanhempi
commit
37bcea3762
1 muutettua tiedostoa jossa 131 lisäystä ja 0 poistoa
  1. 131 0
      src/common/modulecomm/shm/procsm_if.cpp

+ 131 - 0
src/common/modulecomm/shm/procsm_if.cpp

@@ -75,6 +75,8 @@ void procsm_if_readthread::continueread()
     mbRun = true;
 }
 
+
+#if 0
 void procsm_if_readthread::run()
 {
 #ifdef USELCM
@@ -194,7 +196,136 @@ void procsm_if_readthread::run()
     delete pdt;
 //    qDebug("Thread finish.");
 }
+#else
+
+void procsm_if_readthread::run()
+{
+#ifdef USELCM
+    mlcm.subscribe(mstrsmname,&procsm_if_readthread::handlerMethod,this);
+    while(!QThread::isInterruptionRequested())
+    {
+        mlcm.handle();
+    }
+    return;
+#endif
+    QTime xTime;
+    xTime.start();
+    unsigned int nBufLen = 1;
+    unsigned int nRead;
+    char * str = new char[nBufLen];
+    unsigned int index =0;
+
+
+
+
+    QDateTime *pdt = new QDateTime();
+
+
+    bool bAttach = false;
+    bool bFirstRead = true; //if First Read,not read the buffer data.
+    while(!QThread::isInterruptionRequested())
+    {
+        if(mbRun == false)
+        {
+            msleep(10);
+            continue;
+        }
+        if(bAttach == false)
+        {
+            bAttach = mpPSM->AttachMem();
+            if(bAttach == false)
+            {
+                msleep(100);
+                continue;
+            }
+            else
+            {
+                index = mpPSM->getcurrentnext();
+            }
+        }
+
 
+        int nRtn = mpPSM->readmsg(index,str,nBufLen,&nRead,pdt);
+        if(nRtn == 0)
+        {
+#ifndef USE_GROUPUDP
+#ifdef USEDBUS
+            if(mbDBUSOK == true)
+            {
+                mWaitMutex.lock();
+                mwc.wait(&mWaitMutex,10);
+                mWaitMutex.unlock();
+            }
+            else
+            {
+                msleep(1);
+            }
+#else
+            msleep(1);
+#endif
+#else
+            procsm_if * mpif = (procsm_if * )mpparent;
+            if(mpif->WaitNotify()<0)
+            {
+                std::cout<<"Wait Notify Error. Please Check. "<<std::endl;
+                std::this_thread::sleep_for(std::chrono::milliseconds(10));
+            }
+//            mWaitMutex.lock();
+//            mwc.wait(&mWaitMutex,100);
+//            mWaitMutex.unlock();
+#endif
+        }
+        else
+        {
+            if(nRtn == -1)
+            {
+                nBufLen = nRead;
+                delete str;
+                if(nBufLen < 1)nBufLen = 1;
+                str = new char[nBufLen];
+  //              std::cout<<"modulecomm resize str to "<<nBufLen<<std::endl;
+            }
+            else
+            {
+                if((nRtn == -2) ||(nRtn == -100)||(nRtn == -101))
+                {
+                   index = mpPSM->getcurrentnext();
+                   if(nRtn == -100)  //Because New ShareMemory, read this.
+                   {
+                       if((index > 0)&&(bFirstRead == false) )index = index -1;
+                   }
+                }
+                else
+                {
+                   if(nRtn >0)
+                   {
+                       if(mbFunPlus)
+                       {
+                           mFun(str,nRtn,index,pdt,mstrsmname);
+                       }
+                       else
+                       {
+                          (*mpCall)(str,nRtn,index,pdt,mstrsmname);
+                       }
+                       index++;
+                   }
+                   else
+                   {
+                       usleep(100);
+                   }
+                }
+            }
+        }
+        bFirstRead = false;
+
+
+    }
+    delete str;
+    delete pdt;
+//    qDebug("Thread finish.");
+}
+
+#endif
 
 #ifdef USE_GROUPUDP
     void procsm_if_readthread::WakeRead()