Simplified the Behavior object and partially removed the path for applying non-serialized transactions. (#142)
This commit is contained in:
Родитель
d772623815
Коммит
edb38467be
|
@ -83,16 +83,6 @@ class Behavior {
|
|||
// Frees pages previously allocated with AllocateZeroedPages.
|
||||
virtual void FreePages(void* address) noexcept = 0;
|
||||
|
||||
// Locks the mutex that restricts concurrent modifications of the storage
|
||||
// where necessary.
|
||||
// This is customizable for the cases where the storage blobs are located in
|
||||
// shared memory and modified by multiple processes (in which case the
|
||||
// implementation can use a cross-process OS mutex).
|
||||
virtual void LockWriterMutex() noexcept = 0;
|
||||
|
||||
// Unlocks the mutex that restricts all modifications of the storage.
|
||||
virtual void UnlockWriterMutex() noexcept = 0;
|
||||
|
||||
// Serializes the key associated with the provided handle and returns the
|
||||
// number of written bytes.
|
||||
// The serialized data doesn't have to contain this size, as it will be saved
|
||||
|
|
|
@ -60,22 +60,18 @@ class Storage {
|
|||
// Applies the provided transaction and increments the version of the storage
|
||||
// (unless it failed to allocate memory for the transaction, see all possible
|
||||
// outcomes above).
|
||||
// The operation may call LockWriterMutex()/UnlockWriterMutex() on the
|
||||
// Behavior object, but the callers should not rely on this.
|
||||
// Note that the transactions are generally not reusable, and the state of the
|
||||
// provided object can be irreversibly changed regardless of the success of
|
||||
// the operation.
|
||||
[[nodiscard]] TransactionResult ApplyTransaction(
|
||||
TransactionView& transaction) noexcept;
|
||||
|
||||
[[nodiscard]] TransactionResult ApplyTransaction(
|
||||
std::string_view serialized_transaction) noexcept;
|
||||
|
||||
const auto& behavior() const noexcept { return behavior_; }
|
||||
|
||||
private:
|
||||
[[nodiscard]] TransactionResult ApplyTransaction(
|
||||
TransactionView& transaction) noexcept;
|
||||
|
||||
std::shared_ptr<Behavior> behavior_;
|
||||
Snapshot latest_snapshot_;
|
||||
std::mutex writer_mutex_;
|
||||
mutable std::mutex latest_snapshot_reader_mutex_;
|
||||
};
|
||||
|
||||
|
|
|
@ -642,18 +642,6 @@ class TransactionApplicator {
|
|||
size_t extra_blocks_count_{0};
|
||||
};
|
||||
|
||||
class WriterMutexGuard {
|
||||
public:
|
||||
explicit WriterMutexGuard(Behavior& behavior) noexcept : behavior_{behavior} {
|
||||
behavior.LockWriterMutex();
|
||||
}
|
||||
|
||||
~WriterMutexGuard() noexcept { behavior_.UnlockWriterMutex(); }
|
||||
|
||||
private:
|
||||
Behavior& behavior_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace Microsoft::MixedReality::Sharing::VersionedStorage::Detail
|
||||
|
||||
|
@ -676,7 +664,7 @@ Snapshot Storage::GetSnapshot() const noexcept {
|
|||
|
||||
Storage::TransactionResult Storage::ApplyTransaction(
|
||||
TransactionView& transaction) noexcept {
|
||||
auto writer_mutex_guard = Detail::WriterMutexGuard(*behavior_);
|
||||
auto writer_mutex_lock = std::lock_guard{writer_mutex_};
|
||||
// No need to lock latest_snapshot_reader_mutex_ here to perform the read
|
||||
// since only the writer thread can modify the latest_snapshot_ field, and
|
||||
// this method is called by the writer thread.
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -147,14 +147,6 @@ void TestBehavior::FreePages(void* address) noexcept {
|
|||
Platform::FreePages(address);
|
||||
}
|
||||
|
||||
void TestBehavior::LockWriterMutex() noexcept {
|
||||
writer_mutex_.lock();
|
||||
}
|
||||
|
||||
void TestBehavior::UnlockWriterMutex() noexcept {
|
||||
writer_mutex_.unlock();
|
||||
}
|
||||
|
||||
size_t TestBehavior::Serialize(KeyHandle handle,
|
||||
std::vector<std::byte>& byte_stream) {
|
||||
size_t size = byte_stream.size();
|
||||
|
|
|
@ -49,9 +49,6 @@ class TestBehavior : public Behavior {
|
|||
void* AllocateZeroedPages(size_t pages_count) noexcept override;
|
||||
void FreePages(void* address) noexcept override;
|
||||
|
||||
void LockWriterMutex() noexcept override;
|
||||
void UnlockWriterMutex() noexcept override;
|
||||
|
||||
size_t Serialize(KeyHandle handle,
|
||||
std::vector<std::byte>& byte_stream) override;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче