VirtualBox

Changeset 86619 in vbox for trunk


Ignore:
Timestamp:
Oct 16, 2020 11:16:42 PM (4 years ago)
Author:
vboxsync
Message:

tstIprtList.cpp: Ditto insert(). Created common index generator function with improved range. bugref:9841

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstIprtList.cpp

    r86618 r86619  
    526526}
    527527
     528/** Returns an index that is safe from the removal thread. */
     529static uint32_t MtTestSafeRandomIndex(MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList)
     530{
     531    uint32_t cItems = (uint32_t)pTestList->size();
     532    if (cItems > MTTEST_ITEMS)
     533        cItems -= MTTEST_ITEMS;
     534    if (cItems < MTTEST_ITEMS_NOT_REMOVED)
     535        cItems = MTTEST_ITEMS_NOT_REMOVED;
     536    return RTRandU32Ex(0, cItems - 1);
     537}
     538
    528539/**
    529540 * Thread for inserting items to a shared list.
     
    539550    /* Insert new items in the middle of the list. */
    540551    for (size_t i = 0; i < MTTEST_ITEMS; ++i)
    541         pTestList->insert(pTestList->size() / 2, 0xF0F0F0F0);
     552        pTestList->insert(MtTestSafeRandomIndex(pTestList), 0xF0F0F0F0);
    542553
    543554    return VINF_SUCCESS;
     
    562573        while (pTestList->isEmpty())
    563574            RTThreadYield();
    564         uint32_t const idx = RTRandU32Ex(0, RT_MIN((uint32_t)pTestList->size() / 2, MTTEST_ITEMS_NOT_REMOVED));
    565         a = pTestList->at(idx);
     575        a = pTestList->at(MtTestSafeRandomIndex(pTestList));
    566576    }
    567577
     
    586596        while (pTestList->isEmpty())
    587597            RTThreadYield();
    588         uint32_t const idx = RTRandU32Ex(0, RT_MIN((uint32_t)pTestList->size() / 2, MTTEST_ITEMS_NOT_REMOVED));
    589         pTestList->replace(idx, 0xFF00FF00);
     598        pTestList->replace(MtTestSafeRandomIndex(pTestList), 0xFF00FF00);
    590599    }
    591600
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