OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_STREAMING_TRANSLATE_THREAD_H_ | |
6 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_STREAMING_TRANSLATE_THREAD_H_ | |
7 | |
8 #include <deque> | |
9 #include <vector> | |
10 | |
11 #include "native_client/src/include/nacl_macros.h" | |
12 #include "native_client/src/shared/platform/nacl_sync_checked.h" | |
13 #include "native_client/src/trusted/plugin/pnacl_translate_thread.h" | |
14 | |
15 namespace plugin { | |
16 | |
17 class PnaclStreamingTranslateThread : public PnaclTranslateThread { | |
18 public: | |
19 PnaclStreamingTranslateThread(); | |
20 virtual ~PnaclStreamingTranslateThread(); | |
21 | |
22 // Start the translation process. It will continue to run and consume data | |
23 // as it is passed in with PutBytes. | |
24 virtual void RunTranslate(const pp::CompletionCallback& finish_callback, | |
25 const Manifest* manifest, | |
26 const Manifest* ld_manifest, | |
27 TempFile* obj_file, | |
28 LocalTempFile* nexe_file, | |
29 ErrorInfo* error_info, | |
30 PnaclResources* resources, | |
31 Plugin* plugin); | |
32 | |
33 // Kill the translation and/or linking processes. | |
34 virtual void SetSubprocessesShouldDie(); | |
35 | |
36 // Send bitcode bytes to the translator. Called from the main thread. | |
37 void PutBytes(std::vector<char>* data, int count); | |
38 | |
39 private: | |
40 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclStreamingTranslateThread); | |
41 // Run the streaming translation. Call on the translation/SRPC thread. | |
42 void DoTranslate(); | |
43 | |
44 bool done_; | |
45 // Condition variable to synchronize communication with the SRPC thread. | |
46 // SRPC thread waits on this condvar if data_buffers_ is empty (meaning | |
47 // there is no bitcode to send to the translator), and the main thread | |
48 // appends to data_buffers_ and signals it when it receives bitcode. | |
49 struct NaClCondVar buffer_cond_; | |
50 // Mutex for buffer_cond_. | |
51 struct NaClMutex cond_mu_; | |
52 // Data buffers from FileDownloader are enqueued here to pass from the | |
53 // main thread to the SRPC thread. Protected by cond_mu_ | |
54 std::deque<std::vector<char> > data_buffers_; | |
55 }; | |
56 | |
57 } // namespace plugin | |
58 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_STREAMING_TRANSLATE_THREAD_H_ | |
OLD | NEW |