Commit 7362146b authored by Jussi Lindgren's avatar Jussi Lindgren

Server: Miscellaneous small changes

- AcquisitionServer_StartedDriverSleepDuration parameter is now
  interpreted as follows: <0 == busy wait, 0 == yield, >0 == ms to sleep.
- GUI status is no longer updated more frequently than once per 0.5sec
- Fixed centering of the status lines in the GUI
- Minor code cleanup
parent a24a7383
......@@ -444,11 +444,9 @@
<property name="n_columns">2</property>
<child>
<object class="GtkLabel" id="label_status">
<property name="width_request">128</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="justify">center</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="right_attach">2</property>
......@@ -456,11 +454,9 @@
</child>
<child>
<object class="GtkLabel" id="label_connected_host_count">
<property name="width_request">128</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="justify">center</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="right_attach">2</property>
......
......@@ -311,7 +311,7 @@ CAcquisitionServer::CAcquisitionServer(const IKernelContext& rKernelContext)
this->setImpedanceCheckRequest(m_rKernelContext.getConfigurationManager().expandAsBoolean("${AcquisitionServer_CheckImpedance}", false));
this->setChannelSelectionRequest(m_rKernelContext.getConfigurationManager().expandAsBoolean("${AcquisitionServer_ChannelSelection}", false));
m_ui64StartedDriverSleepDuration=m_rKernelContext.getConfigurationManager().expandAsUInteger("${AcquisitionServer_StartedDriverSleepDuration}", 0);
m_i64StartedDriverSleepDuration= m_rKernelContext.getConfigurationManager().expandAsInteger("${AcquisitionServer_StartedDriverSleepDuration}", 0);
m_ui64StoppedDriverSleepDuration=m_rKernelContext.getConfigurationManager().expandAsUInteger("${AcquisitionServer_StoppedDriverSleepDuration}", 100);
m_ui64DriverTimeoutDuration=m_rKernelContext.getConfigurationManager().expandAsUInteger("${AcquisitionServer_DriverTimeoutDuration}", 5000);
......@@ -401,14 +401,12 @@ boolean CAcquisitionServer::loop(void)
{
// m_rKernelContext.getLogManager() << LogLevel_Debug << "idleCB\n";
list < pair < Socket::IConnection*, SConnectionInfo > >::iterator itConnection;
// Searches for new connection(s)
if(m_pConnectionServer)
{
DoubleLock lock(&m_oPendingConnectionProtectionMutex, &m_oPendingConnectionExecutionMutex);
for(itConnection=m_vPendingConnection.begin(); itConnection!=m_vPendingConnection.end(); itConnection++)
for(auto itConnection=m_vPendingConnection.begin(); itConnection!=m_vPendingConnection.end(); itConnection++)
{
m_rKernelContext.getLogManager() << LogLevel_Info << "Received new connection...\n";
......@@ -474,7 +472,7 @@ boolean CAcquisitionServer::loop(void)
}
// Cleans disconnected client(s)
for(itConnection=m_vConnection.begin(); itConnection!=m_vConnection.end(); )
for(auto itConnection=m_vConnection.begin(); itConnection!=m_vConnection.end(); )
{
Socket::IConnection* l_pConnection=itConnection->first;
if(!l_pConnection->isConnected())
......@@ -514,8 +512,26 @@ boolean CAcquisitionServer::loop(void)
l_bResult=m_pDriver->loop();
if(!m_bGotData)
{
System::Time::sleep((uint32)m_ui64StartedDriverSleepDuration);
l_bTimeout=(System::Time::getTime()>l_ui32TimeBeforeCall+m_ui64DriverTimeoutDuration);
if(m_i64StartedDriverSleepDuration>0)
{
// This may cause jitter due to inaccuracies in sleep duration, but has the
// benefit that it frees the CPU core for other tasks
System::Time::sleep( static_cast<uint32_t>(m_i64StartedDriverSleepDuration) );
}
else if(m_i64StartedDriverSleepDuration==0)
{
// Generally spins, but gives other threads a chance. Note that there is no guarantee when
// the scheduler reschedules this thread.
std::this_thread::yield();
}
else
{
// < 0 -> NOP, spins, doesn't offer to yield
// n.b. Unless the driver waits for samples (preferably with a hardware event),
// this choice will spin one core fully.
}
}
}
if(l_bTimeout)
......@@ -565,7 +581,7 @@ boolean CAcquisitionServer::loop(void)
}
// Handle connections
for(itConnection=m_vConnection.begin(); itConnection!=m_vConnection.end(); itConnection++)
for(auto itConnection=m_vConnection.begin(); itConnection!=m_vConnection.end(); itConnection++)
{
// Socket::IConnection* l_pConnection=itConnection->first;
SConnectionInfo& l_rInfo=itConnection->second;
......@@ -753,7 +769,7 @@ boolean CAcquisitionServer::connect(IDriver& rDriver, IHeader& rHeaderCopy, uint
m_rKernelContext.getLogManager() << LogLevel_Trace << "Oversampling factor set to " << m_ui64OverSamplingFactor << "\n";
m_rKernelContext.getLogManager() << LogLevel_Trace << "Sampling frequency set to " << m_ui32SamplingFrequency << "Hz\n";
m_rKernelContext.getLogManager() << LogLevel_Trace << "Started driver sleeping duration is " << m_ui64StartedDriverSleepDuration << " milliseconds\n";
m_rKernelContext.getLogManager() << LogLevel_Trace << "Started driver sleeping duration is " << m_i64StartedDriverSleepDuration << " milliseconds\n";
m_rKernelContext.getLogManager() << LogLevel_Trace << "Stopped driver sleeping duration is " << m_ui64StoppedDriverSleepDuration << " milliseconds\n";
m_rKernelContext.getLogManager() << LogLevel_Trace << "Driver timeout duration set to " << m_ui64DriverTimeoutDuration << " milliseconds\n";
......
......@@ -111,7 +111,7 @@ namespace OpenViBEAcquisitionServer
protected:
bool CAcquisitionServer::requestClientThreadQuit(CConnectionClientHandlerThread* th);
bool requestClientThreadQuit(CConnectionClientHandlerThread* th);
public:
......@@ -175,9 +175,9 @@ namespace OpenViBEAcquisitionServer
CDriftCorrection m_oDriftCorrection;
OpenViBE::uint64 m_ui64JitterEstimationCountForDrift;
OpenViBE::uint64 m_ui64DriverTimeoutDuration;
OpenViBE::uint64 m_ui64StartedDriverSleepDuration;
OpenViBE::uint64 m_ui64StoppedDriverSleepDuration;
OpenViBE::uint64 m_ui64DriverTimeoutDuration; // ms after which the driver is considered having time-outed
OpenViBE::int64 m_i64StartedDriverSleepDuration; // ms, <0 == spin, 0 == yield thread, >0 sleep. Used when driver does not return samples.
OpenViBE::uint64 m_ui64StoppedDriverSleepDuration; // ms to sleep when driver is not running
OpenViBE::uint8* m_pSampleBuffer;
OpenViBE::CStimulationSet m_oPendingStimulationSet;
......
......@@ -40,6 +40,8 @@ namespace OpenViBEAcquisitionServer
void main(void)
{
OpenViBE::boolean l_bFinished = false;
OpenViBE::uint64 l_ui64LastGUIUpdate = 0;
while (!l_bFinished)
{
OpenViBE::boolean l_bShouldSleep = false;
......@@ -86,11 +88,15 @@ namespace OpenViBEAcquisitionServer
}
if (!l_bFinished)
{
{
const OpenViBE::uint64 l_ui64TimeNow = System::Time::zgetTime();
// Update the GUI if the variables have changed. In order to avoid
// gdk_threads_enter()/gdk_threads_exit() calls that may not work on all
// backends (esp. Windows), delegate the work to g_idle_add() functions.
// As a result, we need to protect access to the variables that the callbacks use
// As a result, we need to protect access to the variables that the callbacks use;
// this protection is done inside the callbacks.
if(l_ui64TimeNow - l_ui64LastGUIUpdate > (1LL<<32)/2LL ) // update at most every 0.5sec to avoid hammering the gui
{
if (m_ui32LastStatus != m_ui32Status || l_ui32ClientCount != m_ui32ClientCount)
{
......@@ -118,7 +124,7 @@ namespace OpenViBEAcquisitionServer
gdk_threads_add_idle(idle_updatedisconnect_cb, (void *)this);
}
l_ui64LastGUIUpdate = l_ui64TimeNow;
}
if (l_bShouldSleep)
......@@ -257,7 +263,7 @@ namespace OpenViBEAcquisitionServer
l_sState = "Receiving and sending...";
}
char l_sLabel[1024];
::sprintf(l_sLabel, "%u client%s connected...", (unsigned int)m_ui32ClientCount, (m_ui32ClientCount!=1 ? "s" : ""));
::sprintf(l_sLabel, "%u client%s connected", (unsigned int)m_ui32ClientCount, (m_ui32ClientCount!=1 ? "s" : ""));
l_sClientText = l_sLabel;
break;
case Status_Idle:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment