jint ByteChannel::read(jobject destination) { const ByteBuffer::ClassImpl& bufimpl = ByteBuffer::impl(m_env); const jint remaining = get_remaining(m_env, destination, bufimpl.m_mid_get_remaining); if (!remaining) { // No space in the buffer; don't try to read anything. return 0; } const jint position = get_position(m_env, destination, bufimpl.m_mid_get_position); jint bytes_read = 0; void* data = m_env.GetDirectBufferAddress(destination); if (data) { data = static_cast<char*>(data) + position; bytes_read = m_reader(m_env, data, remaining); } else { // It was not a direct buffer ... see if it has an array. jbyteArray raw_array = get_array(m_env, destination, bufimpl.m_mid_has_array, bufimpl.m_mid_get_array); if (raw_array) { const jint array_offset = get_array_offset( m_env, destination, bufimpl.m_mid_get_array_offset); ByteArray array(m_env, raw_array); ByteArray::MutableContents contents(array); data = contents.data(); data = static_cast<char*>(data) + position + array_offset; bytes_read = m_reader(m_env, data, remaining); } } if (data) { if (bytes_read > 0) set_position(m_env, destination, bufimpl.m_mid_set_position, position + bytes_read); return bytes_read; } // No accessible array, either. Oh well. Create a byte array and // push it into the buffer. ByteArray array(m_env, remaining); ByteArray::MutableContents contents(array); bytes_read = m_reader(m_env, contents.data(), contents.length()); if (bytes_read > 0) put_bytearray(m_env, destination, bufimpl.m_mid_put_bytearray, array, bytes_read); return bytes_read; }
void core::run() { std::thread accept_thread(std::bind(&core::accept, this)); std::thread render_thread(std::bind(&core::render_impl, this)); try { while(m_running) { while(generic_pool_t::global().poll()) ; m_reader(m_workers); m_pinger(m_workers); m_stat_collector(m_workers); render(); std::this_thread::sleep_for(std::chrono::milliseconds(100)); } } catch(std::exception const &e) { log_system("core exception: %%", e.what()); m_running = false; /* Wake up the render thread. */ render(); accept_thread.detach(); render_thread.join(); } /* TODO: shared::thread for more RAII. */ if(accept_thread.joinable()) { accept_thread.detach(); } if(render_thread.joinable()) { render_thread.join(); } }
void require( const std::size_t amount ) { if( m_current.data + amount <= m_end ) { return; } if( m_current.data + amount > m_buffer.get() + m_maximum ) { throw std::overflow_error( "require beyond end of buffer" ); } if( const auto r = m_reader( m_end, ( std::min )( buffer_free_after_end(), ( std::max )( amount, Chunk ) ) ) ) { m_end += r; } }
double GPxiBasicAnalogInput::UpdateFromPhysicalInput() { try { // Create a writer CNiDAQmxAnalogSingleChannelReader m_reader(Stream); // And write immediately m_Value = m_reader.ReadSingleSample(); // // Wait until the I/O completes before destroying the task // WaitUntilDone(-1); emit MeasuredValueChanged(m_Value); } catch (CNiDAQmxException *exception) { exception->ReportError(); exception->Delete(); // return false; } return m_Value; }