Example #1
0
  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);
    }
  }
Example #2
0
  bool Fill(TimeoutClock &timeout) {
    const auto dest = buffer.Write();
    if (dest.IsEmpty())
      /* already full */
      return false;

    const Port::WaitResult wresult =
      port.WaitRead(env, timeout.GetRemainingOrZero());
    if (wresult != Port::WaitResult::READY)
      return false;

    const int nbytes = port.Read(dest.data, dest.length);
    if (nbytes <= 0)
      return false;

    buffer.Append(nbytes);
    return true;
  }
Example #3
0
  const_iterator Wait(std::unique_lock<Mutex> &lock,
                      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();

      const auto remaining = timeout.GetRemainingSigned();
      if (remaining.count() <= 0)
        return end();

      cond.wait_for(lock, remaining);
    }
  }