void EventQueue::ProcessEvents() { auto& current_queue = mQueues[mCurrentQueue]; SwapQueues(); for (auto& event : current_queue) { for (auto& listener : mListeners) { listener->OnEvent(*event); } } current_queue.clear(); }
// SELECTS NEXT RUNNING THREAD void schedule(){ // IF RUNNING THREAD IS NOT FINISHED // PUTS THE THREAD IN ONE OF THE TWO // ABLE QUEUES if(runningThread->state != FINISHED){ DecreaseCredits(runningThread); if(runningThread->state == ABLE){ if (runningThread->credReal == 0){ expiredThreads = AddThread(expiredThreads, runningThread); } else{ activeThreads = AddThread(activeThreads, runningThread); } } else{ if(runningThread->state == BLOCKED){ if(mutexBlock){ //if it was blocked while locking a mutex //reset the flag and it was added to another queue //in the pilock function mutexBlock = 0; } else{ blockedThreads = AddThread(blockedThreads, runningThread); } } } } else{ // IF THE THREAD IS FINISHED, // FREE THE TCB MEMORY free(runningThread); } // SELECTS NEXT THREAD TO RUN runningThread = activeThreads; if (runningThread == NULL){ SwapQueues(&activeThreads, &expiredThreads); activeThreads = RestoreCredits(activeThreads); runningThread = activeThreads; } activeThreads = activeThreads->next; runningThread->next = NULL; runningThread->prev = NULL; if(activeThreads) activeThreads->prev = NULL; runningThread->state = EXECUTION; setcontext(&runningThread->context); }