/** * Runs the eventloop until `cancel()` is called. This function blocks. */ void run() { { std::lock_guard<std::mutex> lock(m_data_lock); if (m_state != State::Cancelling) { m_state = State::Idle; } else { return; } } if (m_prepare) { // NOLINT m_prepare(); } while (true) { // NOLINT if (process() == false) { m_state = State::Canceled; return; } if (m_idle) { m_idle(); } { // we don't care about spurious wakeups... std::unique_lock<std::mutex> lock(m_data_lock); if (!m_buffer.empty() || !m_invokes.empty()) { continue; } if (m_tick_ms != 0) { m_cv.wait_for(lock, std::chrono::milliseconds(m_tick_ms)); } else { m_cv.wait(lock); } } } }
/*===========================================================================* * m_do_close * *===========================================================================*/ static int m_do_close(message *m_ptr) { /* Close a memory character device. */ if (m_prepare(m_ptr->DEVICE) == NULL) return(ENXIO); if(openct[m_device] < 1) { printf("MEMORY: closing unopened device %d\n", m_device); return(EINVAL); } openct[m_device]--; return(OK); }
/*===========================================================================* * m_do_open * *===========================================================================*/ static int m_do_open(message *m_ptr) { /* Open a memory character device. */ int r; /* Check device number on open. */ if (m_prepare(m_ptr->DEVICE) == NULL) return(ENXIO); if (m_device == MEM_DEV) { r = sys_enable_iop(m_ptr->USER_ENDPT); if (r != OK) { printf("m_do_open: sys_enable_iop failed for %d: %d\n", m_ptr->USER_ENDPT, r); return r; } } openct[m_device]++; return(OK); }