コード例 #1
0
ファイル: threadpool.cpp プロジェクト: chewein/x265
ThreadPoolImpl::ThreadPoolImpl(int numThreads)
    : m_ok(false)
    , m_referenceCount(1)
    , m_firstProvider(NULL)
    , m_lastProvider(NULL)
{
    if (numThreads == 0)
        numThreads = getCpuCount();
    m_numSleepMapWords = (numThreads + 63) >> 6;
    m_sleepMap = X265_MALLOC(uint64_t, m_numSleepMapWords);

    char *buffer = (char*)X265_MALLOC(PoolThread, numThreads);
    m_threads = reinterpret_cast<PoolThread*>(buffer);
    m_numThreads = numThreads;

    if (m_threads && m_sleepMap)
    {
        for (int i = 0; i < m_numSleepMapWords; i++)
        {
            m_sleepMap[i] = 0;
        }

        m_ok = true;
        int i;
        for (i = 0; i < numThreads; i++)
        {
            new (buffer)PoolThread(*this, i);
            buffer += sizeof(PoolThread);
            if (!m_threads[i].start())
            {
                m_ok = false;
                break;
            }
        }

        if (m_ok)
        {
            waitForAllIdle();
        }
        else
        {
            // stop threads that did start up
            for (int j = 0; j < i; j++)
            {
                m_threads[j].poke();
                m_threads[j].stop();
            }
        }
    }
}
コード例 #2
0
ファイル: scalinglist.cpp プロジェクト: 5432935/libbpg
bool ScalingList::init()
{
    bool ok = true;
    for (int sizeId = 0; sizeId < NUM_SIZES; sizeId++)
    {
        for (int listId = 0; listId < NUM_LISTS; listId++)
        {
            m_scalingListCoef[sizeId][listId] = X265_MALLOC(int32_t, X265_MIN(MAX_MATRIX_COEF_NUM, s_numCoefPerSize[sizeId]));
            ok &= !!m_scalingListCoef[sizeId][listId];
            for (int rem = 0; rem < NUM_REM; rem++)
            {
                m_quantCoef[sizeId][listId][rem] = X265_MALLOC(int32_t, s_numCoefPerSize[sizeId]);
                m_dequantCoef[sizeId][listId][rem] = X265_MALLOC(int32_t, s_numCoefPerSize[sizeId]);
                ok &= m_quantCoef[sizeId][listId][rem] && m_dequantCoef[sizeId][listId][rem];
            }
        }
    }
    return ok;
}
コード例 #3
0
ファイル: threadpool.cpp プロジェクト: JamesLinus/x265
bool ThreadPool::create(int numThreads, int maxProviders, int node)
{
    X265_CHECK(numThreads <= MAX_POOL_THREADS, "a single thread pool cannot have more than MAX_POOL_THREADS threads\n");

    m_numaNode = node;
    m_numWorkers = numThreads;

    m_workers = X265_MALLOC(WorkerThread, numThreads);
    /* placement new initialization */
    if (m_workers)
        for (int i = 0; i < numThreads; i++)
            new (m_workers + i)WorkerThread(*this, i);

    m_jpTable = X265_MALLOC(JobProvider*, maxProviders);
    m_numProviders = 0;

    return m_workers && m_jpTable;
}