Chromium Code Reviews

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

Issue 393693004: Pepper: Delete FileDownloader in trusted plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: STL fix Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
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...)
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
121 // (count can be < the buffer size). This can be done without the lock.
122 buffer_size = bytes->size();
123 bytes->resize(count);
124
125 NaClXMutexLock(&cond_mu_); 116 NaClXMutexLock(&cond_mu_);
126
127 data_buffers_.push_back(std::vector<char>()); 117 data_buffers_.push_back(std::vector<char>());
128 bytes->swap(data_buffers_.back()); // Avoid copying the buffer data. 118 data_buffers_.back().insert(data_buffers_.back().end(),
129 119 static_cast<const char*>(bytes),
120 static_cast<const char*>(bytes) + count);
130 NaClXCondVarSignal(&buffer_cond_); 121 NaClXCondVarSignal(&buffer_cond_);
131 NaClXMutexUnlock(&cond_mu_); 122 NaClXMutexUnlock(&cond_mu_);
132
133 // Ensure the buffer we send back to the coordinator is the expected size
134 bytes->resize(buffer_size);
135 } 123 }
136 124
137 void PnaclTranslateThread::EndStream() { 125 void PnaclTranslateThread::EndStream() {
138 NaClXMutexLock(&cond_mu_); 126 NaClXMutexLock(&cond_mu_);
139 done_ = true; 127 done_ = true;
140 NaClXCondVarSignal(&buffer_cond_); 128 NaClXCondVarSignal(&buffer_cond_);
141 NaClXMutexUnlock(&cond_mu_); 129 NaClXMutexUnlock(&cond_mu_);
142 } 130 }
143 131
144 void WINAPI PnaclTranslateThread::DoTranslateThread(void* arg) { 132 void WINAPI PnaclTranslateThread::DoTranslateThread(void* arg) {
(...skipping 299 matching lines...)
444 AbortSubprocesses(); 432 AbortSubprocesses();
445 if (translate_thread_ != NULL) 433 if (translate_thread_ != NULL)
446 NaClThreadJoin(translate_thread_.get()); 434 NaClThreadJoin(translate_thread_.get());
447 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n")); 435 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n"));
448 NaClCondVarDtor(&buffer_cond_); 436 NaClCondVarDtor(&buffer_cond_);
449 NaClMutexDtor(&cond_mu_); 437 NaClMutexDtor(&cond_mu_);
450 NaClMutexDtor(&subprocess_mu_); 438 NaClMutexDtor(&subprocess_mu_);
451 } 439 }
452 440
453 } // namespace plugin 441 } // namespace plugin
OLDNEW

Powered by Google App Engine