backing out changes for 129953...

git-svn-id: svn://10.0.0.236/trunk@118729 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
pavlov%netscape.com
2002-04-11 05:38:55 +00:00
parent a770b81658
commit 63ff0ed4b4
7 changed files with 28 additions and 203 deletions

View File

@@ -36,17 +36,10 @@
#include "nsTimerImpl.h"
#include "TimerThread.h"
#include "nsSupportsArray.h"
#include "nsIEventQueue.h"
static TimerThread *gThread = nsnull;
// only the main thread supports idle timers.
static nsSupportsArray *gIdleTimers = nsnull;
static PRBool gFireOnIdle = PR_FALSE;
#include "prmem.h"
#include "prinit.h"
@@ -200,9 +193,6 @@ void nsTimerImpl::Shutdown()
gThread->Shutdown();
NS_RELEASE(gThread);
gFireOnIdle = PR_FALSE;
NS_IF_RELEASE(gIdleTimers);
}
@@ -295,11 +285,11 @@ NS_IMETHODIMP_(void) nsTimerImpl::SetType(PRUint32 aType)
{
mType = (PRUint8)aType;
// XXX if this is called, we should change the actual type.. this could effect
// repeating timers. we need to ensure in Fire() that if mType has changed
// repeating timers. we need to ensure in Process() that if mType has changed
// during the callback that we don't end up with the timer in the queue twice.
}
void nsTimerImpl::Fire()
void nsTimerImpl::Process()
{
if (mCanceled)
return;
@@ -327,7 +317,7 @@ void nsTimerImpl::Fire()
PRIntervalTime timeout = mTimeout;
if (mType == NS_TYPE_REPEATING_PRECISE) {
// Precise repeating timers advance mTimeout by mDelay without fail before
// calling Fire().
// calling Process().
timeout -= mDelay;
}
gThread->UpdateFilter(mDelay, timeout, now);
@@ -354,7 +344,7 @@ void nsTimerImpl::Fire()
#ifdef DEBUG_TIMERS
if (PR_LOG_TEST(gTimerLog, PR_LOG_DEBUG)) {
PR_LOG(gTimerLog, PR_LOG_DEBUG,
("[this=%p] Took %dms to fire timer callback\n",
("[this=%p] Took %dms to fire process timer callback\n",
this, PR_IntervalToMilliseconds(PR_IntervalNow() - now)));
}
#endif
@@ -367,7 +357,7 @@ void nsTimerImpl::Fire()
}
struct TimerEventType {
struct MyEventType {
PLEvent e;
// arguments follow...
#ifdef DEBUG_TIMERS
@@ -376,34 +366,22 @@ struct TimerEventType {
};
void* handleTimerEvent(TimerEventType* event)
void* handleMyEvent(MyEventType* event)
{
#ifdef DEBUG_TIMERS
if (PR_LOG_TEST(gTimerLog, PR_LOG_DEBUG)) {
PRIntervalTime now = PR_IntervalNow();
PR_LOG(gTimerLog, PR_LOG_DEBUG,
("[this=%p] time between PostTimerEvent() and Fire(): %dms\n",
("[this=%p] time between Fire() and Process(): %dms\n",
event->e.owner, PR_IntervalToMilliseconds(now - event->mInit)));
}
#endif
if (gFireOnIdle) {
nsCOMPtr<nsIThread> currentThread, mainThread;
nsIThread::GetCurrent(getter_AddRefs(currentThread));
nsIThread::GetMainThread(getter_AddRefs(mainThread));
if (currentThread == mainThread) {
gIdleTimers->AppendElement(NS_STATIC_CAST(nsITimer*, NS_STATIC_CAST(nsTimerImpl*, event->e.owner)));
return NULL;
}
}
NS_STATIC_CAST(nsTimerImpl*, event->e.owner)->Fire();
NS_STATIC_CAST(nsTimerImpl*, event->e.owner)->Process();
return NULL;
}
void destroyTimerEvent(TimerEventType* event)
void destroyMyEvent(MyEventType* event)
{
nsTimerImpl *timer = NS_STATIC_CAST(nsTimerImpl*, event->e.owner);
NS_RELEASE(timer);
@@ -411,19 +389,19 @@ void destroyTimerEvent(TimerEventType* event)
}
void nsTimerImpl::PostTimerEvent()
void nsTimerImpl::Fire()
{
// XXX we may want to reuse the PLEvent in the case of repeating timers.
TimerEventType* event;
MyEventType* event;
// construct
event = PR_NEW(TimerEventType);
event = PR_NEW(MyEventType);
if (event == NULL) return;
// initialize
PL_InitEvent((PLEvent*)event, this,
(PLHandleEventProc)handleTimerEvent,
(PLDestroyEventProc)destroyTimerEvent);
(PLHandleEventProc)handleMyEvent,
(PLDestroyEventProc)destroyMyEvent);
// Since TimerThread addref'd 'this' for us, we don't need to addref here.
// We will release in destroyMyEvent.
@@ -494,96 +472,3 @@ NS_NewTimer(nsITimer* *aResult, nsTimerCallbackFunc aCallback, void *aClosure,
*aResult = timer;
return NS_OK;
}
/**
* Timer Manager code
*/
NS_IMPL_THREADSAFE_ISUPPORTS1(nsTimerManager, nsITimerManager)
nsTimerManager::nsTimerManager()
{
NS_INIT_REFCNT();
}
nsTimerManager::~nsTimerManager()
{
}
NS_IMETHODIMP nsTimerManager::SetUseIdleTimers(PRBool aUseIdleTimers)
{
if (aUseIdleTimers == PR_FALSE && gFireOnIdle == PR_TRUE)
return NS_ERROR_FAILURE;
gFireOnIdle = aUseIdleTimers;
if (gFireOnIdle && !gIdleTimers) {
gIdleTimers = new nsSupportsArray();
if (!gIdleTimers)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(gIdleTimers);
}
return NS_OK;
}
NS_IMETHODIMP nsTimerManager::GetUseIdleTimers(PRBool *aUseIdleTimers)
{
*aUseIdleTimers = gFireOnIdle;
return NS_OK;
}
NS_IMETHODIMP nsTimerManager::HasIdleTimers(PRBool *aHasTimers)
{
*aHasTimers = PR_FALSE;
if (!gFireOnIdle)
return NS_OK;
nsCOMPtr<nsIThread> currentThread, mainThread;
nsIThread::GetCurrent(getter_AddRefs(currentThread));
nsIThread::GetMainThread(getter_AddRefs(mainThread));
if (currentThread != mainThread) {
return NS_OK;
}
PRUint32 count;
gIdleTimers->Count(&count);
*aHasTimers = (count != 0);
return NS_OK;
}
NS_IMETHODIMP nsTimerManager::FireNextIdleTimer()
{
if (!gFireOnIdle)
return NS_OK;
nsCOMPtr<nsIThread> currentThread, mainThread;
nsIThread::GetCurrent(getter_AddRefs(currentThread));
nsIThread::GetMainThread(getter_AddRefs(mainThread));
if (currentThread != mainThread) {
return NS_OK;
}
PRUint32 count;
gIdleTimers->Count(&count);
if (count > 0) {
nsTimerImpl *theTimer = NS_STATIC_CAST(nsTimerImpl*, NS_STATIC_CAST(nsITimer*, gIdleTimers->ElementAt(0))); // addrefs
gIdleTimers->RemoveElement(NS_STATIC_CAST(nsITimer*, theTimer), 0);
theTimer->Fire();
NS_RELEASE(theTimer);
}
// pull out each one starting at the beginning until no more are left and fire them.
return NS_OK;
}