fix weakmap/set lock delegation

This commit is contained in:
Michael Davidsaver
2015-12-08 17:10:09 -05:00
parent 7de48f0bda
commit 14bcd4a4d1
3 changed files with 25 additions and 2 deletions

View File

@ -257,6 +257,13 @@ public:
}
return ret;
}
//! Access to the weak_set internal lock
//! for use with batch operations.
//! @warning Use caution when swap()ing while holding this lock!
inline epicsMutex& mutex() const {
return m_data->mutex;
}
};
#endif // WEAKMAP_H

View File

@ -191,8 +191,8 @@ public:
//! Access to the weak_set internal lock
//! for use with batch operations.
//! @warning Use caution when swap()ing while holding this lock!
inline guard_type lock() const {
return guard_type(m_data->mutex);
inline epicsMutex& mutex() const {
return m_data->mutex;
}
};

View File

@ -150,6 +150,21 @@ void testWeakMap2()
testOk1(!!ptr);
}
static
void testWeakLock()
{
typedef weak_value_map<int,int> map_type;
map_type::value_pointer ptr;
map_type map;
{
map_type::guard_type G(map.mutex());
ptr.reset(new int(42));
map[4] = ptr;
}
}
} // namespace
MAIN(testweak)
@ -160,5 +175,6 @@ MAIN(testweak)
testWeakSetInvalid();
testWeakMap1();
testWeakMap2();
testWeakLock();
return testDone();
}