VirtualBox

Changeset 102016 in vbox for trunk/src/libs/xpcom18a4


Ignore:
Timestamp:
Nov 9, 2023 10:30:35 AM (15 months ago)
Author:
vboxsync
Message:

libs/xpcom/xpcom: Convert nsEventQueueService,nsEventQueue and plevent from PRThread/nsIThread to IPRT's thread API, bugref:10545

Location:
trunk/src/libs/xpcom18a4/xpcom
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/xpcom/build/nsXPCOM.h

    r101871 r102016  
    4141#include "nscore.h"
    4242#include "nsXPCOMCID.h"
     43
     44#include <iprt/thread.h>
    4345
    4446#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
     
    6870class nsITraceRefcnt;
    6971
     72typedef RTTHREADINT *RTTHREAD;
     73
    7074#ifdef VBOX
    7175/**
     
    7478extern "C" NS_COM PRBool
    7579NS_IsXPCOMInitialized(void);
     80
     81extern "C" NS_COM nsresult
     82NS_GetMainThread(RTTHREAD *phThreadMain);
    7683#endif
    7784
  • trunk/src/libs/xpcom18a4/xpcom/build/nsXPComInit.cpp

    r101944 r102016  
    7474#include "nsIInterfaceInfoManager.h"
    7575
    76 #include "nsThread.h"
    77 
    7876#include "nsEmptyEnumerator.h"
    7977
     
    119117
    120118NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsEventQueueServiceImpl, Init)
     119
     120static RTTHREAD g_hMainThread = 0;
    121121
    122122#define NS_ENVIRONMENT_CLASSNAME "Environment Service"
     
    335335    COMPONENT(EVENTQUEUESERVICE, nsEventQueueServiceImplConstructor),
    336336    COMPONENT(EVENTQUEUE, nsEventQueueImpl::Create),
    337     COMPONENT(THREAD, nsThread::Create),
    338337
    339338#define NS_XPCOMPROXY_CID NS_PROXYEVENT_MANAGER_CID
     
    450449#endif
    451450
     451nsresult NS_COM
     452NS_GetMainThread(RTTHREAD *phThreadMain)
     453{
     454    NS_ASSERTION(phThreadMain, "bad result pointer");
     455    if (g_hMainThread == NIL_RTTHREAD)
     456        return NS_ERROR_FAILURE;
     457    *phThreadMain = g_hMainThread;
     458    return NS_OK;
     459}
     460
    452461nsresult NS_COM NS_InitXPCOM(nsIServiceManager* *result,
    453462                             nsIFile* binDirectory)
     
    470479
    471480    // Establish the main thread here.
    472     rv = nsIThread::SetMainThread();
    473     if (NS_FAILED(rv)) return rv;
     481    g_hMainThread = RTThreadSelf();
    474482
    475483    // If the locale hasn't already been setup by our embedder,
     
    872880    EmptyEnumeratorImpl::Shutdown();
    873881
    874     nsThread::Shutdown();
    875882    NS_PurgeAtomTable();
    876883
  • trunk/src/libs/xpcom18a4/xpcom/threads/nsEventQueue.cpp

    r101993 r102016  
    3939#include "nsEventQueue.h"
    4040#include "nsIEventQueueService.h"
    41 #include "nsIThread.h"
    4241
    4342#include "nsIServiceManager.h"
     
    125124nsEventQueueImpl::Init(PRBool aNative)
    126125{
    127   PRThread *thread = PR_GetCurrentThread();
     126  RTTHREAD hThread = RTThreadSelf();
    128127  if (aNative)
    129     mEventQueue = PL_CreateNativeEventQueue("Thread event queue...", thread);
     128    mEventQueue = PL_CreateNativeEventQueue("Thread event queue...", hThread);
    130129  else
    131     mEventQueue = PL_CreateMonitoredEventQueue("Thread event queue...", thread);
     130    mEventQueue = PL_CreateMonitoredEventQueue("Thread event queue...", hThread);
    132131  NotifyObservers(gActivatedNotification);
    133132  return NS_OK;
     
    135134
    136135NS_IMETHODIMP
    137 nsEventQueueImpl::InitFromPRThread(PRThread* thread, PRBool aNative)
    138 {
    139   if (thread == NS_CURRENT_THREAD)
     136nsEventQueueImpl::InitFromPRThread(RTTHREAD hThread, PRBool aNative)
     137{
     138  if (hThread == NS_CURRENT_THREAD)
    140139  {
    141      thread = PR_GetCurrentThread();
    142   }
    143   else if (thread == NS_UI_THREAD)
     140     hThread = RTThreadSelf();
     141  }
     142  else if (hThread == NS_UI_THREAD)
    144143  {
    145     nsCOMPtr<nsIThread>  mainIThread;
    146     nsresult rv;
    147  
    148144    // Get the primordial thread
    149     rv = nsIThread::GetMainThread(getter_AddRefs(mainIThread));
     145    nsresult rv = NS_GetMainThread(&hThread);
    150146    if (NS_FAILED(rv)) return rv;
    151 
    152     rv = mainIThread->GetPRThread(&thread);
    153     if (NS_FAILED(rv)) return rv;
    154   } 
     147  }
    155148
    156149  if (aNative)
    157     mEventQueue = PL_CreateNativeEventQueue("Thread event queue...", thread);
     150    mEventQueue = PL_CreateNativeEventQueue("Thread event queue...", hThread);
    158151  else
    159     mEventQueue = PL_CreateMonitoredEventQueue("Thread event queue...", thread);
     152    mEventQueue = PL_CreateMonitoredEventQueue("Thread event queue...", hThread);
    160153  NotifyObservers(gActivatedNotification);
    161154  return NS_OK;
  • trunk/src/libs/xpcom18a4/xpcom/threads/nsEventQueueService.cpp

    r101992 r102016  
    5454#include "prmon.h"
    5555#include "nsIComponentManager.h"
    56 #include "nsIThread.h"
    5756#include "nsPIEventQueueChain.h"
     57
     58#include "nsXPCOM.h"
    5859
    5960#include <VBox/log.h>
     
    107108 
    108109  // ensure that a main thread event queue exists!
    109   nsresult rv;
    110   nsCOMPtr<nsIThread> mainThread;
    111   rv = nsIThread::GetMainThread(getter_AddRefs(mainThread));
    112   if (NS_SUCCEEDED(rv)) {
    113     PRThread *thr;
    114     rv = mainThread->GetPRThread(&thr);
    115     if (NS_SUCCEEDED(rv))
    116       rv = CreateEventQueue(thr, PR_TRUE);
    117   }
     110  RTTHREAD hMainThread;
     111  nsresult rv = NS_GetMainThread(&hMainThread);
     112  if (NS_SUCCEEDED(rv))
     113    rv = CreateEventQueue(hMainThread, PR_TRUE);
     114
    118115  return rv;
    119116}
     
    127124nsEventQueueServiceImpl::CreateThreadEventQueue()
    128125{
    129   return CreateEventQueue(PR_GetCurrentThread(), PR_TRUE);
     126  return CreateEventQueue(RTThreadSelf(), PR_TRUE);
    130127}
    131128
     
    133130nsEventQueueServiceImpl::CreateMonitoredThreadEventQueue()
    134131{
    135   return CreateEventQueue(PR_GetCurrentThread(), PR_FALSE);
    136 }
    137 
    138 NS_IMETHODIMP
    139 nsEventQueueServiceImpl::CreateFromIThread(nsIThread *aThread, PRBool aNative,
     132  return CreateEventQueue(RTThreadSelf(), PR_FALSE);
     133}
     134
     135NS_IMETHODIMP
     136nsEventQueueServiceImpl::CreateFromIThread(RTTHREAD aThread, PRBool aNative,
    140137                                           nsIEventQueue **aResult)
    141138{
    142139  nsresult rv;
    143   PRThread *prThread;
    144 
    145   rv = aThread->GetPRThread(&prThread);
    146   if (NS_SUCCEEDED(rv)) {
    147     rv = CreateEventQueue(prThread, aNative); // addrefs
    148     if (NS_SUCCEEDED(rv))
    149       rv = GetThreadEventQueue(prThread, aResult); // addrefs
    150   }
     140
     141  rv = CreateEventQueue(aThread, aNative); // addrefs
     142  if (NS_SUCCEEDED(rv))
     143    rv = GetThreadEventQueue(aThread, aResult); // addrefs
     144
    151145  return rv;
    152146}
     
    154148// private method
    155149NS_IMETHODIMP
    156 nsEventQueueServiceImpl::MakeNewQueue(PRThread* thread,
     150nsEventQueueServiceImpl::MakeNewQueue(RTTHREAD hThread,
    157151                                      PRBool aNative,
    158152                                      nsIEventQueue **aQueue)
     
    162156
    163157  if (NS_SUCCEEDED(rv)) {
    164     rv = queue->InitFromPRThread(thread, aNative);
    165   }     
     158    rv = queue->InitFromPRThread(hThread, aNative);
     159  }
    166160  *aQueue = queue;
    167161  NS_IF_ADDREF(*aQueue);
     
    171165// private method
    172166NS_IMETHODIMP
    173 nsEventQueueServiceImpl::CreateEventQueue(PRThread *aThread, PRBool aNative)
     167nsEventQueueServiceImpl::CreateEventQueue(RTTHREAD aThread, PRBool aNative)
    174168{
    175169  nsresult rv = NS_OK;
     
    200194  PR_EnterMonitor(mEventQMonitor);
    201195
    202   PRThread* currentThread = PR_GetCurrentThread();
    203   nsIEventQueue* queue = mEventQTable.GetWeak(currentThread);
     196  RTTHREAD hThread = RTThreadSelf();
     197  nsIEventQueue* queue = mEventQTable.GetWeak(hThread);
    204198  if (queue) {
    205199    queue->StopAcceptingEvents(); // tell the queue to stop accepting events
    206200    queue = nsnull; // Queue may die on the next line
    207     mEventQTable.Remove(currentThread); // remove nsIEventQueue from hash table (releases)
     201    mEventQTable.Remove(hThread); // remove nsIEventQueue from hash table (releases)
    208202  }
    209203
     
    256250{
    257251  nsresult rv = NS_OK;
    258   PRThread* currentThread = PR_GetCurrentThread();
     252  RTTHREAD hThread = RTThreadSelf();
    259253  PRBool native = PR_TRUE; // native by default as per old comment
    260254
     
    265259  PR_EnterMonitor(mEventQMonitor);
    266260
    267   nsIEventQueue* queue = mEventQTable.GetWeak(currentThread);
     261  nsIEventQueue* queue = mEventQTable.GetWeak(hThread);
    268262 
    269263  NS_ASSERTION(queue, "pushed event queue on top of nothing");
     
    278272
    279273  nsIEventQueue* newQueue = nsnull;
    280   MakeNewQueue(currentThread, native, &newQueue); // create new queue; addrefs
     274  MakeNewQueue(hThread, native, &newQueue); // create new queue; addrefs
    281275
    282276  if (!queue) {
    283277    // shouldn't happen. as a fallback, we guess you wanted a native queue
    284     mEventQTable.Put(currentThread, newQueue);
     278    mEventQTable.Put(hThread, newQueue);
    285279  }
    286280
     
    307301nsEventQueueServiceImpl::PopThreadEventQueue(nsIEventQueue *aQueue)
    308302{
    309   PRThread* currentThread = PR_GetCurrentThread();
     303  RTTHREAD hThread = RTThreadSelf();
    310304
    311305  /* Enter the lock that protects the EventQ hashtable... */
     
    313307
    314308  nsCOMPtr<nsIEventQueue> eldestQueue;
    315   mEventQTable.Get(currentThread, getter_AddRefs(eldestQueue));
     309  mEventQTable.Get(hThread, getter_AddRefs(eldestQueue));
    316310
    317311  // If we are popping the eldest queue, remove its mEventQTable entry.
    318312  if (aQueue == eldestQueue)
    319     mEventQTable.Remove(currentThread);
     313    mEventQTable.Remove(hThread);
    320314
    321315  // Exit the monitor before processing pending events to avoid deadlock.
     
    338332
    339333NS_IMETHODIMP
    340 nsEventQueueServiceImpl::GetThreadEventQueue(PRThread* aThread, nsIEventQueue** aResult)
     334nsEventQueueServiceImpl::GetThreadEventQueue(RTTHREAD aThread, nsIEventQueue** aResult)
    341335{
    342336  /* Parameter validation... */
    343337  if (NULL == aResult) return NS_ERROR_NULL_POINTER;
    344338
    345   PRThread* keyThread = aThread;
     339  RTTHREAD keyThread = aThread;
    346340
    347341  if (keyThread == NS_CURRENT_THREAD)
    348342  {
    349      keyThread = PR_GetCurrentThread();
     343     keyThread = RTThreadSelf();
    350344  }
    351345  else if (keyThread == NS_UI_THREAD)
    352346  {
    353     nsCOMPtr<nsIThread>  mainIThread;
    354 
    355347    // Get the primordial thread
    356     nsresult rv = nsIThread::GetMainThread(getter_AddRefs(mainIThread));
    357     if (NS_FAILED(rv)) return rv;
    358 
    359     rv = mainIThread->GetPRThread(&keyThread);
     348    nsresult rv = NS_GetMainThread(&keyThread);
    360349    if (NS_FAILED(rv)) return rv;
    361350  }
  • trunk/src/libs/xpcom18a4/xpcom/threads/nsEventQueueService.h

    r1 r102016  
    6565                Addref the descriptor in any case. parameter aNative is
    6666                ignored if the queue already exists. */
    67   NS_IMETHOD CreateEventQueue(PRThread *aThread, PRBool aNative);
    68   NS_IMETHOD MakeNewQueue(PRThread* thread, PRBool aNative, nsIEventQueue **aQueue);
     67  NS_IMETHOD CreateEventQueue(RTTHREAD aThread, PRBool aNative);
     68  NS_IMETHOD MakeNewQueue(RTTHREAD thread, PRBool aNative, nsIEventQueue **aQueue);
    6969  inline nsresult GetYoungestEventQueue(nsIEventQueue *queue, nsIEventQueue **aResult);
    7070
  • trunk/src/libs/xpcom18a4/xpcom/threads/nsIEventQueue.idl

    r1 r102016  
    4646
    4747%{C++
    48 #include "prthread.h"
     48#include <iprt/thread.h>
    4949
    5050// {13D86C61-00A9-11d3-9F2A-00400553EEF0}
     
    6060//
    6161[ptr] native PLEventQueuePtr(PLEventQueue);
    62 [ptr] native PRThreadPtr(PRThread);
     62[ptr] native RTTHREAD(RTTHREADINT);
    6363native PRStatus(PRStatus);
    6464[ref] native PRBoolRef(PRBool);
     
    8989
    9090    void init(in boolean aNative);
    91     [noscript] void initFromPRThread(in PRThreadPtr thread,
     91    [noscript] void initFromPRThread(in RTTHREAD thread,
    9292                                     in boolean aNative);
    9393    [noscript] void initFromPLQueue(in PLEventQueuePtr aQueue);
  • trunk/src/libs/xpcom18a4/xpcom/threads/nsIEventQueueService.idl

    r1 r102016  
    4949
    5050%{C++
    51 #include "prthread.h"
    5251#include "plevent.h"
     52
     53#include <iprt/thread.h>
    5354
    5455/* be761f00-a3b0-11d2-996c-0080c7cb1080 */
     
    6061#define NS_EVENTQUEUESERVICE_CLASSNAME "Event Queue Service"
    6162
    62 #define NS_CURRENT_THREAD    ((PRThread*)0)
     63#define NS_CURRENT_THREAD    ((RTTHREAD)0)
    6364#define NS_CURRENT_EVENTQ    ((nsIEventQueue*)0)
    6465
    65 #define NS_UI_THREAD         ((PRThread*)1)
     66#define NS_UI_THREAD         ((RTTHREAD)1)
    6667#define NS_UI_THREAD_EVENTQ  ((nsIEventQueue*)1)
    6768
    6869%}
    69 
    70 /* a forward decl */
    71 interface nsIThread;
    7270
    7371[scriptable, uuid(a6cf90dc-15b3-11d2-932e-00805f8add32)]
     
    10098  void destroyThreadEventQueue();
    10199
    102   nsIEventQueue createFromIThread(in nsIThread aThread,
    103                                   in boolean aNative);
     100  [noscript] nsIEventQueue createFromIThread(in RTTHREAD aThread,
     101                                                                     in boolean aNative);
    104102                               
    105103  [noscript] nsIEventQueue createFromPLEventQueue(in PLEventQueuePtr
     
    113111  void popThreadEventQueue(in nsIEventQueue aQueue);
    114112
    115   [noscript] nsIEventQueue getThreadEventQueue(in PRThreadPtr aThread);
     113  [noscript] nsIEventQueue getThreadEventQueue(in RTTHREAD aThread);
    116114
    117115  /**
  • trunk/src/libs/xpcom18a4/xpcom/threads/plevent.c

    r101990 r102016  
    7474    PRCList             queue;
    7575    PRMonitor*          monitor;
    76     PRThread*           handlerThread;
     76    RTTHREAD            handlerThread;
    7777    EventQueueType      type;
    7878    PRPackedBool        processingEvents;
     
    111111*/
    112112static PLEventQueue * _pl_CreateEventQueue(const char *name,
    113                                            PRThread *handlerThread,
     113                                           RTTHREAD handlerThread,
    114114                                           EventQueueType  qtype)
    115115{
     
    147147
    148148PR_IMPLEMENT(PLEventQueue*)
    149 PL_CreateEventQueue(const char* name, PRThread* handlerThread)
     149PL_CreateEventQueue(const char* name, RTTHREAD handlerThread)
    150150{
    151151    return( _pl_CreateEventQueue( name, handlerThread, EventQueueIsNative ));
     
    153153
    154154PR_EXTERN(PLEventQueue *)
    155 PL_CreateNativeEventQueue(const char *name, PRThread *handlerThread)
     155PL_CreateNativeEventQueue(const char *name, RTTHREAD handlerThread)
    156156{
    157157    return( _pl_CreateEventQueue( name, handlerThread, EventQueueIsNative ));
     
    159159
    160160PR_EXTERN(PLEventQueue *)
    161 PL_CreateMonitoredEventQueue(const char *name, PRThread *handlerThread)
     161PL_CreateMonitoredEventQueue(const char *name, RTTHREAD handlerThread)
    162162{
    163163    return( _pl_CreateEventQueue( name, handlerThread, EventQueueIsMonitored ));
     
    247247    Assert(event != NULL);
    248248
    249     if (PR_GetCurrentThread() == self->handlerThread) {
     249    if (RTThreadSelf() == self->handlerThread) {
    250250        /* Handle the case where the thread requesting the event handling
    251251         * is also the thread that's supposed to do the handling. */
     
    590590       been processed and destroyed or not. */
    591591
    592     Assert(queue->handlerThread == PR_GetCurrentThread());
     592    Assert(queue->handlerThread == RTThreadSelf());
    593593
    594594    PR_EnterMonitor(queue->monitor);
     
    814814PL_IsQueueOnCurrentThread( PLEventQueue *queue )
    815815{
    816     PRThread *me = PR_GetCurrentThread();
    817     return me == queue->handlerThread;
     816    return queue->handlerThread == RTThreadSelf();
    818817}
    819818
  • trunk/src/libs/xpcom18a4/xpcom/threads/plevent.h

    r101981 r102016  
    187187#include "prtypes.h"
    188188#include "prclist.h"
    189 #include "prthread.h"
    190189#include "prcvar.h"
    191190#include "prmon.h"
     
    193192#include <iprt/critsect.h>
    194193#include <iprt/semaphore.h>
     194#include <iprt/thread.h>
    195195
    196196#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
     
    238238*/
    239239PR_EXTERN(PLEventQueue*)
    240 PL_CreateEventQueue(const char* name, PRThread* handlerThread);
     240PL_CreateEventQueue(const char* name, RTTHREAD handlerThread);
    241241
    242242
     
    261261**  name:   A name, as a diagnostic aid.
    262262**
    263 **  handlerThread: A pointer to the PRThread structure for
     263**  handlerThread: A pointer to the IPRT thread structure for
    264264** the thread that will "handle" events posted to this event
    265265** queue.
     
    272272    PL_CreateNativeEventQueue(
    273273        const char *name,
    274         PRThread *handlerThread
     274        RTTHREAD handlerThread
    275275    );
    276276
     
    290290**  name:   A name, as a diagnostic aid.
    291291**
    292 **  handlerThread: A pointer to the PRThread structure for
     292**  handlerThread: A pointer to the IPRT thread structure for
    293293** the thread that will "handle" events posted to this event
    294294** queue.
     
    301301    PL_CreateMonitoredEventQueue(
    302302        const char *name,
    303         PRThread *handlerThread
     303        RTTHREAD handlerThread
    304304    );
    305305
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