Ejemplo n.º 1
0
 INLINE void InitTaskList(int task_list_size, int* task_list, int thread_num, int cur_thread)
 {
     int task_slice = task_list_size / thread_num;
     int task_slice_rest = task_list_size % thread_num;
     
     // cur_thread takes it's slice of tasks
     for (int index = 0; index < task_slice; index++) {
         PushHead(task_list[cur_thread * task_slice + index]);
     }
     
     // Thread 0 takes remaining ready tasks 
     if (cur_thread == 0) {
         for (int index = 0; index < task_slice_rest; index++) {
             PushHead(task_list[thread_num * task_slice + index]);
         }
     }
 }
Ejemplo n.º 2
0
        void Rotate(int nRotate)
        {
            // quick fix
            // need optimization

            if(!Empty()){
                if(auto nCount = std::abs(nRotate)){
                    if(nRotate > 0){
                        for(auto nIndex = 0; nIndex < nCount; ++nIndex){
                            auto stHead = Head();
                            PopHead();
                            PushBack(stHead);
                        }
                    }else{
                        for(auto nIndex = 0; nIndex < nCount; ++nIndex){
                            auto stBack = Back();
                            PopBack();
                            PushHead(stBack);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
void CMyList::PushIndex(int idx, void *tagData)
{

    if (idx <= 0)
    {
        PushHead(tagData);
        return;
    }
    if (idx >= m_NodeCount)
    {
        PushBack(tagData);
        return;
    }

    MYLIST_NODE *pNewNode = (MYLIST_NODE *) GetMem(sizeof(MYLIST_NODE));
    pNewNode->pData = tagData;
    pNewNode->pNext = NULL;

    Lock();
    MYLIST_NODE *pPrev = NULL, *pCurr = m_MyListHead;
    for (int i=0; i<idx; i++)
    {
        pPrev = pCurr;
        pCurr = pCurr->pNext;
    }
    if (pPrev)
    {
        pPrev->pNext = pNewNode;
        pNewNode->pNext = pCurr;
    }
    else
    {
        m_MyListHead = pNewNode;
    }
    m_NodeCount++;
    UnLock();
}