bool CNetConnection::StealFrom(CNameObject * pObject,UINT Param) { CAutoLock Lock1(m_RecvLock); CAutoLock Lock2(m_SendLock); PrintNetLog(0xffffffff,"(%d)执行连接替换(%d)!",GetID(),pObject->GetID()); if(pObject->IsKindOf(GET_CLASS_INFO(CNetConnection))) { Destory(); if(!CNameObject::StealFrom(pObject,Param)) return false; CNetConnection * pConnection=(CNetConnection *)pObject; if(!m_Socket.StealFrom(&(pConnection->m_Socket),Param)) return false; m_pServer=pConnection->m_pServer; m_WantClose=pConnection->m_WantClose; m_pEpollEventRouter=pConnection->m_pEpollEventRouter; pConnection->m_pEpollEventRouter=NULL; if(m_pEpollEventRouter) m_pEpollEventRouter->SetEventHander(this); CEpollEventObject * pEpollEventObject; m_RecvQueue.Create(pConnection->m_RecvQueue.GetBufferSize()); while(pConnection->m_RecvQueue.PopFront(pEpollEventObject)) { m_RecvQueue.PushBack(pEpollEventObject); } m_SendQueue.Create(pConnection->m_SendQueue.GetBufferSize()); while(pConnection->m_SendQueue.PopFront(pEpollEventObject)) { m_SendQueue.PushBack(pEpollEventObject); } return true; } return false; }
void CPartyMng::Worker( void ) { CPlayer* pMember; HANDLE hHandle = m_hCloseWorker; while( WaitForSingleObject( hHandle, 1000 ) == WAIT_TIMEOUT ) { CTime timeCurr = CTime::GetCurrentTime(); CMclAutoLock Lock( g_PlayerMng.m_AddRemoveLock ); CMclAutoLock Lock2( m_AddRemoveLock ); for( C2PartyPtr::iterator i = m_2PartyPtr.begin(); i != m_2PartyPtr.end(); ) { CParty* pParty = (CParty*)i->second; ++i; if( pParty->m_nReferens > 0 ) { for( int j = 1; j < pParty->m_nSizeofMember; j++ ) { if( pParty->m_aMember[j].m_uPlayerId != 0 && pParty->m_aMember[j].m_bRemove ) { if( timeCurr.GetTime() - pParty->m_aMember[j].m_tTime.GetTime() > 60 * 10 ) // 10분 : 60 * 10 // 지금은 1분 { u_long idMember = pParty->GetPlayerId( j ); if( pParty->DeleteMember( idMember ) ) { pParty->m_nReferens--; g_dpCoreSrvr.SendRemoveParty( pParty->m_uPartyId, pParty->m_aMember[0].m_uPlayerId, idMember ); if( pParty->GetSizeofMember() < 2 ) { pMember = g_PlayerMng.GetPlayer( pParty->GetPlayerId( 0 ) ); if( pMember ) pMember->m_uPartyId = 0; DeleteParty( pParty->m_uPartyId ); break; } if( pParty->m_nReferens == 0 ) break; } } } } // for } // if // 파티모드를 체크 for( int j = 0 ; j < MAX_PARTYMODE ; j++ ) { if( pParty->m_nModeTime[j] ) { #if __VER >= 12 // __PARSKILL1001 //12차 파스킬 아이템 수정 world,core,neuz if( j == PARTY_PARSKILL_MODE) continue; #endif //__PARSKILL1001 //12차 파스킬 아이템 수정 world,core,neuz pParty->m_nModeTime[j] -= 1000; if( pParty->m_nModeTime[j] <= 0 ) { pParty->m_nModeTime[j] = 0; g_dpCoreSrvr.SendSetPartyMode( pParty->m_uPartyId, j, FALSE ); } } } } // for // TRACE( "Worker Party\n" ); } }
void VDBFlushMgr::MainLoop() { VDebugContext& context = VTask::GetCurrent()->GetDebugContext(); context.StartLowLevelMode(); sLONG nbpass = 1; Boolean AuMoinsUnFlushTreeNonVide; fIsFlushing = true; if (VDBMgr::GetActivityManager() != nil) VDBMgr::GetActivityManager()->SetActivityWrite(true, -1); /* VGoldfingerSysTrayServer* systray = VGoldfingerSysTrayServer::GetSysTray(); if ( NULL != systray ) systray->SetActivityWrite_Toggle(true); */ VCacheLogQuotedEntry logEntry(eCLEntryKind_Flush, false, true); #if trackClose trackDebugMsg("debut flush MainLoop\n"); #endif while (nbpass<2) { uLONG WaitOthers = 1; //fFlushedBytes = 0; AuMoinsUnFlushTreeNonVide = true; FlushProgressInfo fpi; fpi.curObjectNum = 0; fpi.totbytes = 0; fpi.starttime = VSystem::GetCurrentTime(); fpi.lasttime = fpi.starttime; fpi.currentBD = nil; #if debuglr == 101 if (fFlushProgress != nil && !fFlushProgress->IsManagerValid()) { sLONG xdebug = 1; // put a break here } if (fFlushProgress != nil) fFlushProgress->Release(); #endif fFlushProgress = VDBMgr::GetManager()->RetainDefaultProgressIndicator_For_DataCacheFlushing(); if (fFlushProgress != nil) { XBOX::VString session_title; gs(1005,22,session_title); // Flushing Data fpi.message = session_title; fFlushProgress->BeginSession(sGlobalNbFlushObjects,session_title,false); } Boolean RAZTimers = true; SetCurTaskFlushing(true); while( AuMoinsUnFlushTreeNonVide) { Boolean AllisSomethingFlushed = false; Boolean toutvide = true, waitForRequestForInvalid = false; SetDirty( false); //xSetFlushCancelled( false); BaseFlushInfo *curinfo; { VTaskLock Lock(&ListFlushInfoMutext); curinfo = ListFlushInfo; } while (curinfo != nil) { Boolean isSomethingFlushed = false; BtreeFlush *newbtflush; Boolean mustincreasetimer = false; sLONG NbModifStamp = 0; DataAddrSetVector AllSegsFullyDeletedObjects; { VTaskLock Lock(&(curinfo->TreeMutex)); if (RAZTimers) { curinfo->fWaitToInsertNewObject = 0; curinfo->fWaitToInsertNewObjectTimer.Unlock(); } newbtflush = curinfo->fCurTree; curinfo->fFlushingTree = newbtflush; curinfo->fCurTree = nil; if (newbtflush != nil) { fpi.currentBD = curinfo->GetOwner(); curinfo->GetOwner()->SwapAllSegsFullyDeletedObjects(AllSegsFullyDeletedObjects); if (fNeedValidate.find(curinfo) == fNeedValidate.end()) { curinfo->GetOwner()->InvalidateHeader(); fNeedValidate.insert(curinfo); } } else { if (curinfo->fRequestForInvalid > 0) { waitForRequestForInvalid = true; if (fNeedValidate.find(curinfo) == fNeedValidate.end()) { curinfo->GetOwner()->InvalidateHeader(); fNeedValidate.insert(curinfo); } } } NbModifStamp = curinfo->fNbModifStamp; } if (newbtflush != nil) { VSize curtot = 0; if (newbtflush->ViderFlush( &curtot, &isSomethingFlushed, &events, &FlushEventMutex, fFlushProgress, fpi, AllSegsFullyDeletedObjects)) { // comme tout l'arbre a ete flushe, on peut le supprimer xDisposeFlushingTree( curinfo, false); newbtflush=nil; } else toutvide = false; for (DataAddrSetVector::iterator cur = AllSegsFullyDeletedObjects.begin(), end = AllSegsFullyDeletedObjects.end(); cur != end; cur++) { DataAddrSetForFlush* px = &(*cur); if (!px->fAddrs.empty()) { sLONG nullzero = 0; while (px->fCurrent != px->fLast ) { fpi.currentBD->writelong(&nullzero, 4, *(px->fCurrent), 0); px->fCurrent++; } } } if (NbModifStamp != curinfo->fNbModifStamp) mustincreasetimer = true; if (newbtflush!=nil) { // comme certains objets n'ont pu etre flushe, on recopie le residu d'arbre pour un prochain essai xDisposeFlushingTree( curinfo, true); newbtflush=nil; toutvide = false; } AllisSomethingFlushed = AllisSomethingFlushed || isSomethingFlushed; { VTaskLock Lock(&(curinfo->TreeMutex)); if (curinfo->fCurTree == nil) { if (curinfo->fRequestForInvalid > 0) { waitForRequestForInvalid = true; } else { fNeedValidate.erase(curinfo); curinfo->GetOwner()->ValidateHeader(); } curinfo->fWaitToInsertNewObject = 0; curinfo->fWaitToInsertNewObjectTimer.Unlock(); } else { if (mustincreasetimer) { if (curinfo->fWaitToInsertNewObject == 0) { curinfo->fWaitToInsertNewObject = 1; curinfo->fLastTimeIncrease = VSystem::GetCurrentTime(); curinfo->fWaitToInsertNewObjectTimer.ResetAndLock(); } else { uLONG curtime = VSystem::GetCurrentTime(); if ((uLONG)abs((sLONG)(curtime - curinfo->fLastTimeIncrease)) > curinfo->fWaitToInsertNewObject) { if (curinfo->fWaitToInsertNewObject < 8192) curinfo->fWaitToInsertNewObject = curinfo->fWaitToInsertNewObject * 2; curinfo->fLastTimeIncrease = curtime; } } } else // decrease { if (curinfo->fWaitToInsertNewObject != 0) { if (curinfo->fWaitToInsertNewObject == 1) { curinfo->fWaitToInsertNewObject = 0; curinfo->fWaitToInsertNewObjectTimer.Unlock(); } else { uLONG curtime = VSystem::GetCurrentTime(); if ((uLONG)abs((sLONG)(curtime - curinfo->fLastTimeIncrease)) > curinfo->fWaitToInsertNewObject) { curinfo->fWaitToInsertNewObject = curinfo->fWaitToInsertNewObject / 2; curinfo->fLastTimeIncrease = curtime; } } } } toutvide = false; } } } { VTaskLock Lock(&(curinfo->TreeMutex)); curinfo = curinfo->right; } } // on libere toute les demandes de flush pour memoire qui ont, au moins, fait un cycle complet { VTaskLock lock2(&FlushEventMutex); for (FlushEventList::iterator cur = events.begin(), end = events.end(); cur != end; ) { Boolean next = true; if (cur->needmem) { if (cur->FlushCycle!= fCurrentFlushCycle) { cur->flag->Unlock(); cur->flag->Release(); FlushEventList::iterator theone = cur; cur++; next = false; events.erase(theone); } } if (next) cur++; } fCurrentFlushCycle++; } // maintenant on supprime les BaseFlushInfo des bases qu'on a ferme { VTaskLock Lock(&ListFlushInfoMutext); curinfo = ListFlushInfo; while (curinfo != nil) { Boolean doisdelete = false; BaseFlushInfo* suivant; { VTaskLock Lock2(&(curinfo->TreeMutex)); suivant = curinfo->right; doisdelete = (curinfo->doisdelete); if (doisdelete) DeleteBaseFlushInfo(curinfo); } curinfo = suivant; } } { VTaskLock lock2(&FlushEventMutex); for (FlushEventList::iterator cur = events.begin(), end = events.end(); cur != end; ) { Boolean next = true; if (cur->waitForAllWritten) { cur->flag->Unlock(); cur->flag->Release(); FlushEventList::iterator theone = cur; cur++; next = false; events.erase(theone); } if (next) cur++; } } if (toutvide) { if (waitForRequestForInvalid) AuMoinsUnFlushTreeNonVide = true; else AuMoinsUnFlushTreeNonVide = false; // on peut quitter la boucle car tous les arbres ont ete flushes } else { if (WaitOthers < 2) WaitOthers = WaitOthers * 2; VTask::GetCurrent()->Sleep(WaitOthers); //vYieldNow(); //on donne une chance aux autres process de liberer les objets lockes } VDBMgr::GetCacheManager()->ClearWaitListForBigObject(); RAZTimers = false; VDBMgr::GetManager()->PurgeExpiredDataSets(); VDBMgr::GetManager()->DeleteDeadBlobPaths(); } if (fFlushProgress != nil) { fFlushProgress->EndSession(); #if debuglr == 101 // when debugging, keep the progress indicator #else fFlushProgress->Release(); fFlushProgress = nil; #endif } SetCurTaskFlushing(false); //SetDirty( false); ++nbpass; } #if trackClose trackDebugMsg("fin flush MainLoop\n"); #endif xFlushEnd(); #if trackClose trackDebugMsg("apres xFlushEnd\n"); #endif if (VDBMgr::GetActivityManager() != nil) VDBMgr::GetActivityManager()->SetActivityWrite(false, 0); /* if ( NULL != systray ) systray->SetActivityWrite_Toggle(false); */ VDBMgr::GetManager()->FlushAllData(); context.StopLowLevelMode(); }