Skip to content
Snippets Groups Projects
Commit 4c7ae599 authored by Tofu Linden's avatar Tofu Linden
Browse files

move LLEventTimer into its own source module. everyone includes it, almost...

move LLEventTimer into its own source module.  everyone includes it, almost no-one wants it.  now I can dick with it a bit without rebuilding the world, at least. :)
parent dfdd4a5e
No related branches found
No related tags found
No related merge requests found
...@@ -50,6 +50,7 @@ set(llcommon_SOURCE_FILES ...@@ -50,6 +50,7 @@ set(llcommon_SOURCE_FILES
lleventdispatcher.cpp lleventdispatcher.cpp
lleventfilter.cpp lleventfilter.cpp
llevents.cpp llevents.cpp
lleventtimer.cpp
llfasttimer_class.cpp llfasttimer_class.cpp
llfile.cpp llfile.cpp
llfindlocale.cpp llfindlocale.cpp
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#include "lllivefile.h" #include "lllivefile.h"
#include "llmemory.h" #include "llmemory.h"
#include "llstl.h" // for DeletePointer() #include "llstl.h" // for DeletePointer()
#include "lltimer.h" #include "lleventtimer.h"
// //
// Signal handling // Signal handling
......
/**
* @file lleventtimer.cpp
* @brief Cross-platform objects for doing timing
*
* $LicenseInfo:firstyear=2000&license=viewergpl$
*
* Copyright (c) 2000-2009, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "lleventtimer.h"
#include "u64.h"
//////////////////////////////////////////////////////////////////////////////
//
// LLEventTimer Implementation
//
//////////////////////////////////////////////////////////////////////////////
bool LLEventTimer::sInTickLoop = false;
LLEventTimer::LLEventTimer(F32 period)
: mEventTimer()
{
mPeriod = period;
}
LLEventTimer::LLEventTimer(const LLDate& time)
: mEventTimer()
{
mPeriod = (F32)(time.secondsSinceEpoch() - LLDate::now().secondsSinceEpoch());
}
LLEventTimer::~LLEventTimer()
{
llassert(!LLEventTimer::sInTickLoop); // this LLEventTimer was destroyed from within its own tick() function - bad. if you want tick() to cause destruction of its own timer, make it return true.
}
//static
void LLEventTimer::updateClass()
{
std::list<LLEventTimer*> completed_timers;
LLEventTimer::sInTickLoop = true;
for (instance_iter iter = beginInstances(); iter != 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::sInTickLoop = false;
if ( completed_timers.size() > 0 )
{
for (std::list<LLEventTimer*>::iterator completed_iter = completed_timers.begin();
completed_iter != completed_timers.end();
completed_iter++ )
{
delete *completed_iter;
}
}
}
/**
* @file lleventtimer.h
* @brief Cross-platform objects for doing timing
*
* $LicenseInfo:firstyear=2000&license=viewergpl$
*
* Copyright (c) 2000-2009, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#ifndef LL_EVENTTIMER_H
#define LL_EVENTTIMER_H
#include "stdtypes.h"
#include "lldate.h"
#include "llinstancetracker.h"
#include "lltimer.h"
// class for scheduling a function to be called at a given frequency (approximate, inprecise)
class LL_COMMON_API LLEventTimer : protected LLInstanceTracker<LLEventTimer>
{
public:
LLEventTimer(F32 period); // period is the amount of time between each call to tick() in seconds
LLEventTimer(const LLDate& time);
virtual ~LLEventTimer();
//function to be called at the supplied frequency
// Normally return FALSE; TRUE will delete the timer after the function returns.
virtual BOOL tick() = 0;
static void updateClass();
protected:
LLTimer mEventTimer;
F32 mPeriod;
static bool sInTickLoop;
};
#endif //LL_EVENTTIMER_H
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#include "lllivefile.h" #include "lllivefile.h"
#include "llframetimer.h" #include "llframetimer.h"
#include "lltimer.h" #include "lleventtimer.h"
const F32 DEFAULT_CONFIG_FILE_REFRESH = 5.0f; const F32 DEFAULT_CONFIG_FILE_REFRESH = 5.0f;
......
...@@ -555,59 +555,3 @@ void secondsToTimecodeString(F32 current_time, std::string& tcstring) ...@@ -555,59 +555,3 @@ void secondsToTimecodeString(F32 current_time, std::string& tcstring)
} }
//////////////////////////////////////////////////////////////////////////////
//
// LLEventTimer Implementation
//
//////////////////////////////////////////////////////////////////////////////
bool LLEventTimer::sInTickLoop = false;
LLEventTimer::LLEventTimer(F32 period)
: mEventTimer()
{
mPeriod = period;
}
LLEventTimer::LLEventTimer(const LLDate& time)
: mEventTimer()
{
mPeriod = (F32)(time.secondsSinceEpoch() - LLDate::now().secondsSinceEpoch());
}
LLEventTimer::~LLEventTimer()
{
llassert(!LLEventTimer::sInTickLoop); // this LLEventTimer was destroyed from within its own tick() function - bad. if you want tick() to cause destruction of its own timer, make it return true.
}
//static
void LLEventTimer::updateClass()
{
std::list<LLEventTimer*> completed_timers;
LLEventTimer::sInTickLoop = true;
for (instance_iter iter = beginInstances(); iter != 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::sInTickLoop = false;
if ( completed_timers.size() > 0 )
{
for (std::list<LLEventTimer*>::iterator completed_iter = completed_timers.begin();
completed_iter != completed_timers.end();
completed_iter++ )
{
delete *completed_iter;
}
}
}
...@@ -39,8 +39,6 @@ ...@@ -39,8 +39,6 @@
#include <limits.h> #include <limits.h>
#include "stdtypes.h" #include "stdtypes.h"
#include "lldate.h"
#include "llinstancetracker.h"
#include <string> #include <string>
#include <list> #include <list>
...@@ -171,26 +169,6 @@ LL_COMMON_API struct tm* utc_to_pacific_time(time_t utc_time, BOOL pacific_dayli ...@@ -171,26 +169,6 @@ LL_COMMON_API struct tm* utc_to_pacific_time(time_t utc_time, BOOL pacific_dayli
LL_COMMON_API void microsecondsToTimecodeString(U64 current_time, std::string& tcstring); LL_COMMON_API void microsecondsToTimecodeString(U64 current_time, std::string& tcstring);
LL_COMMON_API void secondsToTimecodeString(F32 current_time, std::string& tcstring); LL_COMMON_API void secondsToTimecodeString(F32 current_time, std::string& tcstring);
// class for scheduling a function to be called at a given frequency (approximate, inprecise)
class LL_COMMON_API LLEventTimer : protected LLInstanceTracker<LLEventTimer>
{
public:
LLEventTimer(F32 period); // period is the amount of time between each call to tick() in seconds
LLEventTimer(const LLDate& time);
virtual ~LLEventTimer();
//function to be called at the supplied frequency
// Normally return FALSE; TRUE will delete the timer after the function returns.
virtual BOOL tick() = 0;
static void updateClass();
protected:
LLTimer mEventTimer;
F32 mPeriod;
static bool sInTickLoop;
};
U64 LL_COMMON_API totalTime(); // Returns current system time in microseconds U64 LL_COMMON_API totalTime(); // Returns current system time in microseconds
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment