OLD | NEW |
---|---|
1 //===-- SRPCStreamer.cpp - Stream bitcode over SRPC ----------------------===// | 1 //===-- SRPCStreamer.cpp - Stream bitcode over SRPC ----------------------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 #if defined(__native_client__) | 9 #if defined(__native_client__) |
10 #define DEBUG_TYPE "bitcode-stream" | 10 #define DEBUG_TYPE "bitcode-stream" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 std::string *ErrMsg) { | 112 std::string *ErrMsg) { |
113 int err = pthread_create(&CompileThread, NULL, Callback, arg); | 113 int err = pthread_create(&CompileThread, NULL, Callback, arg); |
114 if (err) { | 114 if (err) { |
115 if (ErrMsg) *ErrMsg = std::string(strerror(errno)); | 115 if (ErrMsg) *ErrMsg = std::string(strerror(errno)); |
116 return NULL; | 116 return NULL; |
117 } | 117 } |
118 return &Q; | 118 return &Q; |
119 } | 119 } |
120 | 120 |
121 size_t SRPCStreamer::gotChunk(unsigned char *bytes, size_t len) { | 121 size_t SRPCStreamer::gotChunk(unsigned char *bytes, size_t len) { |
122 if (Error) return 0; | 122 if (__sync_fetch_and_add(&Error, 0)) return 0; // Atomic read. |
jvoung (off chromium)
2013/09/09 23:47:53
Hmm hopefully an add of 0 doesn't get optimized ou
| |
123 return Q.PutBytes(bytes, len); | 123 return Q.PutBytes(bytes, len); |
124 } | 124 } |
125 | 125 |
126 int SRPCStreamer::streamEnd(std::string *ErrMsg) { | 126 int SRPCStreamer::streamEnd(std::string *ErrMsg) { |
127 Q.SetDone(); | 127 Q.SetDone(); |
128 int err = pthread_join(CompileThread, NULL); | 128 int err = pthread_join(CompileThread, NULL); |
129 if (err) { | 129 __sync_synchronize(); |
jvoung (off chromium)
2013/09/09 23:47:53
Does pthread_join form a happens-before edge? Do
| |
130 if (Error) { | |
131 if (ErrMsg) | |
132 *ErrMsg = std::string("PNaCl Translator Error: " + ErrorMessage); | |
133 return 1; | |
134 } else if (err) { | |
130 if (ErrMsg) *ErrMsg = std::string(strerror(errno)); | 135 if (ErrMsg) *ErrMsg = std::string(strerror(errno)); |
131 return err; | 136 return err; |
132 } | 137 } |
133 if (Error && ErrMsg) *ErrMsg = std::string("compile failed."); | 138 return 0; |
134 return Error; | 139 } |
140 | |
141 void SRPCStreamer::setFatalError(const std::string& message) { | |
142 __sync_fetch_and_add(&Error, 1); | |
143 ErrorMessage = message; | |
144 __sync_synchronize(); | |
145 pthread_exit(NULL); | |
135 } | 146 } |
136 | 147 |
137 #endif // __native_client__ | 148 #endif // __native_client__ |
OLD | NEW |