VirtualBox

Changeset 102013 in vbox for trunk


Ignore:
Timestamp:
Nov 9, 2023 8:30:09 AM (16 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
160112
Message:

libs/xpcom/java: Remove unused code, bugref:10545

Location:
trunk/src/libs/xpcom18a4/java/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/java/src/nsJavaWrapper.cpp

    r56604 r102013  
    20092009  // Need to release object on the main thread.
    20102010  nsresult rv = NS_ERROR_FAILURE;
    2011 #ifdef VBOX
    20122011  rv = NS_ProxyRelease(do_GetMainThreadQueue().get(), reinterpret_cast<nsISupports*>(aLockObject));
    2013 #else
    2014   nsCOMPtr<nsIThread> thread = do_GetMainThread();
    2015   if (thread) {
    2016       rv = NS_ProxyRelease(thread, reinterpret_cast<nsISupports*>(aLockObject));
    2017   }
    2018 #endif
    20192012  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to release using NS_ProxyRelease");
    20202013}
  • trunk/src/libs/xpcom18a4/java/src/nsJavaXPCOMBindingUtils.cpp

    r101923 r102013  
    792792  nsresult rv = NS_OK;
    793793
    794 #ifdef VBOX
    795 # if 0
     794#if 0
    796795  nsCOMPtr<nsIEventQueue> eq = do_GetMainThreadQueue();
    797796  rv = NS_ProxyRelease(eq.get(), mInstance);
    798797  rv |= NS_ProxyRelease(eq.get(), mIInfo);
    799 # else
     798#else
    800799  // The above code crashes in nsTraceRefcntImpl::LogAddCOMPtr() (@bugref 7620)
    801800  NS_RELEASE(mInstance);
    802801  NS_RELEASE(mIInfo);
    803802  rv = NS_OK;
    804 # endif
    805 #else
    806   // 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   }
    812803#endif
    813804  NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to release using NS_ProxyRelease");
  • trunk/src/libs/xpcom18a4/java/src/nsThreadUtils.h

    r46649 r102013  
    4141
    4242
    43 #ifdef VBOX
    44 #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 
    5343#include "VBox/com/NativeEventQueue.h"
    5444
     
    6050}
    6151
    62 #else
    63 #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 symbols
    73 // appearing in xpcom_core and xpcomglue.  It may be unnecessary in the future
    74 // with better toolchain support.
    75 #ifdef MOZILLA_INTERNAL_API
    76 # define NS_NewThread NS_NewThread_P
    77 # define NS_GetCurrentThread NS_GetCurrentThread_P
    78 # define NS_GetMainThread NS_GetMainThread_P
    79 # define NS_IsMainThread NS_IsMainThread_P
    80 # define NS_DispatchToCurrentThread NS_DispatchToCurrentThread_P
    81 # define NS_DispatchToMainThread NS_DispatchToMainThread_P
    82 # define NS_ProcessPendingEvents NS_ProcessPendingEvents_P
    83 # define NS_HasPendingEvents NS_HasPendingEvents_P
    84 # define NS_ProcessNextEvent NS_ProcessNextEvent_P
    85 #endif
    86 
    87 //-----------------------------------------------------------------------------
    88 // These methods are alternatives to the methods on nsIThreadManager, provided
    89 // for convenience.
    90 
    91 /**
    92  * Create a new thread, and optionally provide an initial event for the thread.
    93  *
    94  * @param result
    95  *   The resulting nsIThread object.
    96  * @param initialEvent
    97  *   The initial event to run on this thread.  This parameter may be null.
    98  *
    99  * @returns NS_ERROR_INVALID_ARG
    100  *   Indicates that the given name is not unique.
    101  */
    102 extern NS_COM_GLUE NS_METHOD
    103 NS_NewThread(nsIThread **result, nsIRunnable *initialEvent = nsnull);
    104 
    105 /**
    106  * Get a reference to the current thread.
    107  *
    108  * @param result
    109  *   The resulting nsIThread object.
    110  */
    111 extern NS_COM_GLUE NS_METHOD
    112 NS_GetCurrentThread(nsIThread **result);
    113 
    114 /**
    115  * Get a reference to the main thread.
    116  *
    117  * @param result
    118  *   The resulting nsIThread object.
    119  */
    120 extern NS_COM_GLUE NS_METHOD
    121 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_FALSE
    127  * 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 event
    136  *   The event to dispatch.
    137  *
    138  * @returns NS_ERROR_INVALID_ARG
    139  *   If event is null.
    140  */
    141 extern NS_COM_GLUE NS_METHOD
    142 NS_DispatchToCurrentThread(nsIRunnable *event);
    143 
    144 /**
    145  * Dispatch the given event to the main thread.
    146  *
    147  * @param event
    148  *   The event to dispatch.
    149  * @param dispatchFlags
    150  *   The flags to pass to the main thread's dispatch method.
    151  *
    152  * @returns NS_ERROR_INVALID_ARG
    153  *   If event is null.
    154  */
    155 extern NS_COM_GLUE NS_METHOD
    156 NS_DispatchToMainThread(nsIRunnable *event,
    157                         PRUint32 dispatchFlags = NS_DISPATCH_NORMAL);
    158 
    159 #ifndef XPCOM_GLUE_AVOID_NSPR
    160 /**
    161  * Process all pending events for the given thread before returning.  This
    162  * method simply calls ProcessNextEvent on the thread while HasPendingEvents
    163  * continues to return true and the time spent in NS_ProcessPendingEvents
    164  * does not exceed the given timeout value.
    165  *
    166  * @param thread
    167  *   The thread object for which to process pending events.  If null, then
    168  *   events will be processed for the current thread.
    169  * @param timeout
    170  *   The maximum number of milliseconds to spend processing pending events.
    171  *   Events are not pre-empted to honor this timeout.  Rather, the timeout
    172  *   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_METHOD
    176 NS_ProcessPendingEvents(nsIThread *thread,
    177                         PRIntervalTime timeout = PR_INTERVAL_NO_TIMEOUT);
    178 #endif
    179 
    180 /**
    181  * Shortcut for nsIThread::HasPendingEvents.
    182  *
    183  * It is an error to call this function when the given thread is not the
    184  * current thread.  This function will return PR_FALSE if called from some
    185  * other thread.
    186  *
    187  * @param thread
    188  *   The current thread or null.
    189  *
    190  * @returns
    191  *   A boolean value that if "true" indicates that there are pending events
    192  *   in the current thread's event queue.
    193  */
    194 extern NS_COM_GLUE PRBool
    195 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 the
    201  * current thread.  This function will simply return PR_FALSE if called
    202  * from some other thread.
    203  *
    204  * @param thread
    205  *   The current thread or null.
    206  * @param mayWait
    207  *   A boolean parameter that if "true" indicates that the method may block
    208  *   the calling thread to wait for a pending event.
    209  *
    210  * @returns
    211  *   A boolean value that if "true" indicates that an event from the current
    212  *   thread's event queue was processed.
    213  */
    214 extern NS_COM_GLUE PRBool
    215 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_API
    237 // Fast access to the current thread.  Do not release the returned pointer!  If
    238 // you want to use this pointer from some other thread, then you will need to
    239 // AddRef it.  Otherwise, you should only consider this pointer valid from code
    240 // running on the current thread.
    241 extern NS_COM_GLUE nsIThread *NS_GetCurrentThread();
    242 #endif
    243 
    244 //-----------------------------------------------------------------------------
    245 
    246 #ifndef XPCOM_GLUE_AVOID_NSPR
    247 
    248 #undef  IMETHOD_VISIBILITY
    249 #define IMETHOD_VISIBILITY NS_COM_GLUE
    250 
    251 // This class is designed to be subclassed.
    252 class NS_COM_GLUE nsRunnable : public nsIRunnable
    253 {
    254 public:
    255   NS_DECL_ISUPPORTS
    256   NS_DECL_NSIRUNNABLE
    257 
    258   nsRunnable() {
    259   }
    260 
    261 protected:
    262   virtual ~nsRunnable() {
    263   }
    264 };
    265 
    266 #undef  IMETHOD_VISIBILITY
    267 #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
    268 
    269 // An event that can be used to call a method on a class.  The class type must
    270 // support reference counting.
    271 template <class T>
    272 class nsRunnableMethod : public nsRunnable
    273 {
    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 MyClass
    304 //  - MyClass must defined AddRef and Release methods
    305 //
    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_NSPR
    312 
    313 // This class is designed to be used when you have an event class E that has a
    314 // 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 has
    316 // been destroyed.  nsRevocableEventPtr makes it easy for R to manage such
    317 // 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 implemented
    392   nsRevocableEventPtr(const nsRevocableEventPtr&);
    393   nsRevocableEventPtr& operator=(const nsRevocableEventPtr&);
    394 
    395   T *mEvent;
    396 };
    397 #endif
    398 
    39952#endif  // nsThreadUtils_h__
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette