bool io_thread::pump_messages() { bool didWork = false; while (have_messages()) { if (halted()) return didWork; if (have_message_queue()) { message_queue().get_message(); message_queue().idle(); } didWork = true; } return didWork; }
Error usi_queue_message(USIMessage *message) { CheckB(message->write_count + message->read_count > 0); /* * If there are any bytes to write, then place them directly into the registers. The first * byte of the message is used as the initial offset location to write to in the registers. */ if (message->write_count) { uint8 offset = message->buffer[0]; uint8 count = (message->write_count < (USI_REGISERS - offset) ? message->write_count : (USI_REGISERS - offset)); CheckB(offset < USI_REGISERS); message->message.state = message_state_writing; for (uint8 i = 0; i < count; ++i) _usi.registers[i + offset] = message->buffer[i + 1]; } /* * If there are any bytes to be read, then queue the message up so that the interupt handler * will fill it with bytes that come from the master. */ if (message->read_count) message_queue(&(message->message), &(_usi.device)); else message->message.state = message_state_success; return success; }
bool io_thread::process_events() { bool didWork = false; while (have_messages()) { message_queue().get_message(); didWork = true; } if (iEventProcessor) didWork = iEventProcessor() || didWork; return didWork; }
bool io_thread::do_io(bool aYieldIfNoWork) { if (iHalted) return false; bool didSome = false; didSome = (iTimerIoService.do_io(false) || didSome); didSome = (iNetworkingIoService.do_io(false) || didSome); didSome = (process_events() || didSome); if (!didSome && aYieldIfNoWork) { if (have_message_queue()) message_queue().idle(); sleep(1); } return didSome; }
bool io_thread::have_messages() const { return have_message_queue() && message_queue().have_message(); }