Index: trunk/src/libs/xpcom18a4/xpcom/build/nsXPCOM.h
===================================================================
--- trunk/src/libs/xpcom18a4/xpcom/build/nsXPCOM.h	(revision 102015)
+++ trunk/src/libs/xpcom18a4/xpcom/build/nsXPCOM.h	(revision 102016)
@@ -41,4 +41,6 @@
 #include "nscore.h"
 #include "nsXPCOMCID.h"
+
+#include <iprt/thread.h>
 
 #ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
@@ -68,4 +70,6 @@
 class nsITraceRefcnt;
 
+typedef RTTHREADINT *RTTHREAD;
+
 #ifdef VBOX
 /**
@@ -74,4 +78,7 @@
 extern "C" NS_COM PRBool
 NS_IsXPCOMInitialized(void);
+
+extern "C" NS_COM nsresult
+NS_GetMainThread(RTTHREAD *phThreadMain);
 #endif
 
Index: trunk/src/libs/xpcom18a4/xpcom/build/nsXPComInit.cpp
===================================================================
--- trunk/src/libs/xpcom18a4/xpcom/build/nsXPComInit.cpp	(revision 102015)
+++ trunk/src/libs/xpcom18a4/xpcom/build/nsXPComInit.cpp	(revision 102016)
@@ -74,6 +74,4 @@
 #include "nsIInterfaceInfoManager.h"
 
-#include "nsThread.h"
-
 #include "nsEmptyEnumerator.h"
 
@@ -119,4 +117,6 @@
 
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsEventQueueServiceImpl, Init)
+
+static RTTHREAD g_hMainThread = 0;
 
 #define NS_ENVIRONMENT_CLASSNAME "Environment Service"
@@ -335,5 +335,4 @@
     COMPONENT(EVENTQUEUESERVICE, nsEventQueueServiceImplConstructor),
     COMPONENT(EVENTQUEUE, nsEventQueueImpl::Create),
-    COMPONENT(THREAD, nsThread::Create),
 
 #define NS_XPCOMPROXY_CID NS_PROXYEVENT_MANAGER_CID
@@ -450,4 +449,14 @@
 #endif
 
+nsresult NS_COM
+NS_GetMainThread(RTTHREAD *phThreadMain)
+{
+    NS_ASSERTION(phThreadMain, "bad result pointer");
+    if (g_hMainThread == NIL_RTTHREAD)
+        return NS_ERROR_FAILURE;
+    *phThreadMain = g_hMainThread;
+    return NS_OK;
+}
+
 nsresult NS_COM NS_InitXPCOM(nsIServiceManager* *result,
                              nsIFile* binDirectory)
@@ -470,6 +479,5 @@
 
     // Establish the main thread here.
-    rv = nsIThread::SetMainThread();
-    if (NS_FAILED(rv)) return rv;
+    g_hMainThread = RTThreadSelf();
 
     // If the locale hasn't already been setup by our embedder,
@@ -872,5 +880,4 @@
     EmptyEnumeratorImpl::Shutdown();
 
-    nsThread::Shutdown();
     NS_PurgeAtomTable();
 
Index: trunk/src/libs/xpcom18a4/xpcom/threads/nsEventQueue.cpp
===================================================================
--- trunk/src/libs/xpcom18a4/xpcom/threads/nsEventQueue.cpp	(revision 102015)
+++ trunk/src/libs/xpcom18a4/xpcom/threads/nsEventQueue.cpp	(revision 102016)
@@ -39,5 +39,4 @@
 #include "nsEventQueue.h"
 #include "nsIEventQueueService.h"
-#include "nsIThread.h"
 
 #include "nsIServiceManager.h"
@@ -125,9 +124,9 @@
 nsEventQueueImpl::Init(PRBool aNative)
 {
-  PRThread *thread = PR_GetCurrentThread();
+  RTTHREAD hThread = RTThreadSelf();
   if (aNative)
-    mEventQueue = PL_CreateNativeEventQueue("Thread event queue...", thread);
+    mEventQueue = PL_CreateNativeEventQueue("Thread event queue...", hThread);
   else
-    mEventQueue = PL_CreateMonitoredEventQueue("Thread event queue...", thread);
+    mEventQueue = PL_CreateMonitoredEventQueue("Thread event queue...", hThread);
   NotifyObservers(gActivatedNotification);
   return NS_OK;
@@ -135,27 +134,21 @@
 
 NS_IMETHODIMP 
-nsEventQueueImpl::InitFromPRThread(PRThread* thread, PRBool aNative)
-{
-  if (thread == NS_CURRENT_THREAD) 
+nsEventQueueImpl::InitFromPRThread(RTTHREAD hThread, PRBool aNative)
+{
+  if (hThread == NS_CURRENT_THREAD) 
   {
-     thread = PR_GetCurrentThread();
-  }
-  else if (thread == NS_UI_THREAD) 
+     hThread = RTThreadSelf();
+  }
+  else if (hThread == NS_UI_THREAD) 
   {
-    nsCOMPtr<nsIThread>  mainIThread;
-    nsresult rv;
-  
     // Get the primordial thread
-    rv = nsIThread::GetMainThread(getter_AddRefs(mainIThread));
+    nsresult rv = NS_GetMainThread(&hThread);
     if (NS_FAILED(rv)) return rv;
-
-    rv = mainIThread->GetPRThread(&thread);
-    if (NS_FAILED(rv)) return rv;
-  }  
+  } 
 
   if (aNative)
-    mEventQueue = PL_CreateNativeEventQueue("Thread event queue...", thread);
+    mEventQueue = PL_CreateNativeEventQueue("Thread event queue...", hThread);
   else
-    mEventQueue = PL_CreateMonitoredEventQueue("Thread event queue...", thread);
+    mEventQueue = PL_CreateMonitoredEventQueue("Thread event queue...", hThread);
   NotifyObservers(gActivatedNotification);
   return NS_OK;
Index: trunk/src/libs/xpcom18a4/xpcom/threads/nsEventQueueService.cpp
===================================================================
--- trunk/src/libs/xpcom18a4/xpcom/threads/nsEventQueueService.cpp	(revision 102015)
+++ trunk/src/libs/xpcom18a4/xpcom/threads/nsEventQueueService.cpp	(revision 102016)
@@ -54,6 +54,7 @@
 #include "prmon.h"
 #include "nsIComponentManager.h"
-#include "nsIThread.h"
 #include "nsPIEventQueueChain.h"
+
+#include "nsXPCOM.h"
 
 #include <VBox/log.h>
@@ -107,13 +108,9 @@
   
   // ensure that a main thread event queue exists!
-  nsresult rv;
-  nsCOMPtr<nsIThread> mainThread;
-  rv = nsIThread::GetMainThread(getter_AddRefs(mainThread));
-  if (NS_SUCCEEDED(rv)) {
-    PRThread *thr;
-    rv = mainThread->GetPRThread(&thr);
-    if (NS_SUCCEEDED(rv))
-      rv = CreateEventQueue(thr, PR_TRUE);
-  }
+  RTTHREAD hMainThread;
+  nsresult rv = NS_GetMainThread(&hMainThread);
+  if (NS_SUCCEEDED(rv))
+    rv = CreateEventQueue(hMainThread, PR_TRUE);
+
   return rv;
 }
@@ -127,5 +124,5 @@
 nsEventQueueServiceImpl::CreateThreadEventQueue()
 {
-  return CreateEventQueue(PR_GetCurrentThread(), PR_TRUE);
+  return CreateEventQueue(RTThreadSelf(), PR_TRUE);
 }
 
@@ -133,20 +130,17 @@
 nsEventQueueServiceImpl::CreateMonitoredThreadEventQueue()
 {
-  return CreateEventQueue(PR_GetCurrentThread(), PR_FALSE);
-}
-
-NS_IMETHODIMP
-nsEventQueueServiceImpl::CreateFromIThread(nsIThread *aThread, PRBool aNative,
+  return CreateEventQueue(RTThreadSelf(), PR_FALSE);
+}
+
+NS_IMETHODIMP
+nsEventQueueServiceImpl::CreateFromIThread(RTTHREAD aThread, PRBool aNative,
                                            nsIEventQueue **aResult)
 {
   nsresult rv;
-  PRThread *prThread;
-
-  rv = aThread->GetPRThread(&prThread);
-  if (NS_SUCCEEDED(rv)) {
-    rv = CreateEventQueue(prThread, aNative); // addrefs
-    if (NS_SUCCEEDED(rv))
-      rv = GetThreadEventQueue(prThread, aResult); // addrefs
-  }
+
+  rv = CreateEventQueue(aThread, aNative); // addrefs
+  if (NS_SUCCEEDED(rv))
+    rv = GetThreadEventQueue(aThread, aResult); // addrefs
+
   return rv;
 }
@@ -154,5 +148,5 @@
 // private method
 NS_IMETHODIMP
-nsEventQueueServiceImpl::MakeNewQueue(PRThread* thread,
+nsEventQueueServiceImpl::MakeNewQueue(RTTHREAD hThread,
                                       PRBool aNative,
                                       nsIEventQueue **aQueue)
@@ -162,6 +156,6 @@
 
   if (NS_SUCCEEDED(rv)) {
-    rv = queue->InitFromPRThread(thread, aNative);
-  }	
+    rv = queue->InitFromPRThread(hThread, aNative);
+  }
   *aQueue = queue;
   NS_IF_ADDREF(*aQueue);
@@ -171,5 +165,5 @@
 // private method
 NS_IMETHODIMP
-nsEventQueueServiceImpl::CreateEventQueue(PRThread *aThread, PRBool aNative)
+nsEventQueueServiceImpl::CreateEventQueue(RTTHREAD aThread, PRBool aNative)
 {
   nsresult rv = NS_OK;
@@ -200,10 +194,10 @@
   PR_EnterMonitor(mEventQMonitor);
 
-  PRThread* currentThread = PR_GetCurrentThread();
-  nsIEventQueue* queue = mEventQTable.GetWeak(currentThread);
+  RTTHREAD hThread = RTThreadSelf();
+  nsIEventQueue* queue = mEventQTable.GetWeak(hThread);
   if (queue) {
     queue->StopAcceptingEvents(); // tell the queue to stop accepting events
     queue = nsnull; // Queue may die on the next line
-    mEventQTable.Remove(currentThread); // remove nsIEventQueue from hash table (releases)
+    mEventQTable.Remove(hThread); // remove nsIEventQueue from hash table (releases)
   }
 
@@ -256,5 +250,5 @@
 {
   nsresult rv = NS_OK;
-  PRThread* currentThread = PR_GetCurrentThread();
+  RTTHREAD hThread = RTThreadSelf();
   PRBool native = PR_TRUE; // native by default as per old comment
 
@@ -265,5 +259,5 @@
   PR_EnterMonitor(mEventQMonitor);
 
-  nsIEventQueue* queue = mEventQTable.GetWeak(currentThread);
+  nsIEventQueue* queue = mEventQTable.GetWeak(hThread);
   
   NS_ASSERTION(queue, "pushed event queue on top of nothing");
@@ -278,9 +272,9 @@
 
   nsIEventQueue* newQueue = nsnull;
-  MakeNewQueue(currentThread, native, &newQueue); // create new queue; addrefs
+  MakeNewQueue(hThread, native, &newQueue); // create new queue; addrefs
 
   if (!queue) {
     // shouldn't happen. as a fallback, we guess you wanted a native queue
-    mEventQTable.Put(currentThread, newQueue);
+    mEventQTable.Put(hThread, newQueue);
   }
 
@@ -307,5 +301,5 @@
 nsEventQueueServiceImpl::PopThreadEventQueue(nsIEventQueue *aQueue)
 {
-  PRThread* currentThread = PR_GetCurrentThread();
+  RTTHREAD hThread = RTThreadSelf();
 
   /* Enter the lock that protects the EventQ hashtable... */
