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

Commit 82167c1

Browse files
committed
fix #87 : always check that threads_required set up the appropriate number of threads---fire off nop functions on unused threads for consistency
1 parent 665303a commit 82167c1

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

Diff for: src/lepton/bitops.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ bounded_iostream::bounded_iostream(Sirikata::DecoderWriter *w,
356356
this->size_callback = size_callback;
357357
buffer_position = 0;
358358
byte_position = 0;
359+
byte_bound = 0x7FFFFFFF;
359360
num_bytes_attempted_to_write = 0;
360361
set_bound(0);
361362
}
@@ -384,7 +385,7 @@ void bounded_iostream::close() {
384385
parent->Close();
385386
}
386387

387-
unsigned int bounded_iostream::write_no_buffer(const void *from, size_t bytes_to_write) {
388+
uint32_t bounded_iostream::write_no_buffer(const void *from, size_t bytes_to_write) {
388389
//return iostream::write(from,tpsize,dtsize);
389390
std::pair<unsigned int, Sirikata::JpegError> retval;
390391
if (byte_bound != 0 && byte_position + bytes_to_write > byte_bound) {

Diff for: src/lepton/bitops.hh

+4-4
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,12 @@ class bounded_iostream
467467
uint8_t buffer[buffer_size];
468468
uint32_t buffer_position;
469469
Sirikata::DecoderWriter *parent;
470-
unsigned int byte_bound;
471-
unsigned int byte_position;
472-
unsigned int num_bytes_attempted_to_write;
470+
uint32_t byte_bound;
471+
uint32_t byte_position;
472+
uint32_t num_bytes_attempted_to_write;
473473
Sirikata::JpegError err;
474474
std::function<void(Sirikata::DecoderWriter*, size_t)> size_callback;
475-
unsigned int write_no_buffer( const void* from, size_t bytes_to_write );
475+
uint32_t write_no_buffer( const void* from, size_t bytes_to_write );
476476
public:
477477
bounded_iostream( Sirikata::DecoderWriter * parent,
478478
const std::function<void(Sirikata::DecoderWriter*, size_t)> &size_callback,

Diff for: src/lepton/lepton_codec.cc

+1
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ CodingReturnValue LeptonCodec::ThreadState::vp8_decode_thread(unsigned int threa
275275
/* deserialize each block in planar order */
276276

277277
dev_assert(luma_splits_.size() == 2); // not ready to do multiple work items on a thread yet
278+
always_assert(luma_splits_.size() >= 2);
278279
int min_y = luma_splits_[0];
279280
int max_y = luma_splits_[1];
280281
while(true) {

Diff for: src/lepton/vp8_decoder.cc

+14-8
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ std::vector<ThreadHandoff> VP8ComponentDecoder::initialize_decoder_state(const U
417417
void VP8ComponentDecoder::flush() {
418418
mux_splicer.drain(mux_reader_);
419419
}
420+
namespace{void nop(){}}
420421
CodingReturnValue VP8ComponentDecoder::decode_chunk(UncompressedComponents * const colldata)
421422
{
422423
mux_splicer.init(spin_workers_);
@@ -455,14 +456,19 @@ CodingReturnValue VP8ComponentDecoder::decode_chunk(UncompressedComponents * con
455456
if (do_threading_) {
456457
for (unsigned int thread_id = 0; thread_id < NUM_THREADS; ++thread_id) {
457458
unsigned int cur_spin_worker = thread_id;
458-
spin_workers_[cur_spin_worker].work
459-
= std::bind(worker_thread,
460-
thread_state_[thread_id],
461-
thread_id,
462-
colldata,
463-
mux_splicer.thread_target,
464-
getWorker(cur_spin_worker),
465-
&send_to_actual_thread_state);
459+
if (!thread_state_[thread_id]) {
460+
spin_workers_[cur_spin_worker].work
461+
= &nop;
462+
} else {
463+
spin_workers_[cur_spin_worker].work
464+
= std::bind(worker_thread,
465+
thread_state_[thread_id],
466+
thread_id,
467+
colldata,
468+
mux_splicer.thread_target,
469+
getWorker(cur_spin_worker),
470+
&send_to_actual_thread_state);
471+
}
466472
spin_workers_[cur_spin_worker].activate_work();
467473
}
468474
flush();

Diff for: src/vp8/decoder/boolreader.hh

+3-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ public:
119119
return;
120120
}
121121
size_t del = rope[0].second-rope[0].first;
122-
memcpy(dest, rope[0].first, del);
122+
if (del) {
123+
memcpy(dest, rope[0].first, del);
124+
}
123125
dest += del;
124126
size -=del;
125127
if (size) {

0 commit comments

Comments
 (0)