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