Commit 7660d568 authored by dschuff@chromium.org's avatar dschuff@chromium.org

Better handling for NULL PutBytes arg in Pnacl streaming translation thread.

Commit this instead of http://codereview.chromium.org/10834009/

R=jvoung@chromium.org,arthurhsu@chromium.org
BUG=none
TEST=nacl_integration
CID=104221

Review URL: https://chromiumcodereview.appspot.com/10828019

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148443 0039d316-1c4b-4281-b951-d872f2087c98
parent 3114e51a
...@@ -60,23 +60,31 @@ void PnaclStreamingTranslateThread::PutBytes(std::vector<char>* bytes, ...@@ -60,23 +60,31 @@ void PnaclStreamingTranslateThread::PutBytes(std::vector<char>* bytes,
PLUGIN_PRINTF(("PutBytes, this %p bytes %p, size %d, count %d\n", this, bytes, PLUGIN_PRINTF(("PutBytes, this %p bytes %p, size %d, count %d\n", this, bytes,
bytes ? bytes->size(): 0, count)); bytes ? bytes->size(): 0, count));
size_t buffer_size = 0; size_t buffer_size = 0;
// If we are done (error or not), Signal the translation thread to stop.
if (count <= PP_OK) {
NaClXMutexLock(&cond_mu_);
done_ = true;
NaClXCondVarSignal(&buffer_cond_);
NaClXMutexUnlock(&cond_mu_);
return;
}
CHECK(bytes != NULL);
// Ensure that the buffer we send to the translation thread is the right size // Ensure that the buffer we send to the translation thread is the right size
// (count can be < the buffer size). This can be done without the lock. // (count can be < the buffer size). This can be done without the lock.
if (bytes != NULL && count >= 0) { buffer_size = bytes->size();
buffer_size = bytes->size(); bytes->resize(count);
bytes->resize(count);
}
NaClXMutexLock(&cond_mu_); NaClXMutexLock(&cond_mu_);
if (count == PP_OK || count < 0) {
done_ = true; data_buffers_.push_back(std::vector<char>());
} else { bytes->swap(data_buffers_.back()); // Avoid copying the buffer data.
data_buffers_.push_back(std::vector<char>());
bytes->swap(data_buffers_.back()); // Avoid copying the buffer data.
}
NaClXCondVarSignal(&buffer_cond_); NaClXCondVarSignal(&buffer_cond_);
NaClXMutexUnlock(&cond_mu_); NaClXMutexUnlock(&cond_mu_);
// Ensure the buffer we send back to the coordinator is the expected size // Ensure the buffer we send back to the coordinator is the expected size
if (bytes != NULL) bytes->resize(buffer_size); bytes->resize(buffer_size);
} }
void PnaclStreamingTranslateThread::DoTranslate() { void PnaclStreamingTranslateThread::DoTranslate() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment