Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SharedCache] Fix some bugs and add the ability to bulk load images
This is a massive and messy commit that started out as trying to add bulk loading of images (the ability to load them in parallel via a single API call) but then required a number of changes that unearthed some fundamental bugs with the current design of `SharedCache`. Untangle it all to create nice clean commits is more work than its worth. The main bug fix is the fact that `State()` was not actually thread safe because `m_state` which it was returning a copy of could be modified concurrently during the copying. Now a lock is held when accessing `m_state` via functions like `State()` and a `shared_ptr` is returned. This is a thread safe operation and the returned `shared_ptr` guarantees the `State` struct remains allocated whilst that `shared_ptr` exists. This has also required changes to some of the code to create local variables to ensure things remain allocated after they are read from `State()`. The other big change is introducing an API call to load a number of images concurrently. This is done using worker threads and required some changes to `SharedCache::LoadImageWithInstallName` and `SharedCache::LoadSectionAtAddress` so that they could work in parallel. Previously they just took locks for extended periods, this is now reduced as much as possible. Other work had to be done to make parts of the loading process thread safe. Something else this commit adds is the commenting out of calls to the undo actions API; `BeginUndoActions`, `ForgetUndoActions` and `CommitUndoActions`. Tbh I don't know if this actually works at all when being used in parallel as, according to Vector35, due to the design of the undo actions system, it can't distinguish undo actions across threads. So when you've got loads of threads making calls to this API and then calling `ForgetUndoActions` or `CommitUndoActions`, is what you expect actually getting forgotten or committed? The main reason for commenting these out though is issues like Vector35#6289. There might be some other minor changes in this commit I've forgotten about but I think this is the majority of it.
- Loading branch information