Commit 165c5952 authored by teravest@chromium.org's avatar teravest@chromium.org

Pepper: Clarify end-of-bitcode-stream behavior.

The PutBytes() method in PnaclTranslateThread is used for two purposes: giving
data to the translator processes and signaling the end of the stream.  The way
it's currently done is a bit confusing; this breaks the method into two
for clarity. This is to make code review easier to read for an upcoming change
which removes FileDownloader from the trusted plugin.

BUG=370556

Review URL: https://codereview.chromium.org/383213005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282734 0039d316-1c4b-4281-b951-d872f2087c98
parent c4095783
...@@ -444,10 +444,15 @@ void PnaclCoordinator::BitcodeStreamGotData(int32_t pp_error, ...@@ -444,10 +444,15 @@ void PnaclCoordinator::BitcodeStreamGotData(int32_t pp_error,
NACL_PRId32 ", data=%p)\n", pp_error, data ? &(*data)[0] : 0)); NACL_PRId32 ", data=%p)\n", pp_error, data ? &(*data)[0] : 0));
DCHECK(translate_thread_.get()); DCHECK(translate_thread_.get());
translate_thread_->PutBytes(data, pp_error); // When we have received data, pp_error is set to the number of bytes
// If pp_error > 0, then it represents the number of bytes received. // received.
if (data && pp_error > 0) if (pp_error > 0) {
CHECK(data);
translate_thread_->PutBytes(data, pp_error);
pexe_size_ += pp_error; pexe_size_ += pp_error;
} else {
translate_thread_->EndStream();
}
} }
StreamCallback PnaclCoordinator::GetCallback() { StreamCallback PnaclCoordinator::GetCallback() {
......
...@@ -111,21 +111,11 @@ void PnaclTranslateThread::RunTranslate( ...@@ -111,21 +111,11 @@ void PnaclTranslateThread::RunTranslate(
} }
// Called from main thread to send bytes to the translator. // Called from main thread to send bytes to the translator.
void PnaclTranslateThread::PutBytes(std::vector<char>* bytes, void PnaclTranslateThread::PutBytes(std::vector<char>* bytes, int count) {
int count) {
PLUGIN_PRINTF(("PutBytes (this=%p, bytes=%p, size=%" NACL_PRIuS PLUGIN_PRINTF(("PutBytes (this=%p, bytes=%p, size=%" NACL_PRIuS
", count=%d)\n", ", count=%d)\n",
this, bytes, bytes ? bytes->size() : 0, count)); this, bytes, 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); 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.
...@@ -144,6 +134,13 @@ void PnaclTranslateThread::PutBytes(std::vector<char>* bytes, ...@@ -144,6 +134,13 @@ void PnaclTranslateThread::PutBytes(std::vector<char>* bytes,
bytes->resize(buffer_size); bytes->resize(buffer_size);
} }
void PnaclTranslateThread::EndStream() {
NaClXMutexLock(&cond_mu_);
done_ = true;
NaClXCondVarSignal(&buffer_cond_);
NaClXMutexUnlock(&cond_mu_);
}
void WINAPI PnaclTranslateThread::DoTranslateThread(void* arg) { void WINAPI PnaclTranslateThread::DoTranslateThread(void* arg) {
PnaclTranslateThread* translator = PnaclTranslateThread* translator =
reinterpret_cast<PnaclTranslateThread*>(arg); reinterpret_cast<PnaclTranslateThread*>(arg);
......
...@@ -63,6 +63,10 @@ class PnaclTranslateThread { ...@@ -63,6 +63,10 @@ class PnaclTranslateThread {
// Send bitcode bytes to the translator. Called from the main thread. // Send bitcode bytes to the translator. Called from the main thread.
void PutBytes(std::vector<char>* data, int count); void PutBytes(std::vector<char>* data, int count);
// Notify the translator that the end of the bitcode stream has been reached.
// Called from the main thread.
void EndStream();
int64_t GetCompileTime() const { return compile_time_; } int64_t GetCompileTime() const { return compile_time_; }
private: private:
......
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