diff options
author | Lang Hames <lhames@gmail.com> | 2018-03-14 06:25:08 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2018-03-14 06:25:08 +0000 |
commit | b2facd64795cfb0ad696b5028d72cb958a62dea2 (patch) | |
tree | ae9473e98a0123d78f2c18a3c5285e9d3e2ad8a7 /llvm/lib | |
parent | 313f590aee01f2bf3a27855a8f7f0f0b800272ce (diff) | |
download | bcm5719-llvm-b2facd64795cfb0ad696b5028d72cb958a62dea2.tar.gz bcm5719-llvm-b2facd64795cfb0ad696b5028d72cb958a62dea2.zip |
[ORC] Fix a data race in the lookup function.
The Error locals need to be protected by a mutex. (This could be fixed by
having the promises / futures contain Expected and Error values, but
MSVC's future implementation does not support this yet).
Hopefully this will fix some of the errors seen on the builders due to
r327474.
llvm-svn: 327477
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/Core.cpp | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/llvm/lib/ExecutionEngine/Orc/Core.cpp b/llvm/lib/ExecutionEngine/Orc/Core.cpp index fd6ec0fe7cb..19ca781fa67 100644 --- a/llvm/lib/ExecutionEngine/Orc/Core.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Core.cpp @@ -353,21 +353,28 @@ Expected<SymbolMap> lookup(const std::vector<VSO *> &VSOs, SymbolNameSet Names, #if LLVM_ENABLE_THREADS // In the threaded case we use promises to return the results. std::promise<SymbolMap> PromisedResult; + std::mutex ErrMutex; Error ResolutionError = Error::success(); std::promise<void> PromisedReady; Error ReadyError = Error::success(); auto OnResolve = [&](Expected<SymbolMap> Result) { - ErrorAsOutParameter _(&ResolutionError); if (Result) PromisedResult.set_value(std::move(*Result)); else { - ResolutionError = Result.takeError(); + { + ErrorAsOutParameter _(&ResolutionError); + std::lock_guard<std::mutex> Lock(ErrMutex); + ResolutionError = Result.takeError(); + } PromisedResult.set_value(SymbolMap()); } }; auto OnReady = [&](Error Err) { - ErrorAsOutParameter _(&ReadyError); - ReadyError = std::move(Err); + if (Err) { + ErrorAsOutParameter _(&ReadyError); + std::lock_guard<std::mutex> Lock(ErrMutex); + ReadyError = std::move(Err); + } PromisedReady.set_value(); }; #else @@ -416,17 +423,24 @@ Expected<SymbolMap> lookup(const std::vector<VSO *> &VSOs, SymbolNameSet Names, #if LLVM_ENABLE_THREADS auto ResultFuture = PromisedResult.get_future(); auto Result = ResultFuture.get(); - if (ResolutionError) { - // ReadyError will never be assigned. Consume the success value. - cantFail(std::move(ReadyError)); - return std::move(ResolutionError); + + { + std::lock_guard<std::mutex> Lock(ErrMutex); + if (ResolutionError) { + // ReadyError will never be assigned. Consume the success value. + cantFail(std::move(ReadyError)); + return std::move(ResolutionError); + } } auto ReadyFuture = PromisedReady.get_future(); ReadyFuture.get(); - if (ReadyError) - return std::move(ReadyError); + { + std::lock_guard<std::mutex> Lock(ErrMutex); + if (ReadyError) + return std::move(ReadyError); + } return std::move(Result); |