void AggressorAI::UpdateAI(const uint32 /*diff*/) { // update i_victimGuid if m_creature->getVictim() != 0 and changed Unit* pVictim = SelectVictim(); if (!pVictim) return; i_victimGuid = pVictim->GetObjectGuid(); DoMeleeAttackIfReady(); }
NewPage LRU::FixNewPage(LBA lba) { NewPage np; np.frame_id = -1; np.page_id = -1; int pid = -1; int frid = -1; LRUBCB* pb = NULL; /* 申请分配新数据页 */ f_alloc_page(1, &pid); if (pid == -1) printf("there is no free page in the flash memory"); ASSERT(pid >= 0); /*注册映射项*/ RegistEntry(lba,pid); /* 在缓冲区中寻找空闲块,用于存储新数据页中的数据*/ frid = SelectVictim(); ftop[frid] = pid; pb = ptob[hash(pid)]; /*将新的LRUBCB链接到桶的尾部*/ if ( pb != NULL) { while( pb->next != NULL) { pb = pb->next; } pb->next = new LRUBCB(); pb = pb->next; } else //桶为空 { pb = new LRUBCB(); ptob[hash(pid)] = pb; } pb->dirty = 0; pb->frame_id = frid; pb->page_id = pid; pb->next = NULL; InsertLRUEle(frid); np.frame_id = frid; np.page_id = pid; return np; }
void Execute() { switch(RandomProvider.GetNextAction()) { case ActionType::Allocate: { // Allocate an object of a random size. int size = RandomProvider.GetNextObjectSize(); void* object = Allocator->Allocate(size); if(object == 0) { std::cout<<"Object could not be allocated!"; std::cout<<"Consider building in 64 bit mode."; exit(-1); } TouchData(object, size); InsertObject(object); break; } case ActionType::Deallocate: { if(PassedObjects.size() > 0) { EnterCriticalSection(&PassedObjectsLock); void* object = *(PassedObjects.end() - 1); PassedObjects.pop_back(); LeaveCriticalSection(&PassedObjectsLock); if(!VerifyData(object)) { std::cout<<"Data corruption detected!\n"; } Allocator->Deallocate(object); } if(Objects.size() > 0 && (deallocateObjects != Objects.size())) { // Randomly select an object to be deallocated. int victim = SelectVictim(); if(victim != -1) { // Deallocate the object and insert the location // in the list of unused positions to be used when allocating. void* object = Objects[victim]; if(!VerifyData(object)) { std::cout<<"Data corruption detected!\n"; } Allocator->Deallocate(object); ResetSlot(victim); } } break; } case ActionType::Pass: { if(Threads.size() > 0 && Objects.size() > 0 && (deallocateObjects != Objects.size())) { // Select an object to be passed to one of the other threads. int victim = SelectVictim(); if(victim != -1) { int otherThread = RandomProvider.GetNextInt(Threads.size()); ThreadData* otherThreadData = Threads[otherThread]; void* object = Objects[victim]; ResetSlot(victim); EnterCriticalSection(&otherThreadData->PassedObjectsLock); otherThreadData->PassedObjects.push_back(object); LeaveCriticalSection(&otherThreadData->PassedObjectsLock); } } break; } } }
int LRU::FixPage(int page_id) { ASSERT(page_id >= 0); int frid = -1; int rv = -1; int hk = hash(page_id); LRUBCB* pb = NULL; pb = PageToLRUBCB(page_id); /*读计数加1*/ total++; /*若该页在缓冲区中已存在*/ if (pb != NULL) { frid = pb->frame_id; AdjustLRUList(frid); /*命中次数加1*/ hit++; return frid; } else // 若该页不在缓冲区中 { frid = SelectVictim(); /*正常情形下,此时应该从二级存储器读入需要加载的数据*/ rv = f_read_page(page_id,(BYTE *)(buf[frid].field),0,FRAMESIZE); if(rv == RV_ERROR_INVALID_PAGE_STATE) { printf("page readed is invalid\n"); } if (rv == RV_ERROR_FLASH_BLOCK_BROKEN) { printf("the block contained this page is broken \n"); } flashreadcount++; ftop[frid] = page_id; pb = ptob[hk]; /*将新的LRUBCB链接到桶的尾部*/ if ( pb != NULL) { while( pb->next != NULL) { pb = pb->next; } pb->next = new LRUBCB(); pb = pb->next; } else //桶为空 { pb = new LRUBCB(); ptob[hk] = pb; } pb->dirty = 0; pb->frame_id = frid; pb->page_id = page_id; pb->next = NULL; InsertLRUEle(frid); return frid; } }