Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SaveState: Fix for race condition ("wait" didn't actually waited for …
…file to flush/close). g_compressAndDumpStateSyncEvent was Set() before destruction of file object (i.e. before flushing changes and closing file).
- Loading branch information
1 parent
a91810b
commit c252645
Showing
2 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
|
||
namespace Common | ||
{ | ||
|
||
class ScopeGuard final | ||
{ | ||
public: | ||
template<class Callable> | ||
ScopeGuard(Callable && finalizer) : m_finalizer(std::forward<Callable>(finalizer)) {} | ||
|
||
ScopeGuard(ScopeGuard && other) : m_finalizer(std::move(other.m_finalizer)) | ||
{ | ||
other.m_finalizer = nullptr; | ||
} | ||
|
||
~ScopeGuard() | ||
{ | ||
Exit(); | ||
} | ||
|
||
void Dismiss() | ||
{ | ||
m_finalizer = nullptr; | ||
} | ||
|
||
void Exit() | ||
{ | ||
if (m_finalizer) | ||
{ | ||
m_finalizer(); // must not throw | ||
m_finalizer = nullptr; | ||
} | ||
} | ||
|
||
ScopeGuard(const ScopeGuard&) = delete; | ||
|
||
void operator = (const ScopeGuard&) = delete; | ||
|
||
private: | ||
std::function<void()> m_finalizer; | ||
}; | ||
|
||
} // Namespace Common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters