This is an archive of the discontinued LLVM Phabricator instance.

Add a lock to PlatformPOSIX::DoLoadImage
ClosedPublic

Authored by friss on May 10 2018, 4:08 PM.

Details

Summary

Multiple threads could be calling into DoLoadImage concurrently,
only one should be allowed to create the UtilityFunction.

Diff Detail

Repository
rL LLVM

Event Timeline

friss created this revision.May 10 2018, 4:08 PM
clayborg requested changes to this revision.May 10 2018, 4:46 PM
clayborg added a subscriber: clayborg.
clayborg added inline comments.
source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
1046–1047 ↗(On Diff #146252)

We should put the mutex, or better yet a std::once_flag, in the process as an instance variable. The utility function belongs to each process.

This revision now requires changes to proceed.May 10 2018, 4:46 PM
friss added inline comments.May 10 2018, 4:58 PM
source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
1046–1047 ↗(On Diff #146252)

I don't disagree, but it seemed a little overkill. Would you just put it as a public member? Or add a GetLoadImageUtilityFunctionOnceFlag() accessor?

clayborg added inline comments.May 10 2018, 5:05 PM
source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
1047 ↗(On Diff #146252)

Accessor would be fine. The other reason for putting this in the process is multi-threaded code that attempts to use this after the main thread has exited will crash as the static mutex might destruct itself.

friss updated this revision to Diff 146268.May 10 2018, 6:20 PM

I heted the idea of hosting the once_flag in Process but using
it in PlatformPOSIX. I did a bigger refactoring where platforms
pass a factory lambda to the accessor and the thread-safe init
is done in the Process class itself using this lambda.

jingham accepted this revision.May 10 2018, 7:14 PM

That looks fine to me.

clayborg accepted this revision.May 11 2018, 9:14 AM

Much better.

This revision is now accepted and ready to land.May 11 2018, 9:14 AM
This revision was automatically updated to reflect the committed changes.