mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
Storage: Add more Dispatcher accessors.
This commit is contained in:
@@ -23,9 +23,8 @@ Storage::Storage() {
|
||||
|
||||
Storage::~Storage() {}
|
||||
|
||||
std::shared_ptr<StorageEntry> Storage::CreateEntry(StringRef name,
|
||||
std::shared_ptr<Value> value,
|
||||
unsigned int flags) {
|
||||
std::shared_ptr<StorageEntry> Storage::DispatchCreateEntry(
|
||||
StringRef name, std::shared_ptr<Value> value, unsigned int flags) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
auto& entry = m_entries[name];
|
||||
if (!entry) entry = std::make_shared<StorageEntry>(name);
|
||||
@@ -34,6 +33,20 @@ std::shared_ptr<StorageEntry> Storage::CreateEntry(StringRef name,
|
||||
return entry;
|
||||
}
|
||||
|
||||
void Storage::DispatchDeleteEntry(StringRef name) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
auto i = m_entries.find(name);
|
||||
if (i == m_entries.end()) return;
|
||||
auto entry = i->getValue();
|
||||
m_entries.erase(i); // erase from map
|
||||
}
|
||||
|
||||
void Storage::DispatchDeleteAllEntries() {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (m_entries.empty()) return;
|
||||
m_entries.clear();
|
||||
}
|
||||
|
||||
void Storage::GetUpdates(UpdateMap* updates, bool* delete_all) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_updates.swap(*updates);
|
||||
|
||||
@@ -60,6 +60,7 @@ class StorageEntry {
|
||||
|
||||
SequenceNumber seq_num() const { return m_seq_num; }
|
||||
void set_seq_num(SequenceNumber seq_num) { m_seq_num = seq_num; }
|
||||
SequenceNumber seq_num_inc() { return ++m_seq_num; }
|
||||
|
||||
private:
|
||||
// These variables are accessed by both Dispatcher and user, so must use
|
||||
@@ -109,9 +110,10 @@ class Storage {
|
||||
std::shared_ptr<StorageEntry> FindEntry(StringRef name) const;
|
||||
|
||||
// Accessors required by Dispatcher.
|
||||
std::shared_ptr<StorageEntry> CreateEntry(StringRef name,
|
||||
std::shared_ptr<Value> value,
|
||||
unsigned int flags);
|
||||
std::shared_ptr<StorageEntry> DispatchCreateEntry(
|
||||
StringRef name, std::shared_ptr<Value> value, unsigned int flags);
|
||||
void DispatchDeleteEntry(StringRef name);
|
||||
void DispatchDeleteAllEntries();
|
||||
void GetUpdates(UpdateMap* updates, bool* delete_all);
|
||||
std::mutex& mutex() { return m_mutex; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user