/** Signal that an input device event is being waited for. * @param _device Device to wait for. * @param data Handle-specific data pointer (unused). * @param event Event to wait for. * @param sync Synchronisation pointer. * @return Status code describing result of the operation. */ static status_t input_device_wait(device_t *_device, void *data, int event, void *sync) { input_device_t *device = _device->data; switch(event) { case DEVICE_EVENT_READABLE: if(semaphore_count(&device->sem)) { object_wait_signal(sync); } else { notifier_register(&device->data_notifier, object_wait_notifier, sync); } return STATUS_SUCCESS; default: return STATUS_INVALID_EVENT; } }
void encoder::add_plain_packet(const uint8_t *data, const uint16_t len) { uint8_t *buf; size_t size = this->symbol_size(); CHECK_LE(len, size - LEN_SIZE) << "Encoder " << m_coder << ": Plain packet is too long: " << len << " > " << size - LEN_SIZE; guard g(m_lock); /* make sure encoder is in a state to accept plain packets */ if (curr_state() != STATE_WAIT) return; buf = get_symbol_buffer(m_plain_pkt_count); *reinterpret_cast<uint16_t *>(buf) = len; memcpy(buf + LEN_SIZE, data, len); /* Copy data into encoder storage */ sak::mutable_storage symbol(buf, this->symbol_size()); this->set_symbol(m_plain_pkt_count++, symbol); update_timestamp(); inc("plain packets added"); VLOG(LOG_PKT) << "Encoder " << m_coder << ": Added plain packet"; if (is_full()) { inc("generations"); dispatch_event(EVENT_FULL); } else if (this->rank() > FLAGS_encoder_threshold*this->symbols() && semaphore_count() > 0) { m_budget += recoder_credit(m_e1, m_e2, m_e3); send_encoded_credit(); } }