make connecting channel wait loop more flexible

This commit is contained in:
Dennis Klein 2017-04-13 12:51:35 +02:00 committed by Mohammad Al-Turany
parent ee0d2e0c55
commit f963a06e25

View File

@ -227,20 +227,20 @@ void FairMQDevice::InitWrapper()
// go over the list of channels until all are initialized (and removed from the uninitialized list) // go over the list of channels until all are initialized (and removed from the uninitialized list)
int numAttempts = 0; int numAttempts = 0;
auto sleepTimeInMS = 50;
auto maxAttempts = fInitializationTimeoutInS * 1000 / sleepTimeInMS;
while (!uninitializedConnectingChannels.empty()) while (!uninitializedConnectingChannels.empty())
{ {
AttachChannels(uninitializedConnectingChannels); AttachChannels(uninitializedConnectingChannels);
if (++numAttempts > fInitializationTimeoutInS) if (numAttempts > maxAttempts)
{ {
LOG(ERROR) << "could not connect all channels after " << fInitializationTimeoutInS << " attempts"; LOG(ERROR) << "could not connect all channels after " << fInitializationTimeoutInS << " attempts";
// TODO: goto ERROR state; // TODO: goto ERROR state;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (numAttempts != 0) this_thread::sleep_for(chrono::milliseconds(sleepTimeInMS));
{ numAttempts++;
this_thread::sleep_for(chrono::milliseconds(1000));
}
} }
Init(); Init();