From b3f112d3559f33dffdd7ddfd11bc5317351ba069 Mon Sep 17 00:00:00 2001 From: "koehler%mythrium.com" Date: Tue, 7 Nov 2000 05:56:30 +0000 Subject: [PATCH] reverted patch 55674 git-svn-id: svn://10.0.0.236/trunk@82374 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/timer/src/beos/Makefile.in | 19 +- .../src/beos/{nsTimerBeOS.cpp => nsTimer.cpp} | 177 ++++++++++++------ mozilla/widget/timer/src/beos/nsTimerBeOS.h | 110 ----------- .../timer/src/beos/nsTimerBeOSFactory.cpp | 44 ----- 4 files changed, 135 insertions(+), 215 deletions(-) rename mozilla/widget/timer/src/beos/{nsTimerBeOS.cpp => nsTimer.cpp} (56%) delete mode 100644 mozilla/widget/timer/src/beos/nsTimerBeOS.h delete mode 100644 mozilla/widget/timer/src/beos/nsTimerBeOSFactory.cpp diff --git a/mozilla/widget/timer/src/beos/Makefile.in b/mozilla/widget/timer/src/beos/Makefile.in index ecfb878a0b1..475e183e978 100644 --- a/mozilla/widget/timer/src/beos/Makefile.in +++ b/mozilla/widget/timer/src/beos/Makefile.in @@ -26,15 +26,20 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -LIBRARY_NAME = timer_$(TIMER_SUFFIX) +MODULE = timer +LIBRARY_NAME = timer_beos -CPPSRCS = nsTimerBeOS.cpp -TIMER_SUFFIX = beos -IS_COMPONENT = 1 -CPPSRCS += nsTimerBeOSFactory.cpp -EXTRA_DSO_LDOPTS = $(MOZ_TK_LDFLAGS) $(MOZ_COMPONENT_LIBS) +CPPSRCS = nsTimer.cpp include $(topsrcdir)/config/rules.mk -INCLUDES += $(MOZ_TK_CFLAGS) -I$(srcdir)/.. +DEFINES += -D_IMPL_NS_TIMER +CXXFLAGS += $(TK_CFLAGS) +INCLUDES += $(TK_CFLAGS) -I$(srcdir)/.. + +EXTRA_DSO_LDOPTS += \ + $(XPCOM_LIBS) \ + $(TK_LIBS) \ + $(NSPR_LIBS) + diff --git a/mozilla/widget/timer/src/beos/nsTimerBeOS.cpp b/mozilla/widget/timer/src/beos/nsTimer.cpp similarity index 56% rename from mozilla/widget/timer/src/beos/nsTimerBeOS.cpp rename to mozilla/widget/timer/src/beos/nsTimer.cpp index eed9419aaa0..f2dd5e58a5a 100644 --- a/mozilla/widget/timer/src/beos/nsTimerBeOS.cpp +++ b/mozilla/widget/timer/src/beos/nsTimer.cpp @@ -20,13 +20,19 @@ * Contributor(s): */ -#include "nsVoidArray.h" -#include "nsTimerBeOS.h" -#include "nsCOMPtr.h" - +#include "nsITimer.h" +#include "nsITimerCallback.h" +#include "nsCRT.h" +#include "prlog.h" +#include +#include +#include #include +#include #include #include +#include +#include static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID); @@ -54,7 +60,81 @@ static sem_id my_find_sem(const char *name) return ret; } -TimerManager nsTimerBeOS::sTimerManager; + +class TimerImpl; +class TimerManager; + +class TimerManager : public BList +{ +public: + TimerManager(); + ~TimerManager(); + void AddRequest(TimerImpl *); + bool RemoveRequest(TimerImpl *); + +private: + BLocker mLocker; + sem_id mSyncSem; + thread_id mTimerThreadID; + bool mQuitRequested; + + static int32 sTimerThreadFunc(void *); + int32 TimerThreadFunc(); + TimerImpl *FirstRequest() { return (TimerImpl *)FirstItem(); } +}; + + +class TimerImpl : public nsITimer +{ + friend class TimerManager; +public: + TimerImpl(); + virtual ~TimerImpl(); + + virtual nsresult Init(nsTimerCallbackFunc aFunc, + void *aClosure, + PRUint32 aDelay, + PRUint32 aPriority = NS_PRIORITY_NORMAL, + PRUint32 aType = NS_TYPE_ONE_SHOT + ); + + virtual nsresult Init(nsITimerCallback *aCallback, + PRUint32 aDelay, + PRUint32 aPriority = NS_PRIORITY_NORMAL, + PRUint32 aType = NS_TYPE_ONE_SHOT + ); + + NS_DECL_ISUPPORTS + + virtual void Cancel(); + virtual PRUint32 GetDelay() { return mDelay; } + virtual void SetDelay(PRUint32); + virtual PRUint32 GetPriority() {} + virtual void SetPriority(PRUint32 aPriority) {} + + virtual PRUint32 GetType() {} + virtual void SetType(PRUint32 aType) {} + virtual void* GetClosure() { return mClosure; } + + void FireTimeout(); + +private: + nsresult Init(PRUint32 aDelay); // Initialize the timer. + + bigtime_t mWhen; // Time when this request should be done + PRUint32 mDelay; // The delay set in Init() + nsTimerCallbackFunc mFunc; // The function to call back when expired + void *mClosure; // The argumnet to pass it. + nsITimerCallback *mCallback; // An interface to notify when expired. + bool mCanceled; + PRThread *mThread; +// PRBool mRepeat; // A repeat, not implemented yet. + +public: + static TimerManager sTimerManager; +}; + +TimerManager TimerImpl::sTimerManager; TimerManager::TimerManager() : BList(40) @@ -82,7 +162,7 @@ TimerManager::~TimerManager() wait_for_thread(mTimerThreadID, &junk); } -void TimerManager::AddRequest(nsITimer *inRequest) +void TimerManager::AddRequest(TimerImpl *inRequest) { if(mLocker.Lock()) { @@ -93,8 +173,8 @@ void TimerManager::AddRequest(nsITimer *inRequest) int32 pos; for(pos = 0; pos < count; pos++) { - nsITimer *entry = (nsITimer *)ItemAtFast(pos); - if(((nsTimerBeOS *)entry)->mSchedTime > ((nsTimerBeOS*)inRequest)->mSchedTime) + TimerImpl *entry = (TimerImpl *)ItemAtFast(pos); + if(entry->mWhen > inRequest->mWhen) break; } AddItem(inRequest, pos); @@ -107,7 +187,7 @@ void TimerManager::AddRequest(nsITimer *inRequest) } } -bool TimerManager::RemoveRequest(nsITimer *inRequest) +bool TimerManager::RemoveRequest(TimerImpl *inRequest) { bool found = false; @@ -140,49 +220,47 @@ int32 TimerManager::TimerThreadFunc() while(! mQuitRequested) { - nsITimer *tobj = 0; + TimerImpl *tobj = 0; mLocker.Lock(); bigtime_t now = system_time(); // Fire expired pending requests - while((tobj = FirstRequest()) != 0 && ((nsTimerBeOS*)tobj)->mSchedTime <= now) + while((tobj = FirstRequest()) != 0 && tobj->mWhen <= now) { - nsTimerBeOS *tobjbeos = (nsTimerBeOS *)tobj; - RemoveItem((int32)0); mLocker.Unlock(); - if(! tobjbeos->mCanceled) + if(! tobj->mCanceled) { // fire it - if(tobjbeos->mThread != cached) + if(tobj->mThread != cached) { - sprintf(portname, "event%lx", (uint32)tobjbeos->mThread); - sprintf(semname, "sync%lx", (uint32)tobjbeos->mThread); + sprintf(portname, "event%lx", tobj->mThread); + sprintf(semname, "sync%lx", tobj->mThread); eventport = find_port(portname); syncsem = my_find_sem(semname); - cached = tobjbeos->mThread; + cached = tobj->mThread; } // call timer synchronously so we're sure tobj is alive ThreadInterfaceData id; - id.data = tobjbeos; + id.data = tobj; id.sync = true; if(write_port(eventport, 'WMti', &id, sizeof(id)) == B_OK) while(acquire_sem(syncsem) == B_INTERRUPTED) ; } - NS_RELEASE(tobjbeos); + NS_RELEASE(tobj); mLocker.Lock(); } mLocker.Unlock(); if(acquire_sem_etc(mSyncSem, 1, B_ABSOLUTE_TIMEOUT, - tobj ? ((nsTimerBeOS *)tobj)->mSchedTime : B_INFINITE_TIMEOUT) == B_BAD_SEM_ID) + tobj ? tobj->mWhen : B_INFINITE_TIMEOUT) == B_BAD_SEM_ID) break; } @@ -190,9 +268,9 @@ int32 TimerManager::TimerThreadFunc() } // -// nsTimerBeOS +// TimerImpl // -void nsTimerBeOS::FireTimeout() +void TimerImpl::FireTimeout() { if( ! mCanceled) { @@ -203,68 +281,60 @@ void nsTimerBeOS::FireTimeout() } } -nsTimerBeOS::nsTimerBeOS() +TimerImpl::TimerImpl() { NS_INIT_REFCNT(); mFunc = 0; mCallback = 0; mDelay = 0; mClosure = 0; - mSchedTime = 0; + mWhen = 0; mCanceled = false; } -nsTimerBeOS::~nsTimerBeOS() +TimerImpl::~TimerImpl() { Cancel(); NS_IF_RELEASE(mCallback); } -void nsTimerBeOS::SetDelay(PRUint32 aDelay) +void TimerImpl::SetDelay(PRUint32 aDelay) { mDelay = aDelay; - mSchedTime = system_time() + mDelay * 1000; + mWhen = system_time() + mDelay * 1000; NS_ADDREF(this); - if (nsTimerBeOS::sTimerManager.RemoveRequest(this)) - nsTimerBeOS::sTimerManager.AddRequest(this); - Release(); + if (TimerImpl::sTimerManager.RemoveRequest(this)) + TimerImpl::sTimerManager.AddRequest(this); +// NS_RELEASE(this); // ?*?*?*?* doesn't work... + Release(); // Is it the right way ? } -void nsTimerBeOS::SetPriority(PRUint32 aPriority) -{ - mPriority = aPriority; -} - -void nsTimerBeOS::SetType(PRUint32 aType) -{ - mType = aType; -} - -nsresult nsTimerBeOS::Init(nsTimerCallbackFunc aFunc, void *aClosure, +nsresult TimerImpl::Init(nsTimerCallbackFunc aFunc, void *aClosure, PRUint32 aDelay, PRUint32 aPriority, PRUint32 aType) { mFunc = aFunc; mClosure = aClosure; + // mRepeat = aRepeat; return Init(aDelay); } -nsresult nsTimerBeOS::Init(nsITimerCallback *aCallback, +nsresult TimerImpl::Init(nsITimerCallback *aCallback, PRUint32 aDelay, PRUint32 aPriority, PRUint32 aType) { mCallback = aCallback; NS_ADDREF(mCallback); - + // mRepeat = aRepeat; return Init(aDelay); } -nsresult nsTimerBeOS::Init(PRUint32 aDelay) +nsresult TimerImpl::Init(PRUint32 aDelay) { mDelay = aDelay; NS_ADDREF(this); // this is for clients of the timer - mSchedTime = system_time() + aDelay * 1000; + mWhen = system_time() + aDelay * 1000; mThread = PR_GetCurrentThread(); @@ -273,13 +343,13 @@ nsresult nsTimerBeOS::Init(PRUint32 aDelay) return NS_OK; } -NS_IMPL_ISUPPORTS(nsTimerBeOS, kITimerIID); +NS_IMPL_ISUPPORTS(TimerImpl, kITimerIID); -void nsTimerBeOS::Cancel() +void TimerImpl::Cancel() { mCanceled = true; - nsTimerBeOS::sTimerManager.RemoveRequest(this); + TimerImpl::sTimerManager.RemoveRequest(this); } nsresult NS_NewTimer(nsITimer** aInstancePtrResult) @@ -288,7 +358,7 @@ nsresult NS_NewTimer(nsITimer** aInstancePtrResult) if(nsnull == aInstancePtrResult) return NS_ERROR_NULL_POINTER; - nsTimerBeOS *timer = new nsTimerBeOS(); + TimerImpl *timer = new TimerImpl(); if(nsnull == timer) return NS_ERROR_OUT_OF_MEMORY; @@ -297,8 +367,7 @@ nsresult NS_NewTimer(nsITimer** aInstancePtrResult) void nsTimerExpired(void *aCallData) { - nsTimerBeOS *timer = (nsTimerBeOS *)aCallData; - timer->FireTimeout(); - NS_RELEASE(timer); + TimerImpl* timer = (TimerImpl *)aCallData; + timer->FireTimeout(); + NS_RELEASE(timer); } - diff --git a/mozilla/widget/timer/src/beos/nsTimerBeOS.h b/mozilla/widget/timer/src/beos/nsTimerBeOS.h deleted file mode 100644 index c62ecaa5f92..00000000000 --- a/mozilla/widget/timer/src/beos/nsTimerBeOS.h +++ /dev/null @@ -1,110 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef __nsTimerBeOS_h -#define __nsTimerBeOS_h - -#include "nsITimer.h" -#include "nsITimerCallback.h" - -#include - -#include -#include - -class TimerManager : public BList -{ -public: - TimerManager(); - ~TimerManager(); - void AddRequest(nsITimer *inRequest); - bool RemoveRequest(nsITimer *inRequest); - -private: - BLocker mLocker; - sem_id mSyncSem; - thread_id mTimerThreadID; - bool mQuitRequested; - - static int32 sTimerThreadFunc(void *); - int32 TimerThreadFunc(); - nsITimer *FirstRequest() { return (nsITimer *)FirstItem(); } -}; - -class nsTimerBeOS : public nsITimer -{ - friend class TimerManager; -public: - - nsTimerBeOS(); - virtual ~nsTimerBeOS(); - - virtual nsresult Init(nsTimerCallbackFunc aFunc, - void *aClosure, - PRUint32 aDelay, - PRUint32 aPriority = NS_PRIORITY_NORMAL, - PRUint32 aType = NS_TYPE_ONE_SHOT - ); - - virtual nsresult Init(nsITimerCallback *aCallback, - PRUint32 aDelay, - PRUint32 aPriority = NS_PRIORITY_NORMAL, - PRUint32 aType = NS_TYPE_ONE_SHOT - ); - - NS_DECL_ISUPPORTS - - virtual void Cancel(); - - virtual PRUint32 GetDelay() { return mDelay; } - virtual void SetDelay(PRUint32 aDelay); - - virtual PRUint32 GetPriority() { return mPriority; } - virtual void SetPriority(PRUint32 aPriority); - - virtual PRUint32 GetType() { return mType; } - virtual void SetType(PRUint32 aType); - - virtual void* GetClosure() { return mClosure; } - - void FireTimeout(); - - bigtime_t mSchedTime; // Time when this request should be done - PRUint32 mDelay; // The delay set in Init() -private: - nsresult Init(PRUint32 aDelay); // Initialize the timer. - - PRUint32 mPriority; - PRUint32 mType; - nsTimerCallbackFunc mFunc; // The function to call back when expired - void * mClosure; // The argumnet to pass it. - nsITimerCallback * mCallback; // An interface to notify when expired. - - bool mCanceled; - PRThread * mThread; -// PRBool mRepeat; // A repeat, not implemented yet. - -public: - static TimerManager sTimerManager; -}; - -#endif // __nsTimerBeOS_h diff --git a/mozilla/widget/timer/src/beos/nsTimerBeOSFactory.cpp b/mozilla/widget/timer/src/beos/nsTimerBeOSFactory.cpp deleted file mode 100644 index 7e5b2d9d8d8..00000000000 --- a/mozilla/widget/timer/src/beos/nsTimerBeOSFactory.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indentT-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "nsIGenericFactory.h" -#include "nsIModule.h" -#include "nsCOMPtr.h" - -#include "nsTimerBeOS.h" - -// {48B62AD2-48D3-11d3-B224-000064657374} -#define NS_TIMER_BEOS_CID \ -{ 0x48b62ad2, 0x48d3, 0x11d3, \ - { 0xb2, 0x24, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } - -NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimerBeOS) - -static nsModuleComponentInfo components[] = -{ - { "BeOS timer", - NS_TIMER_BEOS_CID, - "@mozilla.org/timer;1", - nsTimerBeOSConstructor } -}; - -NS_IMPL_NSGETMODULE("nsBeOSTimerModule", components)