VirtualBox

Changeset 77982 in vbox for trunk


Ignore:
Timestamp:
Apr 2, 2019 10:23:09 AM (6 years ago)
Author:
vboxsync
Message:

IPRT: Addressed todo in rtSchedNativeCheckThreadTypes (sched-linux.cpp) about limiting the transition checking to thread types that are actually in use. bugref:7929

Location:
trunk/src/VBox/Runtime
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/thread.cpp

    r76553 r77982  
    7373*   Global Variables                                                                                                             *
    7474*********************************************************************************************************************************/
    75 /** The AVL thread containing the threads. */
    76 static PAVLPVNODECORE       g_ThreadTree;
    77 /** The number of threads in the tree (for ring-0 termination kludge). */
    78 static uint32_t volatile    g_cThreadInTree;
     75/** Indicates whether we've been initialized or not. */
     76static bool                     g_frtThreadInitialized;
    7977#ifdef IN_RING3
    8078/** The RW lock protecting the tree. */
    81 static RTSEMRW          g_ThreadRWSem = NIL_RTSEMRW;
     79static RTSEMRW                  g_ThreadRWSem = NIL_RTSEMRW;
    8280#else
    8381/** The spinlocks protecting the tree. */
    84 static RTSPINLOCK       g_ThreadSpinlock = NIL_RTSPINLOCK;
    85 #endif
    86 /** Indicates whether we've been initialized or not. */
    87 static bool             g_frtThreadInitialized;
     82static RTSPINLOCK               g_ThreadSpinlock = NIL_RTSPINLOCK;
     83#endif
     84/** The AVL thread containing the threads. */
     85static PAVLPVNODECORE           g_ThreadTree;
     86/** The number of threads in the tree (for ring-0 termination kludge). */
     87static uint32_t volatile        g_cThreadInTree;
     88/** Counters for each thread type. */
     89DECLHIDDEN(uint32_t volatile)   g_acRTThreadTypeStats[RTTHREADTYPE_END];
    8890
    8991
     
    460462                ASMAtomicOrU32(&pThread->fIntFlags, RTTHREADINT_FLAG_IN_TREE);
    461463                if (fRc)
     464                {
    462465                    ASMAtomicIncU32(&g_cThreadInTree);
     466                    ASMAtomicIncU32(&g_acRTThreadTypeStats[pThread->enmType]);
     467                }
    463468
    464469                AssertReleaseMsg(fRc, ("Lock problem? %p (%RTnthrd) %s\n", pThread, NativeThread, pThread->szName));
     
    481486{
    482487    PRTTHREADINT pThread2 = (PRTTHREADINT)RTAvlPVRemove(&g_ThreadTree, pThread->Core.Key);
    483 #if !defined(RT_OS_OS2) /** @todo this asserts for threads created by NSPR */
    484488    AssertMsg(pThread2 == pThread, ("%p(%s) != %p (%p/%s)\n", pThread2, pThread2  ? pThread2->szName : "<null>",
    485489                                    pThread, pThread->Core.Key, pThread->szName));
    486 #endif
    487490    if (pThread2)
     491    {
    488492        ASMAtomicDecU32(&g_cThreadInTree);
     493        ASMAtomicDecU32(&g_acRTThreadTypeStats[pThread->enmType]);
     494    }
    489495}
    490496
  • trunk/src/VBox/Runtime/include/internal/thread.h

    r77910 r77982  
    137137/** @} */
    138138
     139/** Counters for each thread type. */
     140extern DECLHIDDEN(uint32_t volatile)   g_acRTThreadTypeStats[RTTHREADTYPE_END];
     141
    139142
    140143/**
  • trunk/src/VBox/Runtime/r3/linux/sched-linux.cpp

    r77917 r77982  
    5454#include <errno.h>
    5555#include <pthread.h>
     56#include <limits.h>
    5657#include <sched.h>
    5758#include <unistd.h>
     
    542543
    543544    /*
    544      * Set the priority to the current value for specified thread type
    545      */
    546     if (setpriority(PRIO_PROCESS, 0, pPrioPair->iCurrent))
    547         rc = RTErrConvertFromErrno(errno);
     545     * Set the priority to the current value for specified thread type, but
     546     * only if we have any threads of this type (caller checked - INT_MAX).
     547     */
     548    if (pPrioPair->iCurrent != INT_MAX)
     549        if (setpriority(PRIO_PROCESS, 0, pPrioPair->iCurrent))
     550            rc = RTErrConvertFromErrno(errno);
    548551
    549552    /*
     
    572575static int rtSchedNativeCheckThreadTypes(const PROCPRIORITY *pCfg, bool fHavePriorityProxy)
    573576{
    574     /** @todo Only check transitions of thread types that actually are in use.
    575      * For the others, just check we can create threads with the new priority
    576      * scheme (ignoring the old). Best done by having an array of
    577      * per-threadtype counters in common/misc/thread.cpp. */
    578577    int i = RTTHREADTYPE_END;
    579578    while (--i > RTTHREADTYPE_INVALID)
     
    582581        PrioPair.iCurrent = g_pProcessPriority->paTypes[i].iPriority + g_pProcessPriority->iDelta;
    583582        PrioPair.iNew     = pCfg->paTypes[i].iPriority               + pCfg->iDelta;
     583        if (g_acRTThreadTypeStats[i] == 0)
     584            PrioPair.iCurrent = INT_MAX;
    584585
    585586#ifdef RT_STRICT
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