summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
authorRichard Nelson <richard@lindenlab.com>2011-07-26 15:47:53 -0700
committerRichard Nelson <richard@lindenlab.com>2011-07-26 15:47:53 -0700
commit6b3a7480a137fa6db37f3d6e1b0235a282ecaa17 (patch)
treedca0c3f77ef2fd40109f10f6ab53f56ec48d90f9 /indra/llcommon
parent825fc273ee5167052d811dc058b1834c86e005da (diff)
parentdf82fbffa29428af258dc84ce2acbb07180f557e (diff)
merge
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/lleventtimer.cpp20
-rw-r--r--indra/llcommon/llfasttimer_class.cpp41
-rw-r--r--indra/llcommon/llinstancetracker.h157
-rw-r--r--indra/llcommon/tests/llinstancetracker_test.cpp7
4 files changed, 139 insertions, 86 deletions
diff --git a/indra/llcommon/lleventtimer.cpp b/indra/llcommon/lleventtimer.cpp
index 7743826c60..0d96e03da4 100644
--- a/indra/llcommon/lleventtimer.cpp
+++ b/indra/llcommon/lleventtimer.cpp
@@ -58,19 +58,15 @@ LLEventTimer::~LLEventTimer()
void LLEventTimer::updateClass()
{
std::list<LLEventTimer*> completed_timers;
-
+ for (instance_iter iter = beginInstances(); iter != endInstances(); )
{
- LLInstanceTrackerScopedGuard guard;
- for (instance_iter iter = guard.beginInstances(); iter != guard.endInstances(); )
- {
- LLEventTimer& timer = *iter++;
- F32 et = timer.mEventTimer.getElapsedTimeF32();
- if (timer.mEventTimer.getStarted() && et > timer.mPeriod) {
- timer.mEventTimer.reset();
- if ( timer.tick() )
- {
- completed_timers.push_back( &timer );
- }
+ LLEventTimer& timer = *iter++;
+ F32 et = timer.mEventTimer.getElapsedTimeF32();
+ if (timer.mEventTimer.getStarted() && et > timer.mPeriod) {
+ timer.mEventTimer.reset();
+ if ( timer.tick() )
+ {
+ completed_timers.push_back( &timer );
}
}
}
diff --git a/indra/llcommon/llfasttimer_class.cpp b/indra/llcommon/llfasttimer_class.cpp
index 675eda2fc5..ebb5961c91 100644
--- a/indra/llcommon/llfasttimer_class.cpp
+++ b/indra/llcommon/llfasttimer_class.cpp
@@ -219,22 +219,19 @@ LLFastTimer::DeclareTimer::DeclareTimer(const std::string& name)
// static
void LLFastTimer::DeclareTimer::updateCachedPointers()
{
- DeclareTimer::LLInstanceTrackerScopedGuard guard;
// propagate frame state pointers to timer declarations
- for (DeclareTimer::instance_iter it = guard.beginInstances();
- it != guard.endInstances();
- ++it)
+ for (instance_iter it = beginInstances(); it != endInstances(); ++it)
{
// update cached pointer
it->mFrameState = &it->mTimer.getFrameState();
}
- // also update frame states of timers on stack
- LLFastTimer* cur_timerp = LLFastTimer::sCurTimerData.mCurTimer;
- while(cur_timerp->mLastTimerData.mCurTimer != cur_timerp)
- {
- cur_timerp->mFrameState = &cur_timerp->mFrameState->mTimer->getFrameState();
- cur_timerp = cur_timerp->mLastTimerData.mCurTimer;
+ // also update frame states of timers on stack
+ LLFastTimer* cur_timerp = LLFastTimer::sCurTimerData.mCurTimer;
+ while(cur_timerp->mLastTimerData.mCurTimer != cur_timerp)
+ {
+ cur_timerp->mFrameState = &cur_timerp->mFrameState->mTimer->getFrameState();
+ cur_timerp = cur_timerp->mLastTimerData.mCurTimer;
}
}
@@ -396,10 +393,7 @@ void LLFastTimer::NamedTimer::buildHierarchy()
// set up initial tree
{
- NamedTimer::LLInstanceTrackerScopedGuard guard;
- for (instance_iter it = guard.beginInstances();
- it != guard.endInstances();
- ++it)
+ for (instance_iter it = beginInstances(); it != endInstances(); ++it)
{
NamedTimer& timer = *it;
if (&timer == NamedTimerFactory::instance().getRootTimer()) continue;
@@ -527,10 +521,7 @@ void LLFastTimer::NamedTimer::resetFrame()
LLSD sd;
{
- NamedTimer::LLInstanceTrackerScopedGuard guard;
- for (NamedTimer::instance_iter it = guard.beginInstances();
- it != guard.endInstances();
- ++it)
+ for (instance_iter it = beginInstances(); it != endInstances(); ++it)
{
NamedTimer& timer = *it;
FrameState& info = timer.getFrameState();
@@ -567,7 +558,7 @@ void LLFastTimer::NamedTimer::resetFrame()
llassert_always(timerp->mFrameStateIndex < (S32)getFrameStateList().size());
}
- // sort timers by dfs traversal order to improve cache coherency
+ // sort timers by DFS traversal order to improve cache coherency
std::sort(getFrameStateList().begin(), getFrameStateList().end(), SortTimersDFS());
// update pointers into framestatelist now that we've sorted it
@@ -575,10 +566,7 @@ void LLFastTimer::NamedTimer::resetFrame()
// reset for next frame
{
- NamedTimer::LLInstanceTrackerScopedGuard guard;
- for (NamedTimer::instance_iter it = guard.beginInstances();
- it != guard.endInstances();
- ++it)
+ for (instance_iter it = beginInstances(); it != endInstances(); ++it)
{
NamedTimer& timer = *it;
@@ -622,10 +610,7 @@ void LLFastTimer::NamedTimer::reset()
// reset all history
{
- NamedTimer::LLInstanceTrackerScopedGuard guard;
- for (NamedTimer::instance_iter it = guard.beginInstances();
- it != guard.endInstances();
- ++it)
+ for (instance_iter it = beginInstances(); it != endInstances(); ++it)
{
NamedTimer& timer = *it;
if (&timer != NamedTimerFactory::instance().getRootTimer())
@@ -873,7 +858,7 @@ std::string LLFastTimer::sClockType = "rdtsc";
#else
//LL_COMMON_API U64 get_clock_count(); // in lltimer.cpp
-// These use QueryPerformanceCounter, which is arguably fine and also works on amd architectures.
+// These use QueryPerformanceCounter, which is arguably fine and also works on AMD architectures.
U32 LLFastTimer::getCPUClockCount32()
{
return (U32)(get_clock_count()>>8);
diff --git a/indra/llcommon/llinstancetracker.h b/indra/llcommon/llinstancetracker.h
index b971b2f914..1ac6629f8a 100644
--- a/indra/llcommon/llinstancetracker.h
+++ b/indra/llcommon/llinstancetracker.h
@@ -52,13 +52,68 @@ class LLInstanceTracker : public LLInstanceTrackerBase
{
typedef typename std::map<KEY, T*> InstanceMap;
typedef LLInstanceTracker<T, KEY> MyT;
- typedef boost::function<const KEY&(typename InstanceMap::value_type&)> KeyGetter;
- typedef boost::function<T*(typename InstanceMap::value_type&)> InstancePtrGetter;
public:
- /// Dereferencing key_iter gives you a const KEY&
- typedef boost::transform_iterator<KeyGetter, typename InstanceMap::iterator> key_iter;
- /// Dereferencing instance_iter gives you a T&
- typedef boost::indirect_iterator< boost::transform_iterator<InstancePtrGetter, typename InstanceMap::iterator> > instance_iter;
+ class instance_iter : public boost::iterator_facade<instance_iter, T, boost::forward_traversal_tag>
+ {
+ public:
+ instance_iter(typename InstanceMap::iterator& it)
+ : mIterator(it)
+ {
+ ++sIterationNestDepth;
+ }
+
+ ~instance_iter()
+ {
+ --sIterationNestDepth;
+ }
+
+ private:
+ friend class boost::iterator_core_access;
+
+ void increment() { mIterator++; }
+ bool equal(instance_iter const& other) const
+ {
+ return mIterator == other.m_iterator;
+ }
+
+ T& dereference() const
+ {
+ return mIterator->second;
+ }
+
+ typename InstanceMap::iterator mIterator;
+ };
+
+ class key_iter : public boost::iterator_facade<key_iter, KEY, boost::forward_traversal_tag>
+ {
+ public:
+ key_iter(typename InstanceMap::iterator& it)
+ : mIterator(it)
+ {
+ ++sIterationNestDepth;
+ }
+
+ ~key_iter()
+ {
+ --sIterationNestDepth;
+ }
+
+ private:
+ friend class boost::iterator_core_access;
+
+ void increment() { mIterator++; }
+ bool equal(instance_iter const& other) const
+ {
+ return mIterator == other.m_iterator;
+ }
+
+ KEY& dereference() const
+ {
+ return mIterator->first;
+ }
+
+ typename InstanceMap::iterator mIterator;
+ };
static T* getInstance(const KEY& k)
{
@@ -66,42 +121,47 @@ public:
return (found == getMap_().end()) ? NULL : found->second;
}
- static key_iter beginKeys()
- {
- return boost::make_transform_iterator(getMap_().begin(),
- boost::bind(&InstanceMap::value_type::first, _1));
+ static instance_iter beginInstances()
+ {
+ return instance_iter(getMap_().begin());
}
- static key_iter endKeys()
+
+ static instance_iter endInstances()
{
- return boost::make_transform_iterator(getMap_().end(),
- boost::bind(&InstanceMap::value_type::first, _1));
+ return instance_iter(getMap_().end());
}
- static instance_iter beginInstances()
+
+ static S32 instanceCount() { return getMap_().size(); }
+
+ static key_iter beginKeys()
{
- return instance_iter(boost::make_transform_iterator(getMap_().begin(),
- boost::bind(&InstanceMap::value_type::second, _1)));
+ return key_iter(getMap_().begin());
}
- static instance_iter endInstances()
+ static key_iter endKeys()
{
- return instance_iter(boost::make_transform_iterator(getMap_().end(),
- boost::bind(&InstanceMap::value_type::second, _1)));
+ return key_iter(getMap_().end());
}
- static S32 instanceCount() { return getMap_().size(); }
+
protected:
LLInstanceTracker(KEY key) { add_(key); }
- virtual ~LLInstanceTracker() { remove_(); }
+ virtual ~LLInstanceTracker()
+ {
+ // it's unsafe to delete instances of this type while all instances are being iterated over.
+ llassert(sIterationNestDepth == 0);
+ remove_();
+ }
virtual void setKey(KEY key) { remove_(); add_(key); }
- virtual const KEY& getKey() const { return mKey; }
+ virtual const KEY& getKey() const { return mInstanceKey; }
private:
void add_(KEY key)
{
- mKey = key;
+ mInstanceKey = key;
getMap_()[key] = static_cast<T*>(this);
}
void remove_()
{
- getMap_().erase(mKey);
+ getMap_().erase(mInstanceKey);
}
static InstanceMap& getMap_()
@@ -116,9 +176,12 @@ private:
private:
- KEY mKey;
+ KEY mInstanceKey;
+ static S32 sIterationNestDepth;
};
+template <typename T, typename KEY> S32 LLInstanceTracker<T, KEY>::sIterationNestDepth = 0;
+
/// explicit specialization for default case where KEY is T*
/// use a simple std::set<T*>
template<typename T>
@@ -127,42 +190,55 @@ class LLInstanceTracker<T, T*> : public LLInstanceTrackerBase
typedef typename std::set<T*> InstanceSet;
typedef LLInstanceTracker<T, T*> MyT;
public:
- /// Dereferencing key_iter gives you a T* (since T* is the key)
- typedef typename InstanceSet::iterator key_iter;
- /// Dereferencing instance_iter gives you a T&
- typedef boost::indirect_iterator<key_iter> instance_iter;
/// for completeness of analogy with the generic implementation
static T* getInstance(T* k) { return k; }
static S32 instanceCount() { return getSet_().size(); }
- // Instantiate this to get access to iterators for this type. It's a 'guard' in the sense
- // that it treats deletes of this type as errors as long as there is an instance of
- // this class alive in scope somewhere (i.e. deleting while iterating is bad).
- class LLInstanceTrackerScopedGuard
+ class instance_iter : public boost::iterator_facade<instance_iter, T, boost::forward_traversal_tag>
{
public:
- LLInstanceTrackerScopedGuard()
+ instance_iter(typename InstanceSet::iterator& it)
+ : mIterator(it)
+ {
+ ++sIterationNestDepth;
+ }
+
+ instance_iter(const instance_iter& other)
+ : mIterator(other.mIterator)
{
++sIterationNestDepth;
}
- ~LLInstanceTrackerScopedGuard()
+ ~instance_iter()
{
--sIterationNestDepth;
}
- static instance_iter beginInstances() { return instance_iter(getSet_().begin()); }
- static instance_iter endInstances() { return instance_iter(getSet_().end()); }
- static key_iter beginKeys() { return getSet_().begin(); }
- static key_iter endKeys() { return getSet_().end(); }
+ private:
+ friend class boost::iterator_core_access;
+
+ void increment() { mIterator++; }
+ bool equal(instance_iter const& other) const
+ {
+ return mIterator == other.mIterator;
+ }
+
+ T& dereference() const
+ {
+ return **mIterator;
+ }
+
+ typename InstanceSet::iterator mIterator;
};
+ static instance_iter beginInstances() { return instance_iter(getSet_().begin()); }
+ static instance_iter endInstances() { return instance_iter(getSet_().end()); }
+
protected:
LLInstanceTracker()
{
// it's safe but unpredictable to create instances of this type while all instances are being iterated over. I hate unpredictable. This assert will probably be turned on early in the next development cycle.
- //llassert(sIterationNestDepth == 0);
getSet_().insert(static_cast<T*>(this));
}
virtual ~LLInstanceTracker()
@@ -174,7 +250,6 @@ protected:
LLInstanceTracker(const LLInstanceTracker& other)
{
- //llassert(sIterationNestDepth == 0);
getSet_().insert(static_cast<T*>(this));
}
diff --git a/indra/llcommon/tests/llinstancetracker_test.cpp b/indra/llcommon/tests/llinstancetracker_test.cpp
index c7cb488ca1..af55341e1f 100644
--- a/indra/llcommon/tests/llinstancetracker_test.cpp
+++ b/indra/llcommon/tests/llinstancetracker_test.cpp
@@ -156,8 +156,7 @@ namespace tut
keys.insert(&two);
keys.insert(&three);
{
- Unkeyed::LLInstanceTrackerScopedGuard guard;
- for (Unkeyed::key_iter ki(guard.beginKeys()), kend(guard.endKeys());
+ for (Unkeyed::key_iter ki(beginKeys()), kend(endKeys());
ki != kend; ++ki)
{
ensure_equals("spurious key", keys.erase(*ki), 1);
@@ -170,9 +169,7 @@ namespace tut
instances.insert(&two);
instances.insert(&three);
{
- Unkeyed::LLInstanceTrackerScopedGuard guard;
- for (Unkeyed::instance_iter ii(guard.beginInstances()), iend(guard.endInstances());
- ii != iend; ++ii)
+ for (Unkeyed::instance_iter ii(beginInstances()), iend(endInstances()); ii != iend; ++ii)
{
Unkeyed& ref = *ii;
ensure_equals("spurious instance", instances.erase(&ref), 1);