bool KRT2Device::Send(const uint8_t *msg, unsigned msg_size, OperationEnvironment &env) { //! Number of tries to send a message unsigned retries = NR_RETRIES; assert(msg_size > 0); do { response_mutex.Lock(); response = NO_RSP; response_mutex.Unlock(); // Send the message if (!port.FullWrite(msg, msg_size, env, CMD_TIMEOUT)) return false; // Wait for the response response_mutex.Lock(); rx_cond.timed_wait(response_mutex, CMD_TIMEOUT); auto _response = response; response_mutex.Unlock(); if (_response == ACK) // ACK received, finish return true; // No ACK received, retry retries--; } while (retries); return false; }
const_iterator Wait(const K &key, OperationEnvironment &env, TimeoutClock timeout) { while (true) { auto i = map.find(key); if (i != map.end() && !i->second.old) return const_iterator(i); if (env.IsCancelled()) return end(); int remaining = timeout.GetRemainingSigned(); if (remaining <= 0) return end(); cond.timed_wait(*this, remaining); } }
bool CondTime::wait(Mutex& mutex, Cond& cond) { return cond.timed_wait(mutex,timepoint); }