summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-10-25 10:27:17 +0100
committerSven Gothel <[email protected]>2020-10-25 10:27:17 +0100
commit21be64f828fa0464d36ffc15a133134e076a63a1 (patch)
tree04c339a3ff12388b37c7c98f517da058afbf7da4 /src
parent90300424d5a1d8c098806bfd3bace1d67554cc07 (diff)
Review & fix cow_vector 'fancy' write access: write_mutex, copy_store and set_store
Diffstat (limited to 'src')
-rw-r--r--src/direct_bt/DBTAdapter.cpp8
-rw-r--r--src/direct_bt/DBTManager.cpp20
-rw-r--r--src/direct_bt/GATTHandler.cpp16
3 files changed, 22 insertions, 22 deletions
diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp
index 19791bdb..c1df37c3 100644
--- a/src/direct_bt/DBTAdapter.cpp
+++ b/src/direct_bt/DBTAdapter.cpp
@@ -406,11 +406,11 @@ bool DBTAdapter::removeStatusListener(const AdapterStatusListener * l) {
throw jau::IllegalArgumentException("DBTAdapterStatusListener ref is null", E_FILE_LINE);
}
const std::lock_guard<std::recursive_mutex> lock(statusListenerList.get_write_mutex());
- std::shared_ptr<std::vector<std::shared_ptr<AdapterStatusListener>>> snapshot = statusListenerList.copy_store();
+ std::shared_ptr<std::vector<std::shared_ptr<AdapterStatusListener>>> store = statusListenerList.copy_store();
int count = 0;
- for(auto it = snapshot->begin(); it != snapshot->end(); ) {
+ for(auto it = store->begin(); it != store->end(); ) {
if ( **it == *l ) {
- it = snapshot->erase(it);
+ it = store->erase(it);
count++;
break;
} else {
@@ -418,7 +418,7 @@ bool DBTAdapter::removeStatusListener(const AdapterStatusListener * l) {
}
}
if( 0 < count ) {
- statusListenerList.set_store(std::move(snapshot));
+ statusListenerList.set_store(std::move(store));
return true;
}
return false;
diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp
index 5cb7c789..1ae28018 100644
--- a/src/direct_bt/DBTManager.cpp
+++ b/src/direct_bt/DBTManager.cpp
@@ -569,30 +569,30 @@ std::shared_ptr<AdapterInfo> DBTManager::getAdapterInfo(const uint16_t dev_id) c
}
bool DBTManager::addAdapterInfo(std::shared_ptr<AdapterInfo> ai) noexcept {
const std::lock_guard<std::recursive_mutex> lock(adapterInfos.get_write_mutex());
- std::shared_ptr<std::vector<std::shared_ptr<AdapterInfo>>> snapshot = adapterInfos.get_snapshot();
+ std::shared_ptr<std::vector<std::shared_ptr<AdapterInfo>>> store = adapterInfos.copy_store();
- auto begin = snapshot->begin();
- auto it = std::find_if(begin, snapshot->end(), [&](std::shared_ptr<AdapterInfo> const& p) -> bool {
+ auto begin = store->begin();
+ auto it = std::find_if(begin, store->end(), [&](std::shared_ptr<AdapterInfo> const& p) -> bool {
return p->dev_id == ai->dev_id;
});
- if ( it != std::end(*snapshot) ) {
+ if ( it != std::end(*store) ) {
// already existing
return false;
}
- snapshot->push_back(ai);
- adapterInfos.set_store(std::move(snapshot));
+ store->push_back(ai);
+ adapterInfos.set_store(std::move(store));
return true;
}
std::shared_ptr<AdapterInfo> DBTManager::removeAdapterInfo(const uint16_t dev_id) noexcept {
const std::lock_guard<std::recursive_mutex> lock(adapterInfos.get_write_mutex());
- std::shared_ptr<std::vector<std::shared_ptr<AdapterInfo>>> snapshot = adapterInfos.get_snapshot();
+ std::shared_ptr<std::vector<std::shared_ptr<AdapterInfo>>> store = adapterInfos.copy_store();
- for(auto it = snapshot->begin(); it != snapshot->end(); ) {
+ for(auto it = store->begin(); it != store->end(); ) {
std::shared_ptr<AdapterInfo> & ai = *it;
if( ai->dev_id == dev_id ) {
std::shared_ptr<AdapterInfo> res = ai;
- it = snapshot->erase(it);
- adapterInfos.set_store(std::move(snapshot));
+ it = store->erase(it);
+ adapterInfos.set_store(std::move(store));
return res;
} else {
++it;
diff --git a/src/direct_bt/GATTHandler.cpp b/src/direct_bt/GATTHandler.cpp
index 977f224c..7a2808da 100644
--- a/src/direct_bt/GATTHandler.cpp
+++ b/src/direct_bt/GATTHandler.cpp
@@ -124,11 +124,11 @@ bool GATTHandler::removeCharacteristicListener(const GATTCharacteristicListener
return false;
}
const std::lock_guard<std::recursive_mutex> lock(characteristicListenerList.get_write_mutex());
- std::shared_ptr<std::vector<std::shared_ptr<GATTCharacteristicListener>>> snapshot = characteristicListenerList.copy_store();
+ std::shared_ptr<std::vector<std::shared_ptr<GATTCharacteristicListener>>> store = characteristicListenerList.copy_store();
int count = 0;
- for(auto it = snapshot->begin(); it != snapshot->end(); ) {
+ for(auto it = store->begin(); it != store->end(); ) {
if ( **it == *l ) {
- it = snapshot->erase(it);
+ it = store->erase(it);
count++;
break;
} else {
@@ -136,7 +136,7 @@ bool GATTHandler::removeCharacteristicListener(const GATTCharacteristicListener
}
}
if( 0 < count ) {
- characteristicListenerList.set_store(std::move(snapshot));
+ characteristicListenerList.set_store(std::move(store));
return true;
}
return false;
@@ -156,11 +156,11 @@ int GATTHandler::removeAllAssociatedCharacteristicListener(const GATTCharacteris
return false;
}
const std::lock_guard<std::recursive_mutex> lock(characteristicListenerList.get_write_mutex());
- std::shared_ptr<std::vector<std::shared_ptr<GATTCharacteristicListener>>> snapshot = characteristicListenerList.copy_store();
+ std::shared_ptr<std::vector<std::shared_ptr<GATTCharacteristicListener>>> store = characteristicListenerList.copy_store();
int count = 0;
- for(auto it = snapshot->begin(); it != snapshot->end(); ) {
+ for(auto it = store->begin(); it != store->end(); ) {
if ( (*it)->match(*associatedCharacteristic) ) {
- it = snapshot->erase(it);
+ it = store->erase(it);
count++;
break;
} else {
@@ -168,7 +168,7 @@ int GATTHandler::removeAllAssociatedCharacteristicListener(const GATTCharacteris
}
}
if( 0 < count ) {
- characteristicListenerList.set_store(std::move(snapshot));
+ characteristicListenerList.set_store(std::move(store));
return true;
}
return false;