Skip to content

Commit

Permalink
FileDescriptorActivity: fix unit test failure related to almost concu…
Browse files Browse the repository at this point in the history
…rrent removal of watched fd and write

Signed-off-by: Johannes Meyer <johannes@intermodalics.eu>
  • Loading branch information
meyerj committed Oct 24, 2019
1 parent 03e8b76 commit 96eced7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
30 changes: 26 additions & 4 deletions rtt/extras/FileDescriptorActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,36 @@ void FileDescriptorActivity::loop()
oro_atomic_set(&m_trigger, 0);
do_trigger = true;
}
if (oro_atomic_read(&m_update_sets) > 0) {
oro_atomic_set(&m_update_sets, 0);

// Check if file descriptors that have work also have been removed in the current cycle and
// already ignore them. This is a corner case and still triggering an IOReady event would
// probably be fine in real-world applications, but it can break the task-test unit test
// depending on timing.
//
// The simple solution would be to continue without triggering the component, but we might miss
// triggers or activities on other file descriptors then.
//
// Disabled for now and patched in the unit test.
//
// { RTT::os::MutexLock lock(m_fd_lock);
// fd_set copy;
// FD_ZERO(&copy);
// m_has_ioready = false;
// for(int i = 0; i <= max_fd; ++i) {
// if (FD_ISSET(i, &m_fd_set) && FD_ISSET(i, &m_fd_work)) {
// FD_SET(i, &copy);
// m_has_ioready = true;
// }
// }
// m_fd_work = copy;
// }
}
if (oro_atomic_read(&m_break_loop) > 0) {
oro_atomic_set(&m_break_loop, 0);
break;
}
if (oro_atomic_read(&m_update_sets) > 0) {
oro_atomic_set(&m_update_sets, 0);
continue;
}

// Execute activity...
if (m_has_timeout || m_has_ioready || do_trigger)
Expand Down
3 changes: 3 additions & 0 deletions tests/taskthread_fd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ BOOST_AUTO_TEST_CASE(testFileDescriptor_Write )
mtask->unwatch(mcomp.fd[0]);
BOOST_CHECK( mtask->isWatched(mcomp.fd[0]) == false );

// sleep to give the FileDescriptorActivity some time to update the internal file descriptor set
usleep(100000/10);

++ch;
rc = write(mcomp.fd[1], &ch, sizeof(ch));
if (1 != rc) std::cerr << "rc=" << rc << " errno=" << errno << ":" << strerror(errno) << std::endl;
Expand Down

0 comments on commit 96eced7

Please # to comment.