/**
 * Check that a callback from the SelectServer thread executes.
 */
void SelectServerThreadTest::testSameThreadCallback() {
  TestThread test_thread(&m_ss, ola::thread::Thread::Self());
  m_ss.Execute(
      ola::NewSingleCallback(&test_thread, &TestThread::TestCallback));
  OLA_ASSERT_FALSE(test_thread.CallbackRun());
  m_ss.Run();
  OLA_ASSERT_TRUE(test_thread.CallbackRun());
}
Exemplo n.º 2
0
/**
 * Called by the receive thread when new data arrives
 * @param device the device id which produced the data
 * @param data pointer to the data, ownership is transferred, use
 *   DeleteU8ArrayPtr to free.
 * @param data_length the size of the data
 */
void LogicReader::DataReceived(U64 device, U8 *data, uint32_t data_length) {
  {
    MutexLocker lock(&m_mu);
    if (device != m_device_id) {
      DevicesManagerInterface::DeleteU8ArrayPtr(data);
      return;
    }
  }
  m_ss->Execute(
      NewSingleCallback(this, &LogicReader::ProcessData, data, data_length));

  {
    MutexLocker lock(&m_data_mu);
    while (!m_free_data.empty()) {
      U8 *data = m_free_data.front();
      DevicesManagerInterface::DeleteU8ArrayPtr(data);
      m_free_data.pop();
    }
  }
}
Exemplo n.º 3
0
/*
 * Check that RemoveWriteDescriptor is reentrant.
 * We use the Execute() method to close a write descriptor during the same
 * cycle in which it becomes writeable. See
 * https://github.com/OpenLightingProject/ola/pull/429 for details.
 */
void SelectServerTest::testRemoveWriteWhenOtherReadable() {
  Descriptors read_set, write_set, delete_set;
  LoopbackDescriptor *loopback = new LoopbackDescriptor();
  loopback->Init();
  loopback->SetOnWritable(NewCallback(this, &SelectServerTest::NullHandler));

  write_set.insert(loopback);
  delete_set.insert(loopback);

  OLA_ASSERT_TRUE(m_ss->AddWriteDescriptor(loopback));
  OLA_ASSERT_EQ(1, write_descriptor_count->Get());
  OLA_ASSERT_EQ(0, read_descriptor_count->Get());
  m_ss->Execute(NewSingleCallback(
      this, &SelectServerTest::RemoveAndDeleteDescriptors,
      read_set, write_set, delete_set));

  m_ss->Run();
  OLA_ASSERT_EQ(0, write_descriptor_count->Get());
  OLA_ASSERT_EQ(1, connected_read_descriptor_count->Get());
  OLA_ASSERT_EQ(0, read_descriptor_count->Get());
}