Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.cc

Issue 383213005: Pepper: Clarify end-of-bitcode-stream behavior. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.h" 5 #include "ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" 9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
10 #include "ppapi/cpp/var.h" 10 #include "ppapi/cpp/var.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 DoTranslateThread, 104 DoTranslateThread,
105 this, 105 this,
106 kArbitraryStackSize)) { 106 kArbitraryStackSize)) {
107 TranslateFailed(PP_NACL_ERROR_PNACL_THREAD_CREATE, 107 TranslateFailed(PP_NACL_ERROR_PNACL_THREAD_CREATE,
108 "could not create thread."); 108 "could not create thread.");
109 translate_thread_.reset(NULL); 109 translate_thread_.reset(NULL);
110 } 110 }
111 } 111 }
112 112
113 // Called from main thread to send bytes to the translator. 113 // Called from main thread to send bytes to the translator.
114 void PnaclTranslateThread::PutBytes(std::vector<char>* bytes, 114 void PnaclTranslateThread::PutBytes(std::vector<char>* bytes, int count) {
115 int count) {
116 PLUGIN_PRINTF(("PutBytes (this=%p, bytes=%p, size=%" NACL_PRIuS 115 PLUGIN_PRINTF(("PutBytes (this=%p, bytes=%p, size=%" NACL_PRIuS
117 ", count=%d)\n", 116 ", count=%d)\n",
118 this, bytes, bytes ? bytes->size() : 0, count)); 117 this, bytes, bytes ? bytes->size() : 0, count));
119 size_t buffer_size = 0; 118 size_t buffer_size = 0;
120 // If we are done (error or not), Signal the translation thread to stop.
121 if (count <= PP_OK) {
122 NaClXMutexLock(&cond_mu_);
123 done_ = true;
124 NaClXCondVarSignal(&buffer_cond_);
125 NaClXMutexUnlock(&cond_mu_);
126 return;
127 }
128
129 CHECK(bytes != NULL); 119 CHECK(bytes != NULL);
130 // Ensure that the buffer we send to the translation thread is the right size 120 // Ensure that the buffer we send to the translation thread is the right size
131 // (count can be < the buffer size). This can be done without the lock. 121 // (count can be < the buffer size). This can be done without the lock.
132 buffer_size = bytes->size(); 122 buffer_size = bytes->size();
133 bytes->resize(count); 123 bytes->resize(count);
134 124
135 NaClXMutexLock(&cond_mu_); 125 NaClXMutexLock(&cond_mu_);
136 126
137 data_buffers_.push_back(std::vector<char>()); 127 data_buffers_.push_back(std::vector<char>());
138 bytes->swap(data_buffers_.back()); // Avoid copying the buffer data. 128 bytes->swap(data_buffers_.back()); // Avoid copying the buffer data.
139 129
140 NaClXCondVarSignal(&buffer_cond_); 130 NaClXCondVarSignal(&buffer_cond_);
141 NaClXMutexUnlock(&cond_mu_); 131 NaClXMutexUnlock(&cond_mu_);
142 132
143 // Ensure the buffer we send back to the coordinator is the expected size 133 // Ensure the buffer we send back to the coordinator is the expected size
144 bytes->resize(buffer_size); 134 bytes->resize(buffer_size);
145 } 135 }
146 136
137 void PnaclTranslateThread::EndStream() {
138 NaClXMutexLock(&cond_mu_);
139 done_ = true;
140 NaClXCondVarSignal(&buffer_cond_);
141 NaClXMutexUnlock(&cond_mu_);
142 }
143
147 void WINAPI PnaclTranslateThread::DoTranslateThread(void* arg) { 144 void WINAPI PnaclTranslateThread::DoTranslateThread(void* arg) {
148 PnaclTranslateThread* translator = 145 PnaclTranslateThread* translator =
149 reinterpret_cast<PnaclTranslateThread*>(arg); 146 reinterpret_cast<PnaclTranslateThread*>(arg);
150 translator->DoTranslate(); 147 translator->DoTranslate();
151 } 148 }
152 149
153 void PnaclTranslateThread::DoTranslate() { 150 void PnaclTranslateThread::DoTranslate() {
154 ErrorInfo error_info; 151 ErrorInfo error_info;
155 SrpcParams params; 152 SrpcParams params;
156 std::vector<nacl::DescWrapper*> llc_out_files; 153 std::vector<nacl::DescWrapper*> llc_out_files;
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 AbortSubprocesses(); 444 AbortSubprocesses();
448 if (translate_thread_ != NULL) 445 if (translate_thread_ != NULL)
449 NaClThreadJoin(translate_thread_.get()); 446 NaClThreadJoin(translate_thread_.get());
450 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n")); 447 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n"));
451 NaClCondVarDtor(&buffer_cond_); 448 NaClCondVarDtor(&buffer_cond_);
452 NaClMutexDtor(&cond_mu_); 449 NaClMutexDtor(&cond_mu_);
453 NaClMutexDtor(&subprocess_mu_); 450 NaClMutexDtor(&subprocess_mu_);
454 } 451 }
455 452
456 } // namespace plugin 453 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698