friss created this revision. friss added a reviewer: jingham. Herald added a subscriber: emaste.
Multiple threads could be calling into DoLoadImage concurrently, only one should be allowed to create the UtilityFunction. https://reviews.llvm.org/D46733 Files: source/Plugins/Platform/POSIX/PlatformPOSIX.cpp Index: source/Plugins/Platform/POSIX/PlatformPOSIX.cpp =================================================================== --- source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -1036,17 +1036,23 @@ thread_sp->CalculateExecutionContext(exe_ctx); Status utility_error; - - // The UtilityFunction is held in the Process. Platforms don't track the - // lifespan of the Targets that use them, we can't put this in the Platform. - UtilityFunction *dlopen_utility_func - = process->GetLoadImageUtilityFunction(this); + UtilityFunction *dlopen_utility_func; ValueList arguments; FunctionCaller *do_dlopen_function = nullptr; - if (!dlopen_utility_func) { - // Make the UtilityFunction: - dlopen_utility_func = MakeLoadImageUtilityFunction(exe_ctx, error); + // Multiple threads could be calling into DoLoadImage concurrently, + // only one should be allowed to create the UtilityFunction. + { + static std::mutex do_dlopen_mutex; + std::lock_guard<std::mutex> lock(do_dlopen_mutex); + + // The UtilityFunction is held in the Process. Platforms don't track the + // lifespan of the Targets that use them, we can't put this in the Platform. + dlopen_utility_func = process->GetLoadImageUtilityFunction(this); + if (!dlopen_utility_func) { + // Make the UtilityFunction: + dlopen_utility_func = MakeLoadImageUtilityFunction(exe_ctx, error); + } } // If we couldn't make it, the error will be in error, so we can exit here. if (!dlopen_utility_func)
Index: source/Plugins/Platform/POSIX/PlatformPOSIX.cpp =================================================================== --- source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -1036,17 +1036,23 @@ thread_sp->CalculateExecutionContext(exe_ctx); Status utility_error; - - // The UtilityFunction is held in the Process. Platforms don't track the - // lifespan of the Targets that use them, we can't put this in the Platform. - UtilityFunction *dlopen_utility_func - = process->GetLoadImageUtilityFunction(this); + UtilityFunction *dlopen_utility_func; ValueList arguments; FunctionCaller *do_dlopen_function = nullptr; - if (!dlopen_utility_func) { - // Make the UtilityFunction: - dlopen_utility_func = MakeLoadImageUtilityFunction(exe_ctx, error); + // Multiple threads could be calling into DoLoadImage concurrently, + // only one should be allowed to create the UtilityFunction. + { + static std::mutex do_dlopen_mutex; + std::lock_guard<std::mutex> lock(do_dlopen_mutex); + + // The UtilityFunction is held in the Process. Platforms don't track the + // lifespan of the Targets that use them, we can't put this in the Platform. + dlopen_utility_func = process->GetLoadImageUtilityFunction(this); + if (!dlopen_utility_func) { + // Make the UtilityFunction: + dlopen_utility_func = MakeLoadImageUtilityFunction(exe_ctx, error); + } } // If we couldn't make it, the error will be in error, so we can exit here. if (!dlopen_utility_func)
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits