int UpdateDictThread::update_() { std::vector<std::string> updated_files; int failedCount = 0; { boost::mutex::scoped_lock swl(lock_); updating_ = true; for (MapType::iterator itr = map_.begin(); itr != map_.end(); ++itr) { long curModifiedTime = getFileLastModifiedTime(itr->first); if (curModifiedTime == itr->second.lastModifiedTime_) continue; //update all dictionary if (itr->second.relatedDict_.get()->update(itr->first.c_str(), curModifiedTime)) ++failedCount; updated_files.push_back(itr->first); #ifdef DEBUG_UDT cout << "Update " << itr->first << " failed." << endl; #endif itr->second.lastModifiedTime_ = curModifiedTime; } } if (!updated_files.empty()) { for(std::map<std::string, UpdateCBType>::const_iterator it = callback_list_.begin(); it != callback_list_.end(); ++it) { try { it->second(updated_files); } catch(const std::exception& e) { std::cerr << "update callback exception in " << it->first << ", " << e.what() << std::endl; } } } boost::mutex::scoped_lock swl(lock_); updating_ = false; cond_.notify_all(); return failedCount; }
void UpdateDictThread::removeUpdateCallback(const std::string& unique_str) { boost::mutex::scoped_lock swl(lock_); while (updating_) { cond_.wait(lock_); } callback_list_.erase(unique_str); }
bool UpdateDictThread::start() { boost::mutex::scoped_lock swl(lock_); if (isStarted()) return false; thread_ = boost::thread(&UpdateDictThread::run_, this); return true; }
void UpdateDictThread::addUpdateCallback(const std::string& unique_str, UpdateCBType cb) { boost::mutex::scoped_lock swl(lock_); if (cb) { while(updating_) { cond_.wait(lock_); } callback_list_[unique_str] = cb; } }
boost::shared_ptr<UpdatableDict> UpdateDictThread::addRelatedDict(const std::string& path, const boost::shared_ptr< UpdatableDict >& dict) { boost::mutex::scoped_lock swl(lock_); MapType::iterator itr = map_.find(path); if (itr == map_.end()) { if (dict.get()) { DictSource& ds = map_[path]; ds.lastModifiedTime_ = getFileLastModifiedTime(path); ds.relatedDict_ = dict; } return dict; } else return itr->second.relatedDict_; }
bool ScreenPub::onHandlePost(const void* buf, size_t len, OutputStream& out) { u32 timeStamp = Timer::currentTimeMillis(); if(dumpOn && dumpFile.is_open() && buf && len > 0) { ScopedLock sl(dumpLock); //std::cout<<getId()<<" [DUMP] Post Call "<<len<<" bytes!"<<std::endl; //Dump::hexDump(os,buf,len); dumpFile.write((const char*)&len,4); dumpFile.write((const char*)&timeStamp,4); dumpFile.write((const char*)buf,(int)len); dumpFile.flush(); } //DDSS_AUDIT("CLIENT")<<"[PUB-RECV],"<<Timer::currentTimeMillis()<<","<<getId()<<","<<(len)<<std::endl; /*std::cout<<"Incoming "<<len<<" byte rect data"<<std::endl; Dump::hexDump(std::cout,buf,len); std::cout<<"---- end "<<len<<" byte rect data"<<std::endl; */ ScopedWriteLock swl(getScreen().getRWLock()); return getScreen().postData(buf,len, timeStamp); }
//主线程 void LogGate::v_timetick(QWORD usec) { DWORD cur = usec/1000/1000; _close_iter tmp_close; NetProcessor *clo = 0; { ScopeWriteLock swl(_close_critical); for (_close_iter it = _close_list.begin(); it != _close_list.end(); ) { tmp_close = it++; if (tmp_close->second + 3 <= cur) { clo = tmp_close->first; v_CloseNp(clo); XDBG("[%s],_close_list 删除连接,%s(%llu),%p", serverName, clo->name(), clo->id(), clo); _close_list.erase(tmp_close); SAFE_DELETE(clo); } } } }