@@ -313,9 +307,9 @@
 
   nsCOMPtr<nsIEventQueue> eldestQueue;
-  mEventQTable.Get(currentThread, getter_AddRefs(eldestQueue));
+  mEventQTable.Get(hThread, getter_AddRefs(eldestQueue));
 
   // If we are popping the eldest queue, remove its mEventQTable entry.
   if (aQueue == eldestQueue)
-    mEventQTable.Remove(currentThread);
+    mEventQTable.Remove(hThread);
 
   // Exit the monitor before processing pending events to avoid deadlock.
@@ -338,24 +332,19 @@
 
 NS_IMETHODIMP
-nsEventQueueServiceImpl::GetThreadEventQueue(PRThread* aThread, nsIEventQueue** aResult)
+nsEventQueueServiceImpl::GetThreadEventQueue(RTTHREAD aThread, nsIEventQueue** aResult)
 {
   /* Parameter validation... */
   if (NULL == aResult) return NS_ERROR_NULL_POINTER;
 
-  PRThread* keyThread = aThread;
+  RTTHREAD keyThread = aThread;
 
   if (keyThread == NS_CURRENT_THREAD)
   {
-     keyThread = PR_GetCurrentThread();
+     keyThread = RTThreadSelf();
   }
   else if (keyThread == NS_UI_THREAD)
   {
-    nsCOMPtr<nsIThread>  mainIThread;
-
     // Get the primordial thread
-    nsresult rv = nsIThread::GetMainThread(getter_AddRefs(mainIThread));
-    if (NS_FAILED(rv)) return rv;
-
-    rv = mainIThread->GetPRThread(&keyThread);
+    nsresult rv = NS_GetMainThread(&keyThread);
     if (NS_FAILED(rv)) return rv;
   }
Index: trunk/src/libs/xpcom18a4/xpcom/threads/nsEventQueueService.h
===================================================================
--- trunk/src/libs/xpcom18a4/xpcom/threads/nsEventQueueService.h	(revision 102015)
+++ trunk/src/libs/xpcom18a4/xpcom/threads/nsEventQueueService.h	(revision 102016)
@@ -65,6 +65,6 @@
                 Addref the descriptor in any case. parameter aNative is
                 ignored if the queue already exists. */
-  NS_IMETHOD CreateEventQueue(PRThread *aThread, PRBool aNative);
-  NS_IMETHOD MakeNewQueue(PRThread* thread, PRBool aNative, nsIEventQueue **aQueue);
+  NS_IMETHOD CreateEventQueue(RTTHREAD aThread, PRBool aNative);
+  NS_IMETHOD MakeNewQueue(RTTHREAD thread, PRBool aNative, nsIEventQueue **aQueue);
   inline nsresult GetYoungestEventQueue(nsIEventQueue *queue, nsIEventQueue **aResult);
 
Index: trunk/src/libs/xpcom18a4/xpcom/threads/nsIEventQueue.idl
===================================================================
--- trunk/src/libs/xpcom18a4/xpcom/threads/nsIEventQueue.idl	(revision 102015)
+++ trunk/src/libs/xpcom18a4/xpcom/threads/nsIEventQueue.idl	(revision 102016)
@@ -46,5 +46,5 @@
 
 %{C++
-#include "prthread.h"
+#include <iprt/thread.h>
 
 // {13D86C61-00A9-11d3-9F2A-00400553EEF0}
@@ -60,5 +60,5 @@
 //
 [ptr] native PLEventQueuePtr(PLEventQueue);
-[ptr] native PRThreadPtr(PRThread);
+[ptr] native RTTHREAD(RTTHREADINT);
 native PRStatus(PRStatus);
 [ref] native PRBoolRef(PRBool);
@@ -89,5 +89,5 @@
 
     void init(in boolean aNative);
-    [noscript] void initFromPRThread(in PRThreadPtr thread, 
+    [noscript] void initFromPRThread(in RTTHREAD thread, 
                                      in boolean aNative);
     [noscript] void initFromPLQueue(in PLEventQueuePtr aQueue);
Index: trunk/src/libs/xpcom18a4/xpcom/threads/nsIEventQueueService.idl
===================================================================
--- trunk/src/libs/xpcom18a4/xpcom/threads/nsIEventQueueService.idl	(revision 102015)
+++ trunk/src/libs/xpcom18a4/xpcom/threads/nsIEventQueueService.idl	(revision 102016)
@@ -49,6 +49,7 @@
 
 %{C++
-#include "prthread.h"
 #include "plevent.h"
+
+#include <iprt/thread.h>
 
 /* be761f00-a3b0-11d2-996c-0080c7cb1080 */
@@ -60,14 +61,11 @@
 #define NS_EVENTQUEUESERVICE_CLASSNAME "Event Queue Service"
 
-#define NS_CURRENT_THREAD    ((PRThread*)0)
+#define NS_CURRENT_THREAD    ((RTTHREAD)0)
 #define NS_CURRENT_EVENTQ    ((nsIEventQueue*)0)
 
-#define NS_UI_THREAD         ((PRThread*)1)
+#define NS_UI_THREAD         ((RTTHREAD)1)
 #define NS_UI_THREAD_EVENTQ  ((nsIEventQueue*)1)
 
 %}
-
-/* a forward decl */
-interface nsIThread;
 
 [scriptable, uuid(a6cf90dc-15b3-11d2-932e-00805f8add32)]
@@ -100,6 +98,6 @@
   void destroyThreadEventQueue();
 
-  nsIEventQueue createFromIThread(in nsIThread aThread, 
-				  in boolean aNative);
+  [noscript] nsIEventQueue createFromIThread(in RTTHREAD aThread, 
+				                                     in boolean aNative);
                                
   [noscript] nsIEventQueue createFromPLEventQueue(in PLEventQueuePtr 
@@ -113,5 +111,5 @@
   void popThreadEventQueue(in nsIEventQueue aQueue);
 
-  [noscript] nsIEventQueue getThreadEventQueue(in PRThreadPtr aThread);
+  [noscript] nsIEventQueue getThreadEventQueue(in RTTHREAD aThread);
 
   /**
Index: trunk/src/libs/xpcom18a4/xpcom/threads/plevent.c
===================================================================
--- trunk/src/libs/xpcom18a4/xpcom/threads/plevent.c	(revision 102015)
+++ trunk/src/libs/xpcom18a4/xpcom/threads/plevent.c	(revision 102016)
@@ -74,5 +74,5 @@
     PRCList             queue;
     PRMonitor*          monitor;
-    PRThread*           handlerThread;
+    RTTHREAD            handlerThread;
     EventQueueType      type;
     PRPackedBool        processingEvents;
@@ -111,5 +111,5 @@
 */
 static PLEventQueue * _pl_CreateEventQueue(const char *name,
-                                           PRThread *handlerThread,
+                                           RTTHREAD handlerThread,
                                            EventQueueType  qtype)
 {
@@ -147,5 +147,5 @@
 
 PR_IMPLEMENT(PLEventQueue*)
-PL_CreateEventQueue(const char* name, PRThread* handlerThread)
+PL_CreateEventQueue(const char* name, RTTHREAD handlerThread)
 {
     return( _pl_CreateEventQueue( name, handlerThread, EventQueueIsNative ));
@@ -153,5 +153,5 @@
 
 PR_EXTERN(PLEventQueue *)
-PL_CreateNativeEventQueue(const char *name, PRThread *handlerThread)
+PL_CreateNativeEventQueue(const char *name, RTTHREAD handlerThread)
 {
     return( _pl_CreateEventQueue( name, handlerThread, EventQueueIsNative ));
@@ -159,5 +159,5 @@
 
 PR_EXTERN(PLEventQueue *)
-PL_CreateMonitoredEventQueue(const char *name, PRThread *handlerThread)
+PL_CreateMonitoredEventQueue(const char *name, RTTHREAD handlerThread)
 {
     return( _pl_CreateEventQueue( name, handlerThread, EventQueueIsMonitored ));
@@ -247,5 +247,5 @@
     Assert(event != NULL);
 
-    if (PR_GetCurrentThread() == self->handlerThread) {
+    if (RTThreadSelf() == self->handlerThread) {
         /* Handle the case where the thread requesting the event handling
          * is also the thread that's supposed to do the handling. */
@@ -590,5 +590,5 @@
        been processed and destroyed or not. */
 
-    Assert(queue->handlerThread == PR_GetCurrentThread());
+    Assert(queue->handlerThread == RTThreadSelf());
 
     PR_EnterMonitor(queue->monitor);
@@ -814,6 +814,5 @@
 PL_IsQueueOnCurrentThread( PLEventQueue *queue )
 {
-    PRThread *me = PR_GetCurrentThread();
-    return me == queue->handlerThread;
+    return queue->handlerThread == RTThreadSelf();
 }
 
Index: trunk/src/libs/xpcom18a4/xpcom/threads/plevent.h
===================================================================
--- trunk/src/libs/xpcom18a4/xpcom/threads/plevent.h	(revision 102015)
+++ trunk/src/libs/xpcom18a4/xpcom/threads/plevent.h	(revision 102016)
@@ -187,5 +187,4 @@
 #include "prtypes.h"
 #include "prclist.h"
-#include "prthread.h"
 #include "prcvar.h"
 #include "prmon.h"
@@ -193,4 +192,5 @@
 #include <iprt/critsect.h>
 #include <iprt/semaphore.h>
+#include <iprt/thread.h>
 
 #ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
@@ -238,5 +238,5 @@
 */
 PR_EXTERN(PLEventQueue*)
-PL_CreateEventQueue(const char* name, PRThread* handlerThread);
+PL_CreateEventQueue(const char* name, RTTHREAD handlerThread);
 
 
@@ -261,5 +261,5 @@
 **  name:   A name, as a diagnostic aid.
 ** 
-**  handlerThread: A pointer to the PRThread structure for
+**  handlerThread: A pointer to the IPRT thread structure for
 ** the thread that will "handle" events posted to this event
 ** queue.
@@ -272,5 +272,5 @@
     PL_CreateNativeEventQueue(
         const char *name, 
-        PRThread *handlerThread
+        RTTHREAD handlerThread
     );
 
@@ -290,5 +290,5 @@
 **  name:   A name, as a diagnostic aid.
 ** 
-**  handlerThread: A pointer to the PRThread structure for
+**  handlerThread: A pointer to the IPRT thread structure for
 ** the thread that will "handle" events posted to this event
 ** queue.
@@ -301,5 +301,5 @@
     PL_CreateMonitoredEventQueue(
         const char *name,
-        PRThread *handlerThread
+        RTTHREAD handlerThread
     );
 
