VirtualBox

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


Ignore:
Timestamp:
Nov 8, 2023 11:04:10 AM (15 months ago)
Author:
vboxsync
Message:

libs/xpcom: Convert nsThread.{cpp,h} to the IPRT RTTls* API, bugref:10545

Location:
trunk/src/libs/xpcom18a4/xpcom/threads
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/xpcom/threads/nsThread.cpp

    r1 r101960  
    4141#include "nsAutoLock.h"
    4242
    43 PRUintn nsThread::kIThreadSelfIndex = 0;
     43#include <iprt/assert.h>
     44
     45RTTLS nsThread::kIThreadSelfIndex = NIL_RTTLS;
    4446static nsIThread *gMainThread = 0;
    4547
     
    135137}
    136138
    137 void
     139DECLCALLBACK(void)
    138140nsThread::Exit(void* arg)
    139141{
     
    349351nsThread::RegisterThreadSelf()
    350352{
    351     PRStatus status;
    352 
    353     if (kIThreadSelfIndex == 0) {
    354         status = PR_NewThreadPrivateIndex(&kIThreadSelfIndex, Exit);
    355         if (status != PR_SUCCESS) return NS_ERROR_FAILURE;
    356     }
    357 
    358     status = PR_SetThreadPrivate(kIThreadSelfIndex, this);
    359     if (status != PR_SUCCESS) return NS_ERROR_FAILURE;
     353    int vrc;
     354
     355    if (kIThreadSelfIndex == NIL_RTTLS) {
     356        vrc = RTTlsAllocEx(&kIThreadSelfIndex, Exit);
     357        if (RT_FAILURE(vrc)) return NS_ERROR_FAILURE;
     358    }
     359
     360    vrc = RTTlsSet(kIThreadSelfIndex, this);
     361    if (RT_FAILURE(vrc)) return NS_ERROR_FAILURE;
    360362
    361363    return NS_OK;
     
    380382nsIThread::GetIThread(PRThread* prthread, nsIThread* *result)
    381383{
    382     PRStatus status;
    383384    nsThread* thread;
    384385
    385     if (nsThread::kIThreadSelfIndex == 0) {
    386         status = PR_NewThreadPrivateIndex(&nsThread::kIThreadSelfIndex, nsThread::Exit);
    387         if (status != PR_SUCCESS) return NS_ERROR_FAILURE;
    388     }
    389 
    390     thread = (nsThread*)PR_GetThreadPrivate(nsThread::kIThreadSelfIndex);
     386    if (nsThread::kIThreadSelfIndex == NIL_RTTLS) {
     387        int vrc = RTTlsAllocEx(&nsThread::kIThreadSelfIndex, nsThread::Exit);
     388        if (RT_FAILURE(vrc)) return NS_ERROR_FAILURE;
     389    }
     390
     391    thread = (nsThread*)RTTlsGet(nsThread::kIThreadSelfIndex);
    391392    if (thread == nsnull) {
    392393        // if the current thread doesn't have an nsIThread associated
     
    450451        NS_WARN_IF_FALSE(cnt == 0, "Main thread being held past XPCOM shutdown.");
    451452        gMainThread = nsnull;
    452        
    453         kIThreadSelfIndex = 0;
     453
     454        int vrc = RTTlsFree(kIThreadSelfIndex);
     455        AssertRC(vrc); RT_NOREF(vrc);
     456        kIThreadSelfIndex = NIL_RTTLS;
    454457    }
    455458}
  • trunk/src/libs/xpcom18a4/xpcom/threads/nsThread.h

    r1 r101960  
    5454#include "nsCOMPtr.h"
    5555
     56#include <iprt/thread.h>
     57
    5658class nsThread : public nsIThread
    5759{
     
    7072
    7173    static void PR_CALLBACK Main(void* arg);
    72     static void PR_CALLBACK Exit(void* arg);
     74    static DECLCALLBACK(void) Exit(void* arg);
    7375    static void PR_CALLBACK Shutdown();
    7476
    75     static PRUintn kIThreadSelfIndex;
     77    static RTTLS kIThreadSelfIndex;
    7678
    7779    static NS_METHOD
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