OLD | NEW |
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 "native_client/src/trusted/plugin/pnacl_streaming_translate_thread.h" | 5 #include "native_client/src/trusted/plugin/pnacl_streaming_translate_thread.h" |
6 | 6 |
7 #include "native_client/src/include/nacl_scoped_ptr.h" | 7 #include "native_client/src/include/nacl_scoped_ptr.h" |
8 #include "native_client/src/trusted/plugin/plugin.h" | 8 #include "native_client/src/trusted/plugin/plugin.h" |
9 #include "native_client/src/trusted/plugin/pnacl_resources.h" | 9 #include "native_client/src/trusted/plugin/pnacl_resources.h" |
10 #include "native_client/src/trusted/plugin/srpc_params.h" | 10 #include "native_client/src/trusted/plugin/srpc_params.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 translate_thread_.reset(NULL); | 53 translate_thread_.reset(NULL); |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 // Called from main thread to send bytes to the translator. | 57 // Called from main thread to send bytes to the translator. |
58 void PnaclStreamingTranslateThread::PutBytes(std::vector<char>* bytes, | 58 void PnaclStreamingTranslateThread::PutBytes(std::vector<char>* bytes, |
59 int count) { | 59 int count) { |
60 PLUGIN_PRINTF(("PutBytes, this %p bytes %p, size %d, count %d\n", this, bytes, | 60 PLUGIN_PRINTF(("PutBytes, this %p bytes %p, size %d, count %d\n", this, bytes, |
61 bytes ? bytes->size(): 0, count)); | 61 bytes ? bytes->size(): 0, count)); |
62 size_t buffer_size = 0; | 62 size_t buffer_size = 0; |
| 63 // If we are done (error or not), Signal the translation thread to stop. |
| 64 if (count <= PP_OK) { |
| 65 NaClXMutexLock(&cond_mu_); |
| 66 done_ = true; |
| 67 NaClXCondVarSignal(&buffer_cond_); |
| 68 NaClXMutexUnlock(&cond_mu_); |
| 69 return; |
| 70 } |
| 71 |
| 72 CHECK(bytes != NULL); |
63 // Ensure that the buffer we send to the translation thread is the right size | 73 // Ensure that the buffer we send to the translation thread is the right size |
64 // (count can be < the buffer size). This can be done without the lock. | 74 // (count can be < the buffer size). This can be done without the lock. |
65 if (bytes != NULL && count >= 0) { | 75 buffer_size = bytes->size(); |
66 buffer_size = bytes->size(); | 76 bytes->resize(count); |
67 bytes->resize(count); | 77 |
68 } | |
69 NaClXMutexLock(&cond_mu_); | 78 NaClXMutexLock(&cond_mu_); |
70 if (count == PP_OK || count < 0) { | 79 |
71 done_ = true; | 80 data_buffers_.push_back(std::vector<char>()); |
72 } else { | 81 bytes->swap(data_buffers_.back()); // Avoid copying the buffer data. |
73 data_buffers_.push_back(std::vector<char>()); | 82 |
74 bytes->swap(data_buffers_.back()); // Avoid copying the buffer data. | |
75 } | |
76 NaClXCondVarSignal(&buffer_cond_); | 83 NaClXCondVarSignal(&buffer_cond_); |
77 NaClXMutexUnlock(&cond_mu_); | 84 NaClXMutexUnlock(&cond_mu_); |
| 85 |
78 // Ensure the buffer we send back to the coordinator is the expected size | 86 // Ensure the buffer we send back to the coordinator is the expected size |
79 if (bytes != NULL) bytes->resize(buffer_size); | 87 bytes->resize(buffer_size); |
80 } | 88 } |
81 | 89 |
82 void PnaclStreamingTranslateThread::DoTranslate() { | 90 void PnaclStreamingTranslateThread::DoTranslate() { |
83 ErrorInfo error_info; | 91 ErrorInfo error_info; |
84 nacl::scoped_ptr<NaClSubprocess> llc_subprocess( | 92 nacl::scoped_ptr<NaClSubprocess> llc_subprocess( |
85 StartSubprocess(PnaclUrls::GetLlcUrl(), manifest_, &error_info)); | 93 StartSubprocess(PnaclUrls::GetLlcUrl(), manifest_, &error_info)); |
86 if (llc_subprocess == NULL) { | 94 if (llc_subprocess == NULL) { |
87 TranslateFailed("Compile process could not be created: " + | 95 TranslateFailed("Compile process could not be created: " + |
88 error_info.message()); | 96 error_info.message()); |
89 return; | 97 return; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 176 } |
169 | 177 |
170 void PnaclStreamingTranslateThread::SetSubprocessesShouldDie() { | 178 void PnaclStreamingTranslateThread::SetSubprocessesShouldDie() { |
171 PnaclTranslateThread::SetSubprocessesShouldDie(); | 179 PnaclTranslateThread::SetSubprocessesShouldDie(); |
172 nacl::MutexLocker ml(&cond_mu_); | 180 nacl::MutexLocker ml(&cond_mu_); |
173 done_ = true; | 181 done_ = true; |
174 NaClXCondVarSignal(&buffer_cond_); | 182 NaClXCondVarSignal(&buffer_cond_); |
175 } | 183 } |
176 | 184 |
177 } // namespace plugin | 185 } // namespace plugin |
OLD | NEW |