m_data removal
Try to avoid stepping on this vxWorks landmine.
This commit is contained in:
@ -75,7 +75,7 @@ private:
|
|||||||
mutex_type mutex;
|
mutex_type mutex;
|
||||||
store_t store;
|
store_t store;
|
||||||
};
|
};
|
||||||
std::tr1::shared_ptr<data> m_data;
|
std::tr1::shared_ptr<data> _data;
|
||||||
|
|
||||||
struct dtor {
|
struct dtor {
|
||||||
std::tr1::weak_ptr<data> container;
|
std::tr1::weak_ptr<data> container;
|
||||||
@ -110,7 +110,7 @@ private:
|
|||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
//! Construct a new empty set
|
//! Construct a new empty set
|
||||||
weak_value_map() :m_data(new data) {}
|
weak_value_map() :_data(new data) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Not copyable
|
//! Not copyable
|
||||||
@ -122,22 +122,22 @@ public:
|
|||||||
//! exchange the two sets.
|
//! exchange the two sets.
|
||||||
//! @warning Not thread safe (exchanges mutexes as well)
|
//! @warning Not thread safe (exchanges mutexes as well)
|
||||||
void swap(weak_value_map& O) {
|
void swap(weak_value_map& O) {
|
||||||
m_data.swap(O.m_data);
|
_data.swap(O._data);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Remove all (weak) entries from the set
|
//! Remove all (weak) entries from the set
|
||||||
//! @note Thread safe
|
//! @note Thread safe
|
||||||
void clear() {
|
void clear() {
|
||||||
guard_type G(m_data->mutex);
|
guard_type G(_data->mutex);
|
||||||
return m_data->store.clear();
|
return _data->store.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Test if set is empty at this moment
|
//! Test if set is empty at this moment
|
||||||
//! @note Thread safe
|
//! @note Thread safe
|
||||||
//! @warning see size()
|
//! @warning see size()
|
||||||
bool empty() const {
|
bool empty() const {
|
||||||
guard_type G(m_data->mutex);
|
guard_type G(_data->mutex);
|
||||||
return m_data->store.empty();
|
return _data->store.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! number of entries in the set at this moment
|
//! number of entries in the set at this moment
|
||||||
@ -145,8 +145,8 @@ public:
|
|||||||
//! @warning May be momentarily inaccurate (larger) due to dead refs.
|
//! @warning May be momentarily inaccurate (larger) due to dead refs.
|
||||||
//! which have not yet been removed.
|
//! which have not yet been removed.
|
||||||
size_t size() const {
|
size_t size() const {
|
||||||
guard_type G(m_data->mutex);
|
guard_type G(_data->mutex);
|
||||||
return m_data->store.size();
|
return _data->store.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! proxy class for lookup of non-const
|
//! proxy class for lookup of non-const
|
||||||
@ -167,8 +167,8 @@ public:
|
|||||||
{
|
{
|
||||||
if(!v.unique())
|
if(!v.unique())
|
||||||
throw std::invalid_argument("Only unique() references may be inserted");
|
throw std::invalid_argument("Only unique() references may be inserted");
|
||||||
value_pointer chainptr(v.get(), dtor(M.m_data, k, v));
|
value_pointer chainptr(v.get(), dtor(M._data, k, v));
|
||||||
M.m_data->store[k] = chainptr;
|
M._data->store[k] = chainptr;
|
||||||
v.swap(chainptr);
|
v.swap(chainptr);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
@ -215,9 +215,9 @@ public:
|
|||||||
value_pointer find(const K& k) const
|
value_pointer find(const K& k) const
|
||||||
{
|
{
|
||||||
value_pointer ret;
|
value_pointer ret;
|
||||||
guard_type G(m_data->mutex);
|
guard_type G(_data->mutex);
|
||||||
typename store_t::const_iterator it(m_data->store.find(k));
|
typename store_t::const_iterator it(_data->store.find(k));
|
||||||
if(it!=m_data->store.end()) {
|
if(it!=_data->store.end()) {
|
||||||
// may be nullptr if we race destruction
|
// may be nullptr if we race destruction
|
||||||
// as ref. count falls to zero before we can remove it
|
// as ref. count falls to zero before we can remove it
|
||||||
ret = it->second.lock();
|
ret = it->second.lock();
|
||||||
@ -230,9 +230,9 @@ public:
|
|||||||
value_pointer insert(const K& k, value_pointer& v)
|
value_pointer insert(const K& k, value_pointer& v)
|
||||||
{
|
{
|
||||||
value_pointer ret;
|
value_pointer ret;
|
||||||
guard_type G(m_data->mutex);
|
guard_type G(_data->mutex);
|
||||||
typename store_t::const_iterator it = m_data->store.find(k);
|
typename store_t::const_iterator it = _data->store.find(k);
|
||||||
if(it!=m_data->store.end())
|
if(it!=_data->store.end())
|
||||||
ret = it->second.lock();
|
ret = it->second.lock();
|
||||||
(*this)[k] = v;
|
(*this)[k] = v;
|
||||||
return ret;
|
return ret;
|
||||||
@ -243,9 +243,9 @@ public:
|
|||||||
lock_map_type lock_map() const
|
lock_map_type lock_map() const
|
||||||
{
|
{
|
||||||
lock_map_type ret;
|
lock_map_type ret;
|
||||||
guard_type G(m_data->mutex);
|
guard_type G(_data->mutex);
|
||||||
for(typename store_t::const_iterator it = m_data->store.begin(),
|
for(typename store_t::const_iterator it = _data->store.begin(),
|
||||||
end = m_data->store.end(); it!=end; ++it)
|
end = _data->store.end(); it!=end; ++it)
|
||||||
{
|
{
|
||||||
value_pointer P(it->second.lock);
|
value_pointer P(it->second.lock);
|
||||||
if(P) ret[it->first] = P;
|
if(P) ret[it->first] = P;
|
||||||
@ -259,10 +259,10 @@ public:
|
|||||||
lock_vector_type lock_vector() const
|
lock_vector_type lock_vector() const
|
||||||
{
|
{
|
||||||
lock_vector_type ret;
|
lock_vector_type ret;
|
||||||
guard_type G(m_data->mutex);
|
guard_type G(_data->mutex);
|
||||||
ret.reserve(m_data->store.size());
|
ret.reserve(_data->store.size());
|
||||||
for(typename store_t::const_iterator it = m_data->store.begin(),
|
for(typename store_t::const_iterator it = _data->store.begin(),
|
||||||
end = m_data->store.end(); it!=end; ++it)
|
end = _data->store.end(); it!=end; ++it)
|
||||||
{
|
{
|
||||||
value_pointer P(it->second.lock());
|
value_pointer P(it->second.lock());
|
||||||
if(P) ret.push_back(std::make_pair(it->first, P));
|
if(P) ret.push_back(std::make_pair(it->first, P));
|
||||||
@ -274,7 +274,7 @@ public:
|
|||||||
//! for use with batch operations.
|
//! for use with batch operations.
|
||||||
//! @warning Use caution when swap()ing while holding this lock!
|
//! @warning Use caution when swap()ing while holding this lock!
|
||||||
inline epicsMutex& mutex() const {
|
inline epicsMutex& mutex() const {
|
||||||
return m_data->mutex;
|
return _data->mutex;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ private:
|
|||||||
mutex_type mutex;
|
mutex_type mutex;
|
||||||
store_t store;
|
store_t store;
|
||||||
};
|
};
|
||||||
std::tr1::shared_ptr<data> m_data;
|
std::tr1::shared_ptr<data> _data;
|
||||||
|
|
||||||
//! Destroyer for a chained shared_ptr
|
//! Destroyer for a chained shared_ptr
|
||||||
//! which holds the unique() real strong
|
//! which holds the unique() real strong
|
||||||
@ -131,7 +131,7 @@ private:
|
|||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
//! Construct a new empty set
|
//! Construct a new empty set
|
||||||
weak_set() :m_data(new data) {}
|
weak_set() :_data(new data) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Not copyable
|
//! Not copyable
|
||||||
@ -143,22 +143,22 @@ public:
|
|||||||
//! exchange the two sets.
|
//! exchange the two sets.
|
||||||
//! @warning Not thread safe (exchanges mutexes as well)
|
//! @warning Not thread safe (exchanges mutexes as well)
|
||||||
void swap(weak_set& O) {
|
void swap(weak_set& O) {
|
||||||
m_data.swap(O.m_data);
|
_data.swap(O._data);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Remove all (weak) entries from the set
|
//! Remove all (weak) entries from the set
|
||||||
//! @note Thread safe
|
//! @note Thread safe
|
||||||
void clear() {
|
void clear() {
|
||||||
guard_type G(m_data->mutex);
|
guard_type G(_data->mutex);
|
||||||
return m_data->store.clear();
|
return _data->store.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Test if set is empty
|
//! Test if set is empty
|
||||||
//! @note Thread safe
|
//! @note Thread safe
|
||||||
//! @warning see size()
|
//! @warning see size()
|
||||||
bool empty() const {
|
bool empty() const {
|
||||||
guard_type G(m_data->mutex);
|
guard_type G(_data->mutex);
|
||||||
return m_data->store.empty();
|
return _data->store.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! number of entries in the set at this moment
|
//! number of entries in the set at this moment
|
||||||
@ -166,8 +166,8 @@ public:
|
|||||||
//! @warning May be momentarily inaccurate (larger) due to dead refs.
|
//! @warning May be momentarily inaccurate (larger) due to dead refs.
|
||||||
//! which have not yet been removed.
|
//! which have not yet been removed.
|
||||||
size_t size() const {
|
size_t size() const {
|
||||||
guard_type G(m_data->mutex);
|
guard_type G(_data->mutex);
|
||||||
return m_data->store.size();
|
return _data->store.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Insert a new entry into the set
|
//! Insert a new entry into the set
|
||||||
@ -178,8 +178,8 @@ public:
|
|||||||
//! Remove any (weak) ref to this object from the set
|
//! Remove any (weak) ref to this object from the set
|
||||||
//! @returns the number of objects removed (0 or 1)
|
//! @returns the number of objects removed (0 or 1)
|
||||||
size_t erase(value_pointer& v) {
|
size_t erase(value_pointer& v) {
|
||||||
guard_type G(m_data->mutex);
|
guard_type G(_data->mutex);
|
||||||
return m_data->store.erase(v);
|
return _data->store.erase(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Return a set of strong references to all entries
|
//! Return a set of strong references to all entries
|
||||||
@ -197,7 +197,7 @@ public:
|
|||||||
//! for use with batch operations.
|
//! for use with batch operations.
|
||||||
//! @warning Use caution when swap()ing while holding this lock!
|
//! @warning Use caution when swap()ing while holding this lock!
|
||||||
inline epicsMutex& mutex() const {
|
inline epicsMutex& mutex() const {
|
||||||
return m_data->mutex;
|
return _data->mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! an iterator-ish object which also locks the set during iteration
|
//! an iterator-ish object which also locks the set during iteration
|
||||||
@ -205,7 +205,7 @@ public:
|
|||||||
weak_set& set;
|
weak_set& set;
|
||||||
epicsGuard<epicsMutex> guard;
|
epicsGuard<epicsMutex> guard;
|
||||||
typename store_t::iterator it, end;
|
typename store_t::iterator it, end;
|
||||||
XIterator(weak_set& S) :set(S), guard(S.mutex()), it(S.m_data->store.begin()), end(S.m_data->store.end()) {}
|
XIterator(weak_set& S) :set(S), guard(S.mutex()), it(S._data->store.begin()), end(S._data->store.end()) {}
|
||||||
//! yield the next live entry
|
//! yield the next live entry
|
||||||
value_pointer next() {
|
value_pointer next() {
|
||||||
value_pointer ret;
|
value_pointer ret;
|
||||||
@ -229,14 +229,14 @@ void weak_set<T>::insert(value_pointer &v)
|
|||||||
if(!v.unique())
|
if(!v.unique())
|
||||||
throw std::invalid_argument("Only unique() references may be inserted");
|
throw std::invalid_argument("Only unique() references may be inserted");
|
||||||
|
|
||||||
guard_type G(m_data->mutex);
|
guard_type G(_data->mutex);
|
||||||
typename store_t::const_iterator it = m_data->store.find(v);
|
typename store_t::const_iterator it = _data->store.find(v);
|
||||||
if(it==m_data->store.end()) { // new object
|
if(it==_data->store.end()) { // new object
|
||||||
|
|
||||||
// wrapped strong ref. which removes from our map
|
// wrapped strong ref. which removes from our map
|
||||||
value_pointer chainptr(v.get(), dtor(m_data, v));
|
value_pointer chainptr(v.get(), dtor(_data, v));
|
||||||
|
|
||||||
m_data->store.insert(chainptr);
|
_data->store.insert(chainptr);
|
||||||
|
|
||||||
v.swap(chainptr); // we only keep the chained pointer
|
v.swap(chainptr); // we only keep the chained pointer
|
||||||
} else {
|
} else {
|
||||||
@ -253,9 +253,9 @@ typename weak_set<T>::set_type
|
|||||||
weak_set<T>::lock_set() const
|
weak_set<T>::lock_set() const
|
||||||
{
|
{
|
||||||
set_type ret;
|
set_type ret;
|
||||||
guard_type G(m_data->mutex);
|
guard_type G(_data->mutex);
|
||||||
for(typename store_t::const_iterator it=m_data->store.begin(),
|
for(typename store_t::const_iterator it=_data->store.begin(),
|
||||||
end=m_data->store.end(); it!=end; ++it)
|
end=_data->store.end(); it!=end; ++it)
|
||||||
{
|
{
|
||||||
value_pointer P(it->lock());
|
value_pointer P(it->lock());
|
||||||
if(P) ret.insert(P);
|
if(P) ret.insert(P);
|
||||||
@ -275,10 +275,10 @@ weak_set<T>::lock_vector() const
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void weak_set<T>::lock_vector(vector_type& ret) const
|
void weak_set<T>::lock_vector(vector_type& ret) const
|
||||||
{
|
{
|
||||||
guard_type G(m_data->mutex);
|
guard_type G(_data->mutex);
|
||||||
ret.reserve(m_data->store.size());
|
ret.reserve(_data->store.size());
|
||||||
for(typename store_t::const_iterator it=m_data->store.begin(),
|
for(typename store_t::const_iterator it=_data->store.begin(),
|
||||||
end=m_data->store.end(); it!=end; ++it)
|
end=_data->store.end(); it!=end; ++it)
|
||||||
{
|
{
|
||||||
value_pointer P(it->lock());
|
value_pointer P(it->lock());
|
||||||
if(P) ret.push_back(P);
|
if(P) ret.push_back(P);
|
||||||
|
Reference in New Issue
Block a user