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 "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 Loading... |
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(const void* bytes, int32_t count) { | 114 void PnaclTranslateThread::PutBytes(std::vector<char>* bytes, int count) { |
| 115 PLUGIN_PRINTF(("PutBytes (this=%p, bytes=%p, size=%" NACL_PRIuS |
| 116 ", count=%d)\n", |
| 117 this, bytes, bytes ? bytes->size() : 0, count)); |
| 118 size_t buffer_size = 0; |
115 CHECK(bytes != NULL); | 119 CHECK(bytes != NULL); |
| 120 // Ensure that the buffer we send to the translation thread is the right size |
| 121 // (count can be < the buffer size). This can be done without the lock. |
| 122 buffer_size = bytes->size(); |
| 123 bytes->resize(count); |
| 124 |
116 NaClXMutexLock(&cond_mu_); | 125 NaClXMutexLock(&cond_mu_); |
117 std::vector<char> v; | 126 |
118 data_buffers_.push_back(v); | 127 data_buffers_.push_back(std::vector<char>()); |
119 data_buffers_.back().insert(v.end(), | 128 bytes->swap(data_buffers_.back()); // Avoid copying the buffer data. |
120 static_cast<const char*>(bytes), | 129 |
121 static_cast<const char*>(bytes) + count); | |
122 NaClXCondVarSignal(&buffer_cond_); | 130 NaClXCondVarSignal(&buffer_cond_); |
123 NaClXMutexUnlock(&cond_mu_); | 131 NaClXMutexUnlock(&cond_mu_); |
| 132 |
| 133 // Ensure the buffer we send back to the coordinator is the expected size |
| 134 bytes->resize(buffer_size); |
124 } | 135 } |
125 | 136 |
126 void PnaclTranslateThread::EndStream() { | 137 void PnaclTranslateThread::EndStream() { |
127 NaClXMutexLock(&cond_mu_); | 138 NaClXMutexLock(&cond_mu_); |
128 done_ = true; | 139 done_ = true; |
129 NaClXCondVarSignal(&buffer_cond_); | 140 NaClXCondVarSignal(&buffer_cond_); |
130 NaClXMutexUnlock(&cond_mu_); | 141 NaClXMutexUnlock(&cond_mu_); |
131 } | 142 } |
132 | 143 |
133 void WINAPI PnaclTranslateThread::DoTranslateThread(void* arg) { | 144 void WINAPI PnaclTranslateThread::DoTranslateThread(void* arg) { |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 AbortSubprocesses(); | 444 AbortSubprocesses(); |
434 if (translate_thread_ != NULL) | 445 if (translate_thread_ != NULL) |
435 NaClThreadJoin(translate_thread_.get()); | 446 NaClThreadJoin(translate_thread_.get()); |
436 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n")); | 447 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n")); |
437 NaClCondVarDtor(&buffer_cond_); | 448 NaClCondVarDtor(&buffer_cond_); |
438 NaClMutexDtor(&cond_mu_); | 449 NaClMutexDtor(&cond_mu_); |
439 NaClMutexDtor(&subprocess_mu_); | 450 NaClMutexDtor(&subprocess_mu_); |
440 } | 451 } |
441 | 452 |
442 } // namespace plugin | 453 } // namespace plugin |
OLD | NEW |