- Timestamp:
- Nov 9, 2023 8:30:09 AM (16 months ago)
- svn:sync-xref-src-repo-rev:
- 160112
- Location:
- trunk/src/libs/xpcom18a4/java/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/java/src/nsJavaWrapper.cpp
r56604 r102013 2009 2009 // Need to release object on the main thread. 2010 2010 nsresult rv = NS_ERROR_FAILURE; 2011 #ifdef VBOX2012 2011 rv = NS_ProxyRelease(do_GetMainThreadQueue().get(), reinterpret_cast<nsISupports*>(aLockObject)); 2013 #else2014 nsCOMPtr<nsIThread> thread = do_GetMainThread();2015 if (thread) {2016 rv = NS_ProxyRelease(thread, reinterpret_cast<nsISupports*>(aLockObject));2017 }2018 #endif2019 2012 NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to release using NS_ProxyRelease"); 2020 2013 } -
trunk/src/libs/xpcom18a4/java/src/nsJavaXPCOMBindingUtils.cpp
r101923 r102013 792 792 nsresult rv = NS_OK; 793 793 794 #ifdef VBOX 795 # if 0 794 #if 0 796 795 nsCOMPtr<nsIEventQueue> eq = do_GetMainThreadQueue(); 797 796 rv = NS_ProxyRelease(eq.get(), mInstance); 798 797 rv |= NS_ProxyRelease(eq.get(), mIInfo); 799 # 798 #else 800 799 // The above code crashes in nsTraceRefcntImpl::LogAddCOMPtr() (@bugref 7620) 801 800 NS_RELEASE(mInstance); 802 801 NS_RELEASE(mIInfo); 803 802 rv = NS_OK; 804 # endif805 #else806 // Need to release these objects on the main thread.807 nsCOMPtr<nsIThread> thread = do_GetMainThread();808 if (thread) {809 rv = NS_ProxyRelease(thread, mInstance);810 rv |= NS_ProxyRelease(thread, mIInfo);811 }812 803 #endif 813 804 NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to release using NS_ProxyRelease"); -
trunk/src/libs/xpcom18a4/java/src/nsThreadUtils.h
r46649 r102013 41 41 42 42 43 #ifdef VBOX44 #include "nsIThread.h"45 46 inline already_AddRefed<nsIThread>47 do_GetMainThread() {48 nsIThread *thread = nsnull;49 nsIThread::GetMainThread(&thread);50 return already_AddRefed<nsIThread>(thread);51 }52 53 43 #include "VBox/com/NativeEventQueue.h" 54 44 … … 60 50 } 61 51 62 #else63 #include "prthread.h"64 #include "prinrval.h"65 #include "nsIThreadManager.h"66 #include "nsIThread.h"67 #include "nsIRunnable.h"68 #include "nsStringGlue.h"69 #include "nsCOMPtr.h"70 71 72 // This is needed on some systems to prevent collisions between the symbols73 // appearing in xpcom_core and xpcomglue. It may be unnecessary in the future74 // with better toolchain support.75 #ifdef MOZILLA_INTERNAL_API76 # define NS_NewThread NS_NewThread_P77 # define NS_GetCurrentThread NS_GetCurrentThread_P78 # define NS_GetMainThread NS_GetMainThread_P79 # define NS_IsMainThread NS_IsMainThread_P80 # define NS_DispatchToCurrentThread NS_DispatchToCurrentThread_P81 # define NS_DispatchToMainThread NS_DispatchToMainThread_P82 # define NS_ProcessPendingEvents NS_ProcessPendingEvents_P83 # define NS_HasPendingEvents NS_HasPendingEvents_P84 # define NS_ProcessNextEvent NS_ProcessNextEvent_P85 #endif86 87 //-----------------------------------------------------------------------------88 // These methods are alternatives to the methods on nsIThreadManager, provided89 // for convenience.90 91 /**92 * Create a new thread, and optionally provide an initial event for the thread.93 *94 * @param result95 * The resulting nsIThread object.96 * @param initialEvent97 * The initial event to run on this thread. This parameter may be null.98 *99 * @returns NS_ERROR_INVALID_ARG100 * Indicates that the given name is not unique.101 */102 extern NS_COM_GLUE NS_METHOD103 NS_NewThread(nsIThread **result, nsIRunnable *initialEvent = nsnull);104 105 /**106 * Get a reference to the current thread.107 *108 * @param result109 * The resulting nsIThread object.110 */111 extern NS_COM_GLUE NS_METHOD112 NS_GetCurrentThread(nsIThread **result);113 114 /**115 * Get a reference to the main thread.116 *117 * @param result118 * The resulting nsIThread object.119 */120 extern NS_COM_GLUE NS_METHOD121 NS_GetMainThread(nsIThread **result);122 123 /**124 * Test to see if the current thread is the main thread.125 *126 * @returns PR_TRUE if the current thread is the main thread, and PR_FALSE127 * otherwise.128 */129 extern NS_COM_GLUE NS_METHOD_(PRBool)130 NS_IsMainThread();131 132 /**133 * Dispatch the given event to the current thread.134 *135 * @param event136 * The event to dispatch.137 *138 * @returns NS_ERROR_INVALID_ARG139 * If event is null.140 */141 extern NS_COM_GLUE NS_METHOD142 NS_DispatchToCurrentThread(nsIRunnable *event);143 144 /**145 * Dispatch the given event to the main thread.146 *147 * @param event148 * The event to dispatch.149 * @param dispatchFlags150 * The flags to pass to the main thread's dispatch method.151 *152 * @returns NS_ERROR_INVALID_ARG153 * If event is null.154 */155 extern NS_COM_GLUE NS_METHOD156 NS_DispatchToMainThread(nsIRunnable *event,157 PRUint32 dispatchFlags = NS_DISPATCH_NORMAL);158 159 #ifndef XPCOM_GLUE_AVOID_NSPR160 /**161 * Process all pending events for the given thread before returning. This162 * method simply calls ProcessNextEvent on the thread while HasPendingEvents163 * continues to return true and the time spent in NS_ProcessPendingEvents164 * does not exceed the given timeout value.165 *166 * @param thread167 * The thread object for which to process pending events. If null, then168 * events will be processed for the current thread.169 * @param timeout170 * The maximum number of milliseconds to spend processing pending events.171 * Events are not pre-empted to honor this timeout. Rather, the timeout172 * value is simply used to determine whether or not to process another event.173 * Pass PR_INTERVAL_NO_TIMEOUT to specify no timeout.174 */175 extern NS_COM_GLUE NS_METHOD176 NS_ProcessPendingEvents(nsIThread *thread,177 PRIntervalTime timeout = PR_INTERVAL_NO_TIMEOUT);178 #endif179 180 /**181 * Shortcut for nsIThread::HasPendingEvents.182 *183 * It is an error to call this function when the given thread is not the184 * current thread. This function will return PR_FALSE if called from some185 * other thread.186 *187 * @param thread188 * The current thread or null.189 *190 * @returns191 * A boolean value that if "true" indicates that there are pending events192 * in the current thread's event queue.193 */194 extern NS_COM_GLUE PRBool195 NS_HasPendingEvents(nsIThread *thread = nsnull);196 197 /**198 * Shortcut for nsIThread::ProcessNextEvent.199 *200 * It is an error to call this function when the given thread is not the201 * current thread. This function will simply return PR_FALSE if called202 * from some other thread.203 *204 * @param thread205 * The current thread or null.206 * @param mayWait207 * A boolean parameter that if "true" indicates that the method may block208 * the calling thread to wait for a pending event.209 *210 * @returns211 * A boolean value that if "true" indicates that an event from the current212 * thread's event queue was processed.213 */214 extern NS_COM_GLUE PRBool215 NS_ProcessNextEvent(nsIThread *thread = nsnull, PRBool mayWait = PR_TRUE);216 217 //-----------------------------------------------------------------------------218 // Helpers that work with nsCOMPtr:219 220 inline already_AddRefed<nsIThread>221 do_GetCurrentThread() {222 nsIThread *thread = nsnull;223 NS_GetCurrentThread(&thread);224 return already_AddRefed<nsIThread>(thread);225 }226 227 inline already_AddRefed<nsIThread>228 do_GetMainThread() {229 nsIThread *thread = nsnull;230 NS_GetMainThread(&thread);231 return already_AddRefed<nsIThread>(thread);232 }233 234 //-----------------------------------------------------------------------------235 236 #ifdef MOZILLA_INTERNAL_API237 // Fast access to the current thread. Do not release the returned pointer! If238 // you want to use this pointer from some other thread, then you will need to239 // AddRef it. Otherwise, you should only consider this pointer valid from code240 // running on the current thread.241 extern NS_COM_GLUE nsIThread *NS_GetCurrentThread();242 #endif243 244 //-----------------------------------------------------------------------------245 246 #ifndef XPCOM_GLUE_AVOID_NSPR247 248 #undef IMETHOD_VISIBILITY249 #define IMETHOD_VISIBILITY NS_COM_GLUE250 251 // This class is designed to be subclassed.252 class NS_COM_GLUE nsRunnable : public nsIRunnable253 {254 public:255 NS_DECL_ISUPPORTS256 NS_DECL_NSIRUNNABLE257 258 nsRunnable() {259 }260 261 protected:262 virtual ~nsRunnable() {263 }264 };265 266 #undef IMETHOD_VISIBILITY267 #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN268 269 // An event that can be used to call a method on a class. The class type must270 // support reference counting.271 template <class T>272 class nsRunnableMethod : public nsRunnable273 {274 public:275 typedef void (T::*Method)();276 277 nsRunnableMethod(T *obj, Method method)278 : mObj(obj), mMethod(method) {279 NS_ADDREF(mObj);280 }281 282 NS_IMETHOD Run() {283 (mObj->*mMethod)();284 return NS_OK;285 }286 287 private:288 virtual ~nsRunnableMethod() {289 NS_RELEASE(mObj);290 }291 292 T *mObj;293 Method mMethod;294 };295 296 // Use this helper macro like so:297 //298 // nsCOMPtr<nsIRunnable> event =299 // NS_NEW_RUNNABLE_METHOD(MyClass, myObject, HandleEvent);300 // NS_DispatchToCurrentThread(event);301 //302 // Constraints:303 // - myObject must be of type MyClass304 // - MyClass must defined AddRef and Release methods305 //306 // NOTE: Attempts to make this a template function caused VC6 to barf :-(307 //308 #define NS_NEW_RUNNABLE_METHOD(class_, obj_, method_) \309 new nsRunnableMethod<class_>(obj_, &class_::method_)310 311 #endif // XPCOM_GLUE_AVOID_NSPR312 313 // This class is designed to be used when you have an event class E that has a314 // pointer back to resource class R. If R goes away while E is still pending,315 // then it is important to "revoke" E so that it does not try use R after R has316 // been destroyed. nsRevocableEventPtr makes it easy for R to manage such317 // situations:318 //319 // class R;320 //321 // class E : public nsRunnable {322 // public:323 // void Revoke() {324 // mResource = nsnull;325 // }326 // private:327 // R *mResource;328 // };329 //330 // class R {331 // public:332 // void EventHandled() {333 // mEvent.Forget();334 // }335 // private:336 // nsRevocableEventPtr<E> mEvent;337 // };338 //339 // void R::PostEvent() {340 // // Make sure any pending event is revoked.341 // mEvent->Revoke();342 //343 // nsCOMPtr<nsIRunnable> event = new E();344 // if (NS_SUCCEEDED(NS_DispatchToCurrentThread(event))) {345 // // Keep pointer to event so we can revoke it.346 // mEvent = event;347 // }348 // }349 //350 // NS_IMETHODIMP E::Run() {351 // if (!mResource)352 // return NS_OK;353 // ...354 // mResource->EventHandled();355 // return NS_OK;356 // }357 //358 template <class T>359 class nsRevocableEventPtr {360 public:361 nsRevocableEventPtr()362 : mEvent(nsnull) {363 }364 365 ~nsRevocableEventPtr() {366 Revoke();367 }368 369 const nsRevocableEventPtr& operator=(T *event) {370 Revoke();371 mEvent = event;372 return *this;373 }374 375 void Revoke() {376 if (mEvent) {377 mEvent->Revoke();378 mEvent = nsnull;379 }380 }381 382 void Forget() {383 mEvent = nsnull;384 }385 386 PRBool IsPending() {387 return mEvent != nsnull;388 }389 390 private:391 // Not implemented392 nsRevocableEventPtr(const nsRevocableEventPtr&);393 nsRevocableEventPtr& operator=(const nsRevocableEventPtr&);394 395 T *mEvent;396 };397 #endif398 399 52 #endif // nsThreadUtils_h__
Note:
See TracChangeset
for help on using the changeset viewer.