Skip to content

Commit

Permalink
Protect functions that throw away const-ness (check dirty flag) with …
Browse files Browse the repository at this point in the history
…mutex
  • Loading branch information
RainCT authored and Paul Mathieu committed Sep 9, 2014
1 parent 3399878 commit 978a31a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
20 changes: 18 additions & 2 deletions include/open_karto/Karto.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <boost/thread.hpp>

#ifdef USE_POCO
#include <Poco/Mutex.h>
Expand Down Expand Up @@ -5119,7 +5120,10 @@ namespace karto
{
}

public:
private:
mutable boost::shared_mutex m_Lock;

public:
/**
* Gets the odometric pose of this scan
* @return odometric pose of this scan
Expand Down Expand Up @@ -5167,9 +5171,12 @@ namespace karto
*/
inline const Pose2& GetBarycenterPose() const
{
boost::shared_lock<boost::shared_mutex> lock(m_Lock);
if (m_IsDirty)
{
// throw away constness and do an update!
lock.unlock();
boost::unique_lock<boost::shared_mutex> uniqueLock(m_Lock);
const_cast<LocalizedRangeScan*>(this)->Update();
}

Expand All @@ -5183,9 +5190,12 @@ namespace karto
*/
inline Pose2 GetReferencePose(kt_bool useBarycenter) const
{
boost::shared_lock<boost::shared_mutex> lock(m_Lock);
if (m_IsDirty)
{
// throw away constness and do an update!
lock.unlock();
boost::unique_lock<boost::shared_mutex> uniqueLock(m_Lock);
const_cast<LocalizedRangeScan*>(this)->Update();
}

Expand Down Expand Up @@ -5237,9 +5247,12 @@ namespace karto
*/
inline const BoundingBox2& GetBoundingBox() const
{
boost::shared_lock<boost::shared_mutex> lock(m_Lock);
if (m_IsDirty)
{
// throw away constness and do an update!
lock.unlock();
boost::unique_lock<boost::shared_mutex> uniqueLock(m_Lock);
const_cast<LocalizedRangeScan*>(this)->Update();
}

Expand All @@ -5251,9 +5264,12 @@ namespace karto
*/
inline const PointVectorDouble& GetPointReadings(kt_bool wantFiltered = false) const
{
boost::shared_lock<boost::shared_mutex> lock(m_Lock);
if (m_IsDirty)
{
// throw away constness and do an update!
lock.unlock();
boost::unique_lock<boost::shared_mutex> uniqueLock(m_Lock);
const_cast<LocalizedRangeScan*>(this)->Update();
}

Expand All @@ -5267,7 +5283,7 @@ namespace karto
}
}

private:
private:
/**
* Compute point readings based on range readings
* Only range readings within [minimum range; range threshold] are returned
Expand Down
5 changes: 5 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
<license>LGPLv3</license>

<buildtool_depend>catkin</buildtool_depend>

<build_depend>boost</build_depend>

<run_depend>boost</run_depend>

</package>

0 comments on commit 978a31a

Please sign in to comment.