Added caution about accuracy of the std::clock() function of RateLimitedPolicy under linux and Cygwin environnement.

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@781 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
clitte_bbt 2006-11-20 23:43:08 +00:00
parent f6e7714eca
commit 1ecc9448b9

View file

@ -166,6 +166,10 @@ namespace Loki
* Use the setRate method to set the rate parameters. * Use the setRate method to set the rate parameters.
* default is 10 objects in a second. * default is 10 objects in a second.
*/ */
// !! CAUTION !!
// The std::clock() function is not quite precise
// under linux this policy might not work.
// TODO : get a better implementation (platform dependant)
class RateLimitedCreation class RateLimitedCreation
{ {
private: private:
@ -177,7 +181,7 @@ namespace Loki
void cleanVector() void cleanVector()
{ {
clock_t currentTime = std::clock(); clock_t currentTime = clock();
D( cout << "currentTime = " << currentTime<< endl; ) D( cout << "currentTime = " << currentTime<< endl; )
D( cout << "currentTime - lastUpdate = " << currentTime - lastUpdate<< endl; ) D( cout << "currentTime - lastUpdate = " << currentTime - lastUpdate<< endl; )
if(currentTime - lastUpdate > timeValidity) if(currentTime - lastUpdate > timeValidity)
@ -207,7 +211,7 @@ namespace Loki
cout << endl; cout << endl;
} }
protected: protected:
RateLimitedCreation() : maxCreation(10), timeValidity(CLOCKS_PER_SEC), lastUpdate(std::clock()) RateLimitedCreation() : maxCreation(10), timeValidity(CLOCKS_PER_SEC), lastUpdate(clock())
{} {}
struct Exception : public std::exception struct Exception : public std::exception
@ -226,7 +230,7 @@ namespace Loki
void onCreate() void onCreate()
{ {
m_vTimes.push_back(std::clock()); m_vTimes.push_back(clock());
} }
void onDestroy() void onDestroy()