single shot and reusable timers for xlib. Not yet part of build. Thanks to faulkner@igelaus.com.au

This commit is contained in:
quy%igelaus.com.au 2000-08-29 06:20:07 +00:00
Родитель ccae14bc01
Коммит 56ef0c603c
2 изменённых файлов: 33 добавлений и 15 удалений

Просмотреть файл

@ -55,6 +55,7 @@ nsTimerXlib::nsTimerXlib()
mCallback = NULL; mCallback = NULL;
mNext = NULL; mNext = NULL;
mClosure = NULL; mClosure = NULL;
mType = NS_TYPE_ONE_SHOT;
} }
nsTimerXlib::~nsTimerXlib() nsTimerXlib::~nsTimerXlib()
@ -77,6 +78,7 @@ nsTimerXlib::Init(nsTimerCallbackFunc aFunc,
{ {
mFunc = aFunc; mFunc = aFunc;
mClosure = aClosure; mClosure = aClosure;
mType = aType;
return Init(aDelay); return Init(aDelay);
} }
@ -87,6 +89,7 @@ nsTimerXlib::Init(nsITimerCallback *aCallback,
PRUint32 aType PRUint32 aType
) )
{ {
mType = aType;
mCallback = aCallback; mCallback = aCallback;
NS_ADDREF(mCallback); NS_ADDREF(mCallback);
@ -100,6 +103,7 @@ nsTimerXlib::Init(PRUint32 aDelay)
// printf("nsTimerXlib::Init (%p) called with delay %d\n", // printf("nsTimerXlib::Init (%p) called with delay %d\n",
//this, aDelay); //this, aDelay);
// get the cuurent time // get the cuurent time
mDelay = aDelay;
gettimeofday(&Now, NULL); gettimeofday(&Now, NULL);
mFireTime.tv_sec = Now.tv_sec + (aDelay / 1000); mFireTime.tv_sec = Now.tv_sec + (aDelay / 1000);
mFireTime.tv_usec = Now.tv_usec + ((aDelay%1000) * 1000); mFireTime.tv_usec = Now.tv_usec + ((aDelay%1000) * 1000);
@ -147,9 +151,10 @@ nsTimerXlib::Init(PRUint32 aDelay)
return NS_OK; return NS_OK;
} }
void PRBool
nsTimerXlib::Fire(struct timeval *aNow) nsTimerXlib::Fire(struct timeval *aNow)
{ {
nsCOMPtr<nsITimer> kungFuDeathGrip = this;
// printf("nsTimerXlib::Fire (%p) called at %ld / %ld\n", // printf("nsTimerXlib::Fire (%p) called at %ld / %ld\n",
// this, // this,
//aNow->tv_sec, aNow->tv_usec); //aNow->tv_sec, aNow->tv_usec);
@ -159,6 +164,8 @@ nsTimerXlib::Fire(struct timeval *aNow)
else if (mCallback != NULL) { else if (mCallback != NULL) {
mCallback->Notify(this); mCallback->Notify(this);
} }
return ((mType == NS_TYPE_REPEATING_SLACK) || (mType == NS_TYPE_REPEATING_PRECISE));
} }
void void
@ -195,6 +202,10 @@ void
nsTimerXlib::ProcessTimeouts(struct timeval *aNow) nsTimerXlib::ProcessTimeouts(struct timeval *aNow)
{ {
nsTimerXlib *p = gTimerList; nsTimerXlib *p = gTimerList;
nsTimerXlib *tmp;
struct timeval ntv;
int res;
if (aNow->tv_sec == 0 && if (aNow->tv_sec == 0 &&
aNow->tv_usec == 0) { aNow->tv_usec == 0) {
gettimeofday(aNow, NULL); gettimeofday(aNow, NULL);
@ -211,15 +222,21 @@ nsTimerXlib::ProcessTimeouts(struct timeval *aNow)
//printf("Firing timeout for (%p)\n", //printf("Firing timeout for (%p)\n",
// p); // p);
NS_ADDREF(p); NS_ADDREF(p);
p->Fire(aNow); res = p->Fire(aNow);
// Clear the timer. if (res == 0) {
// Period synced.
p->Cancel(); p->Cancel();
NS_RELEASE(p); NS_RELEASE(p);
// Reset the loop (can't look at p->pNext now, and called
// code may have added/cleared timers).
// (could do this by going recursive and returning).
p = gTimerList; p = gTimerList;
} else {
gettimeofday(&ntv, NULL);
p->mFireTime.tv_sec = ntv.tv_sec + (p->mDelay / 1000);
p->mFireTime.tv_usec = ntv.tv_usec + ((p->mDelay%1000) * 1000);
tmp = p;
p = p->mNext;
NS_RELEASE(tmp);
}
} }
else { else {
p = p->mNext; p = p->mNext;

Просмотреть файл

@ -54,7 +54,7 @@ public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
virtual void Cancel(); virtual void Cancel();
void Fire(struct timeval *aNow); PRBool Fire(struct timeval *aNow);
virtual PRUint32 GetDelay() { return 0; }; virtual PRUint32 GetDelay() { return 0; };
virtual void SetDelay(PRUint32 aDelay) {}; virtual void SetDelay(PRUint32 aDelay) {};
@ -76,6 +76,7 @@ private:
nsresult Init(PRUint32 aDelay); nsresult Init(PRUint32 aDelay);
nsresult EnsureWindowService(); nsresult EnsureWindowService();
PRUint32 mType;
nsTimerCallbackFunc mFunc; nsTimerCallbackFunc mFunc;
void * mClosure; void * mClosure;
PRUint32 mDelay; PRUint32 mDelay;