Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Commit

Permalink
fix #87 : always check that threads_required set up the appropriate n…
Browse files Browse the repository at this point in the history
…umber of threads---fire off nop functions on unused threads for consistency
  • Loading branch information
danielrh committed Apr 5, 2017
1 parent 665303a commit 82167c1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/lepton/bitops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ bounded_iostream::bounded_iostream(Sirikata::DecoderWriter *w,
this->size_callback = size_callback;
buffer_position = 0;
byte_position = 0;
byte_bound = 0x7FFFFFFF;
num_bytes_attempted_to_write = 0;
set_bound(0);
}
Expand Down Expand Up @@ -384,7 +385,7 @@ void bounded_iostream::close() {
parent->Close();
}

unsigned int bounded_iostream::write_no_buffer(const void *from, size_t bytes_to_write) {
uint32_t bounded_iostream::write_no_buffer(const void *from, size_t bytes_to_write) {
//return iostream::write(from,tpsize,dtsize);
std::pair<unsigned int, Sirikata::JpegError> retval;
if (byte_bound != 0 && byte_position + bytes_to_write > byte_bound) {
Expand Down
8 changes: 4 additions & 4 deletions src/lepton/bitops.hh
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,12 @@ class bounded_iostream
uint8_t buffer[buffer_size];
uint32_t buffer_position;
Sirikata::DecoderWriter *parent;
unsigned int byte_bound;
unsigned int byte_position;
unsigned int num_bytes_attempted_to_write;
uint32_t byte_bound;
uint32_t byte_position;
uint32_t num_bytes_attempted_to_write;
Sirikata::JpegError err;
std::function<void(Sirikata::DecoderWriter*, size_t)> size_callback;
unsigned int write_no_buffer( const void* from, size_t bytes_to_write );
uint32_t write_no_buffer( const void* from, size_t bytes_to_write );
public:
bounded_iostream( Sirikata::DecoderWriter * parent,
const std::function<void(Sirikata::DecoderWriter*, size_t)> &size_callback,
Expand Down
1 change: 1 addition & 0 deletions src/lepton/lepton_codec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ CodingReturnValue LeptonCodec::ThreadState::vp8_decode_thread(unsigned int threa
/* deserialize each block in planar order */

dev_assert(luma_splits_.size() == 2); // not ready to do multiple work items on a thread yet
always_assert(luma_splits_.size() >= 2);
int min_y = luma_splits_[0];
int max_y = luma_splits_[1];
while(true) {
Expand Down
22 changes: 14 additions & 8 deletions src/lepton/vp8_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ std::vector<ThreadHandoff> VP8ComponentDecoder::initialize_decoder_state(const U
void VP8ComponentDecoder::flush() {
mux_splicer.drain(mux_reader_);
}
namespace{void nop(){}}
CodingReturnValue VP8ComponentDecoder::decode_chunk(UncompressedComponents * const colldata)
{
mux_splicer.init(spin_workers_);
Expand Down Expand Up @@ -455,14 +456,19 @@ CodingReturnValue VP8ComponentDecoder::decode_chunk(UncompressedComponents * con
if (do_threading_) {
for (unsigned int thread_id = 0; thread_id < NUM_THREADS; ++thread_id) {
unsigned int cur_spin_worker = thread_id;
spin_workers_[cur_spin_worker].work
= std::bind(worker_thread,
thread_state_[thread_id],
thread_id,
colldata,
mux_splicer.thread_target,
getWorker(cur_spin_worker),
&send_to_actual_thread_state);
if (!thread_state_[thread_id]) {
spin_workers_[cur_spin_worker].work
= &nop;
} else {
spin_workers_[cur_spin_worker].work
= std::bind(worker_thread,
thread_state_[thread_id],
thread_id,
colldata,
mux_splicer.thread_target,
getWorker(cur_spin_worker),
&send_to_actual_thread_state);
}
spin_workers_[cur_spin_worker].activate_work();
}
flush();
Expand Down
4 changes: 3 additions & 1 deletion src/vp8/decoder/boolreader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ public:
return;
}
size_t del = rope[0].second-rope[0].first;
memcpy(dest, rope[0].first, del);
if (del) {
memcpy(dest, rope[0].first, del);
}
dest += del;
size -=del;
if (size) {
Expand Down

0 comments on commit 82167c1

Please sign in to comment.