コード例 #1
0
 void initialPopulate() {
     TURF_ASSERT(m_addIndex == m_removeIndex);
     MapAdapter::Map *map = m_shared.map;
     for (ureg i = 0; i < m_shared.numKeysPerThread; i++) {
         u32 key = m_addIndex * Prime;
         map->insert(key, (void*) (key & ~uptr(3)));
         if (++m_addIndex == m_rangeHi)
             m_addIndex = m_rangeLo;
     }
 }
コード例 #2
0
    void run() {
        MapAdapter::Map *map = m_shared.map;
        turf::CPUTimer::Converter converter;
        Delay delay(m_shared.delayFactor);
        Stats stats;
        ureg lookupIndex = m_rangeLo;
        ureg remaining = m_shared.itersPerChunk;
        if (m_threadIndex == 0)
            m_shared.spinKicker.kick(m_shared.numThreads - 1);
        else {
            remaining = ~u32(0);
            m_shared.spinKicker.waitForKick();
        }

        // ---------
        turf::CPUTimer::Point start = turf::CPUTimer::get();
        for (; remaining > 0; remaining--) {
            // Add
            delay.delay(stats.workUnitsDone);
            if (m_shared.doneFlag.load(turf::Relaxed))
                break;
            u32 key = m_addIndex * Prime;
            if (key >= 2) {
                map->insert(key, (void*) uptr(key));
                stats.mapOpsDone++;
            }
            if (++m_addIndex == m_rangeHi)
                m_addIndex = m_rangeLo;

            // Lookup
            if (s32(lookupIndex - m_removeIndex) < 0)
                lookupIndex = m_removeIndex;
            for (ureg l = 0; l < m_shared.readsPerWrite; l++) {
                delay.delay(stats.workUnitsDone);
                if (m_shared.doneFlag.load(turf::Relaxed))
                    break;
                key = lookupIndex * Prime;
                if (key >= 2) {
                    volatile void* value = map->get(key);
                    TURF_UNUSED(value);
                    stats.mapOpsDone++;
                }
                if (++lookupIndex == m_rangeHi)
                    lookupIndex = m_rangeLo;
                if (lookupIndex == m_addIndex)
                    lookupIndex = m_removeIndex;
            }

            // Remove
            delay.delay(stats.workUnitsDone);
            if (m_shared.doneFlag.load(turf::Relaxed))
                break;
            key = m_removeIndex * Prime;
            if (key >= 2) {
                map->erase(key);
                stats.mapOpsDone++;
            }
            if (++m_removeIndex == m_rangeHi)
                m_removeIndex = m_rangeLo;

            // Lookup
            if (s32(lookupIndex - m_removeIndex) < 0)
                lookupIndex = m_removeIndex;
            for (ureg l = 0; l < m_shared.readsPerWrite; l++) {
                delay.delay(stats.workUnitsDone);
                if (m_shared.doneFlag.load(turf::Relaxed))
                    break;
                key = lookupIndex * Prime;
                if (key >= 2) {
                    volatile void* value = map->get(key);
                    TURF_UNUSED(value);
                    stats.mapOpsDone++;
                }
                if (++lookupIndex == m_rangeHi)
                    lookupIndex = m_rangeLo;
                if (lookupIndex == m_addIndex)
                    lookupIndex = m_removeIndex;
            }
        }
        if (m_threadIndex == 0)
            m_shared.doneFlag.store(1, turf::Relaxed);
        m_threadCtx.update();
        turf::CPUTimer::Point end = turf::CPUTimer::get();
        // ---------

        stats.duration = converter.toSeconds(end - start);
        m_stats = stats;
    }