summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/llframetimer.cpp44
-rw-r--r--indra/llcommon/llframetimer.h15
-rw-r--r--indra/llcommon/llmemory.cpp5
-rw-r--r--indra/llcommon/llmemory.h81
4 files changed, 87 insertions, 58 deletions
diff --git a/indra/llcommon/llframetimer.cpp b/indra/llcommon/llframetimer.cpp
index c66410651f..fca2bd2e85 100644
--- a/indra/llcommon/llframetimer.cpp
+++ b/indra/llcommon/llframetimer.cpp
@@ -33,6 +33,50 @@ void LLFrameTimer::updateFrameTime()
sFrameCount++;
}
+void LLFrameTimer::start()
+{
+ reset();
+ mStarted = TRUE;
+}
+
+void LLFrameTimer::stop()
+{
+ mStarted = FALSE;
+}
+
+void LLFrameTimer::reset()
+{
+ mStartTime = sFrameTime;
+ mExpiry = sFrameTime;
+}
+
+// Don't combine pause/unpause with start/stop
+// Useage:
+// LLFrameTime foo; // starts automatically
+// foo.unpause(); // noop but safe
+// foo.pause(); // pauses timer
+// foo.unpause() // unpauses
+// F32 elapsed = foo.getElapsedTimeF32() // does not include time between pause() and unpause()
+// Note: elapsed would also be valid with no unpause() call (= time run until pause() called)
+void LLFrameTimer::pause()
+{
+ if (mStarted)
+ mStartTime = sFrameTime - mStartTime; // save dtime
+ mStarted = FALSE;
+}
+
+void LLFrameTimer::unpause()
+{
+ if (!mStarted)
+ mStartTime = sFrameTime - mStartTime; // restore dtime
+ mStarted = TRUE;
+}
+
+void LLFrameTimer::setTimerExpirySec(F32 expiration)
+{
+ mExpiry = expiration + mStartTime;
+}
+
void LLFrameTimer::setExpiryAt(F64 seconds_since_epoch)
{
mStartTime = sFrameTime;
diff --git a/indra/llcommon/llframetimer.h b/indra/llcommon/llframetimer.h
index 05b01e6a72..c7c1c50c7b 100644
--- a/indra/llcommon/llframetimer.h
+++ b/indra/llcommon/llframetimer.h
@@ -44,8 +44,7 @@ public:
return sTotalSeconds;
}
- // Call this method once per frame to update the current frame
- // time.
+ // Call this method once per frame to update the current frame time.
static void updateFrameTime();
static S32 getFrameCount() { return sFrameCount; }
@@ -53,10 +52,12 @@ public:
static F32 getFrameDeltaTimeF32();
// MANIPULATORS
- void start() { reset(); mStarted = TRUE; }
- void stop() { mStarted = FALSE; }
- void reset() { mStartTime = sFrameTime; mExpiry = sFrameTime; }
- void setTimerExpirySec(F32 expiration) { mExpiry = expiration + mStartTime; }
+ void start();
+ void stop();
+ void reset();
+ void pause();
+ void unpause();
+ void setTimerExpirySec(F32 expiration);
void setExpiryAt(F64 seconds_since_epoch);
BOOL checkExpirationAndReset(F32 expiration);
F32 getElapsedTimeAndResetF32() { F32 t = F32(sFrameTime - mStartTime); reset(); return t; }
@@ -66,7 +67,7 @@ public:
// ACCESSORS
BOOL hasExpired() const { return (sFrameTime >= mExpiry); }
F32 getTimeToExpireF32() const { return (F32)(mExpiry - sFrameTime); }
- F32 getElapsedTimeF32() const { return (F32)(sFrameTime - mStartTime); }
+ F32 getElapsedTimeF32() const { return mStarted ? (F32)(sFrameTime - mStartTime) : (F32)mStartTime; }
BOOL getStarted() const { return mStarted; }
// return the seconds since epoch when this timer will expire.
diff --git a/indra/llcommon/llmemory.cpp b/indra/llcommon/llmemory.cpp
index 1063de5a8c..addda19775 100644
--- a/indra/llcommon/llmemory.cpp
+++ b/indra/llcommon/llmemory.cpp
@@ -11,11 +11,6 @@
#include "llmemory.h"
#include "llmemtype.h"
-// not defining nullfunc will currently crash when trying to use a LLHandle
-template< typename _Ty >
- const typename LLHandle< _Ty >::NullFunc
- LLHandle< _Ty >::sNullFunc = LLHandle< _Ty >::defaultNullFunc;
-
//----------------------------------------------------------------------------
//static
diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h
index f7f4818740..2a58db659e 100644
--- a/indra/llcommon/llmemory.h
+++ b/indra/llcommon/llmemory.h
@@ -220,29 +220,28 @@ class LLHandle
{
public:
LLHandle() :
- mPointer(sNullFunc())
+ mPointer(NULL)
{
- ref();
}
LLHandle(Type* ptr) :
- mPointer(nonNull(ptr))
+ mPointer(NULL)
{
- ref();
+ assign(ptr);
}
LLHandle(const LLHandle<Type>& ptr) :
- mPointer(ptr.mPointer)
+ mPointer(NULL)
{
- ref();
+ assign(ptr.mPointer);
}
// support conversion up the type hierarchy. See Item 45 in Effective C++, 3rd Ed.
template<typename Subclass>
LLHandle(const LLHandle<Subclass>& ptr) :
- mPointer(ptr.get())
+ mPointer(NULL)
{
- ref();
+ assign(ptr.get());
}
~LLHandle()
@@ -250,47 +249,39 @@ public:
unref();
}
+ const Type* operator->() const { return nonNull(mPointer); }
+ Type* operator->() { return nonNull(mPointer); }
+
Type* get() const { return mPointer; }
- const Type* operator->() const { return mPointer; }
- Type* operator->() { return mPointer; }
- const Type& operator*() const { return *mPointer; }
- Type& operator*() { return *mPointer; }
+ // we disallow these operations as they expose our null objects to direct manipulation
+ // and bypass the reference counting semantics
+ //const Type& operator*() const { return *nonNull(mPointer); }
+ //Type& operator*() { return *nonNull(mPointer); }
- operator BOOL() const { return (mPointer != sNullFunc()); }
- operator bool() const { return (mPointer != sNullFunc()); }
- bool operator!() const { return (mPointer == sNullFunc()); }
- bool isNull() const { return (mPointer == sNullFunc()); }
- bool notNull() const { return (mPointer != sNullFunc()); }
+ operator BOOL() const { return mPointer != NULL; }
+ operator bool() const { return mPointer != NULL; }
+ bool operator!() const { return mPointer == NULL; }
+ bool isNull() const { return mPointer == NULL; }
+ bool notNull() const { return mPointer != NULL; }
operator Type*() const { return mPointer; }
operator const Type*() const { return mPointer; }
- bool operator !=(Type* ptr) const { return (mPointer != nonNull(ptr)); }
- bool operator ==(Type* ptr) const { return (mPointer == nonNull(ptr)); }
+ bool operator !=(Type* ptr) const { return (mPointer != ptr); }
+ bool operator ==(Type* ptr) const { return (mPointer == ptr); }
bool operator ==(const LLHandle<Type>& ptr) const { return (mPointer == ptr.mPointer); }
bool operator < (const LLHandle<Type>& ptr) const { return (mPointer < ptr.mPointer); }
bool operator > (const LLHandle<Type>& ptr) const { return (mPointer > ptr.mPointer); }
LLHandle<Type>& operator =(Type* ptr)
{
- if( mPointer != ptr )
- {
- unref();
- mPointer = nonNull(ptr);
- ref();
- }
-
+ assign(ptr);
return *this;
}
LLHandle<Type>& operator =(const LLHandle<Type>& ptr)
{
- if( mPointer != ptr.mPointer )
- {
- unref();
- mPointer = ptr.mPointer;
- ref();
- }
+ assign(ptr.mPointer);
return *this;
}
@@ -298,12 +289,7 @@ public:
template<typename Subclass>
LLHandle<Type>& operator =(const LLHandle<Subclass>& ptr)
{
- if( mPointer != ptr.get() )
- {
- unref();
- mPointer = ptr.get();
- ref();
- }
+ assign(ptr.get());
return *this;
}
@@ -325,9 +311,9 @@ protected:
if (mPointer)
{
Type *tempp = mPointer;
- mPointer = sNullFunc();
+ mPointer = NULL;
tempp->unref();
- if (mPointer != sNullFunc())
+ if (mPointer != NULL)
{
llwarns << "Unreference did assignment to non-NULL because of destructor" << llendl;
unref();
@@ -335,19 +321,22 @@ protected:
}
}
- static Type* nonNull(Type* ptr)
+ void assign(Type* ptr)
{
- return ptr == NULL ? sNullFunc() : ptr;
+ if( mPointer != ptr )
+ {
+ unref();
+ mPointer = ptr;
+ ref();
+ }
}
- static Type* defaultNullFunc()
+ static Type* nonNull(Type* ptr)
{
- llerrs << "No null value provided for LLHandle" << llendl;
- return NULL;
+ return ptr == NULL ? sNullFunc() : ptr;
}
protected:
-
Type* mPointer;
};