File: C:/Redmine-4.x/redmine-4.2.9/files/160203114914_VPIScheduler.cpp.patch
--- OpenOpcUaCoreServer/source/VPIScheduler.cpp
+++ OpenOpcUaCoreServer/source/VPIScheduler.cpp
@@ -114,6 +114,7 @@
//m_pVpiDevices->clear();
// Scheduler variable and thread init
OpcUa_Semaphore_Create(&m_hStopSchedulerThread,0,0x100);
+ OpcUa_Semaphore_Create(&m_hSchedulerThreadFinished,0,1);
OpcUa_Semaphore_Create(&m_hVpiReaderInitialized, 0, 1);
OpcUa_Semaphore_Create(&m_hVpiWriterInitialized, 0, 1);
StartVpiReaderThread();
@@ -132,6 +133,7 @@
m_uiSamplingInterval=1000; // default value for the polling interval (1000)
m_hSchedulerThread=NULL;
OpcUa_Semaphore_Create(&m_hStopSchedulerThread, 0, 0x100);
+ OpcUa_Semaphore_Create(&m_hSchedulerThreadFinished,0,1);
OpcUa_Semaphore_Create(&m_hVpiReaderInitialized, 0, 1);
OpcUa_Semaphore_Create(&m_hVpiWriterInitialized, 0, 1);
StartVpiReaderThread();
@@ -156,6 +158,7 @@
//}
//delete m_pVpiDevices;
OpcUa_Semaphore_Delete(&m_hStopSchedulerThread);
+ OpcUa_Semaphore_Delete(&m_hSchedulerThreadFinished);
OpcUa_Semaphore_Delete(&m_hVpiReaderInitialized);
OpcUa_Semaphore_Delete(&m_hVpiWriterInitialized);
OpcUa_Mutex_Delete(&m_VpiWriteObjectsMutex);
@@ -390,14 +393,19 @@
}
}
}
- OpcUa_Semaphore_Post(pVPIScheduler->m_hStopSchedulerThread,1);
+
+ OpcUa_Semaphore_Post(pVPIScheduler->m_hSchedulerThreadFinished,1);
}
OpcUa_StatusCode CVPIScheduler::StopVpiReaderThread()
{
OpcUa_Mutex_Lock(m_VpiReaderThreadMutex);
m_bRunSchedulerThread=OpcUa_False;
OpcUa_Semaphore_Post(m_hStopSchedulerThread,1);
- OpcUa_StatusCode uStatus = OpcUa_Semaphore_TimedWait( m_hStopSchedulerThread,OPC_TIMEOUT*2); // 15 secondes max.
+ OpcUa_Mutex_Unlock(&m_VpiReaderThreadMutex);
+
+ OpcUa_StatusCode uStatus = OpcUa_Semaphore_TimedWait( m_hSchedulerThreadFinished,OPC_TIMEOUT*2); // 15 secondes max.
+
+ OpcUa_Mutex_Lock(m_VpiReaderThreadMutex);
if (uStatus == OpcUa_GoodNonCriticalTimeout)
{
// on force la fin du thread de simulation