示例#1
0
 /**
  * Wakes up the thread to do work, calls tick().
  */
 void Trigger() {
   const ScopeLock lock(mutex);
   if (!trigger_flag) {
     trigger_flag = true;
     trigger_cond.signal();
   }
 }
void PendingChecks::runChecks()
{
    DynMutex::Guard guard = m_mutex.lock();
    Checks::iterator it = m_checks.begin();
    bool removed = false;
    while (it != m_checks.end()) {
        bool cont;
        try {
            cont = (**it)();
        } catch (...) {
            Exception::handle(HANDLE_EXCEPTION_FATAL);
            // keep compiler happy
            cont = false;
        }

        if (!cont) {
            // Done with this check
            Checks::iterator next = it;
            ++next;
            m_checks.erase(it);
            it = next;
            removed = true;
        } else {
            ++it;
        }
    }
    // Tell blockOnCheck() calls that they may have completed.
    if (removed) {
        m_cond.signal();
    }
}
 void Cancel() {
   const ScopeLock lock(mutex);
   if (!cancel_flag) {
     cancel_flag = true;
     cancel_cond.signal();
   }
 }
    void leave() const
    {
        Lock lock(mutex);

        assert(refcnt > 0);
        assert(pthread_equal(holder, pthread_self()) != 0);

        refcnt--;
        if (refcnt == 0)
        {
            cond.signal();
        }
    }
示例#5
0
  void TriggerDone() {
    assert(mutex.IsLockedByCurrent());

    cond.signal();
  }
示例#6
0
  void TriggerCommand() {
    assert(mutex.IsLockedByCurrent());

    cond.signal();
  }
示例#7
0
 /**
  * Triggers thread shutdown.  Call Thread::Join() after this to wait
  * synchronously for the thread to exit.
  */
 void BeginStop() {
   const ScopeLock lock(mutex);
   SuspensibleThread::_BeginStop();
   trigger_cond.signal();
 }
示例#8
0
 /**
  * Like BeginSuspend(), but expects the mutex to be locked already.
  */
 void _BeginSuspend() {
   SuspensibleThread::_BeginSuspend();
   trigger_cond.signal();
 }
示例#9
0
文件: KRT2.cpp 项目: Andy-1954/XCSoar
bool
KRT2Device::DataReceived(const void *_data, size_t length,
                         struct NMEAInfo &info)
{
  assert(_data != nullptr);
  assert(length > 0);

  const uint8_t *data = (const uint8_t *)_data;
  const uint8_t *end = data + length;

  do {
    // Append new data to the buffer, as much as fits in there
    auto range = rx_buf.Write();
    if (rx_buf.IsFull()) {
      // Overflow: reset buffer to recover quickly
      rx_buf.Clear();
      expected_msg_length = 0;
      continue;
    }
    size_t nbytes = std::min(range.size, size_t(end - data));
    memcpy(range.data, data, nbytes);
    data += nbytes;
    rx_buf.Append(nbytes);

    for (;;) {
      // Read data from buffer to handle the messages
      range = rx_buf.Read();
      if (range.IsEmpty())
        break;

      if (range.size < expected_msg_length)
        break;

      expected_msg_length = ExpectedMsgLength(range.data, range.size);

      if (range.size >= expected_msg_length) {
        switch (*(const uint8_t *) range.data) {
          case ACK:
          case NAK:
            // Received a response to a normal command (STX)
            response_mutex.Lock();
            response = *(const uint8_t *) range.data;
            // Signal the response to the TX thread
            rx_cond.signal();
            response_mutex.Unlock();
            break;
          default:
            // Received a command from the radio -> ignore it
            break;
        }
        // Message handled -> remove message
        rx_buf.Consume(expected_msg_length);
        expected_msg_length = 0;
        // Received something from the radio -> the connection is alive
        info.alive.Update(info.clock);
      }
    }
  } while (data < end);

  return true;
}