Ejemplo n.º 1
0
  void StartThreads(Function wait) {
    m_watcher1 = std::thread(wait, std::ref(m_done1));
    m_watcher2 = std::thread(wait, std::ref(m_done2));

    // Wait briefly to let the lock be unlocked.
    ShortSleep();
    bool locked = m_mutex.try_lock();
    if (locked) m_mutex.unlock();
    EXPECT_TRUE(locked)
        << "The condition variable failed to unlock the lock.";
  }
Ejemplo n.º 2
0
void updateNotifierAlarm(void* notifier_pointer, uint64_t triggerTime, int32_t *status)
{
	std::lock_guard<priority_recursive_mutex> sync(notifierMutex);

	Notifier* notifier = (Notifier*)notifier_pointer;
	notifier->triggerTime = triggerTime;
	bool wasActive = (closestTrigger != UINT64_MAX);

	if (!notifierInterruptMutex.try_lock() || notifierRefCount == 0 ||
			!notifierAlarm)
		return;

	// Update alarm time if closer than current.
	if (triggerTime < closestTrigger) {
		closestTrigger = triggerTime;
		// Simply truncate the hardware trigger time to 32-bit.
		notifierAlarm->writeTriggerTime((uint32_t)triggerTime, status);
	}
	// Enable the alarm.  The hardware disables itself after each alarm.
	if (!wasActive) notifierAlarm->writeEnable(true, status);

	notifierInterruptMutex.unlock();
}
Ejemplo n.º 3
0
// internal version of updateAlarm used during the alarmCallback when we know
// that the pointer is a valid pointer.
void updateNotifierAlarmInternal(std::shared_ptr<Notifier> notifierPointer,
                                 uint64_t triggerTime, int32_t* status) {
  std::lock_guard<priority_recursive_mutex> sync(notifierMutex);

  auto notifier = notifierPointer;
  // no need for a null check, as this must always be a valid pointer.
  notifier->triggerTime = triggerTime;
  bool wasActive = (closestTrigger != UINT64_MAX);

  if (!notifierInterruptMutex.try_lock() || notifierRefCount == 0 ||
      !notifierAlarm)
    return;

  // Update alarm time if closer than current.
  if (triggerTime < closestTrigger) {
    closestTrigger = triggerTime;
    // Simply truncate the hardware trigger time to 32-bit.
    notifierAlarm->writeTriggerTime(static_cast<uint32_t>(triggerTime), status);
  }
  // Enable the alarm.  The hardware disables itself after each alarm.
  if (!wasActive) notifierAlarm->writeEnable(true, status);

  notifierInterruptMutex.unlock();
}