当前位置: 首页>>代码示例>>C++>>正文


C++ TaskQueue::assign方法代码示例

本文整理汇总了C++中TaskQueue::assign方法的典型用法代码示例。如果您正苦于以下问题:C++ TaskQueue::assign方法的具体用法?C++ TaskQueue::assign怎么用?C++ TaskQueue::assign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TaskQueue的用法示例。


在下文中一共展示了TaskQueue::assign方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: migrateTasks

// pack the jobs into multiple packages - 2000 jobs per package
// and insert it into the ready queue of server that requested to steal tasks
//int Worker::migrateTasks(int num_tasks, ZHTClient &clientRet, int index){
void* migrateTasks(void *args) {

	Worker *worker = (Worker*) args;
	int index;
	while (ON) {
		//while(migrateq.size() > 0) {
		while (migratev.any()) {
			pthread_mutex_lock(&mq_lock);
			if (migratev.any()) {
				//int *index = (int*)args;                
				//index = migrateq.front();
				index = migratev.pop();
				//migrateq.pop();
				//cout << "1 worker = " << worker->selfIndex << " to index = " << index << " size = " << rqueue.size() << endl;
			} else {
				//cout << "migratev count = " << migratev.count() << endl;
				pthread_mutex_unlock(&mq_lock);
				continue;
			}
			if (index < 0 || index >= worker->num_nodes) {
				//cout << "bad index: worker = " << worker->selfIndex << " to index = " << index << endl;
				pthread_mutex_unlock(&mq_lock);
				continue;
			}
			pthread_mutex_unlock(&mq_lock);
			//cout << "2 worker = " << worker->selfIndex << " to index = " << index << " size = " << rqueue.size() << endl;
			pthread_mutex_lock(&m_lock);
			pthread_mutex_lock(&lock);
			int32_t num_tasks = rqueue.size() / 2;
			if (num_tasks < 1) {
				pthread_mutex_unlock(&lock);
				pthread_mutex_unlock(&m_lock);
				continue;;
			}
			try {	//cout << "going to send " << num_tasks << " tasks" << endl;
				mqueue.assign(rqueue.end() - num_tasks, rqueue.end());
				rqueue.erase(rqueue.end() - num_tasks, rqueue.end());
				//cout << "rqueue size = " << rqueue.size() << " mqueue size = " << mqueue.size() << endl;
			} catch (...) {
				cout
						<< "migrateTasks: cannot allocate memory while copying tasks to migrate queue"
						<< endl;
				pthread_exit(NULL);
			}
			pthread_mutex_unlock(&lock);

			map<uint32_t, NodeList> update_map = worker->get_map(mqueue);
			int update_ret = worker->zht_update(update_map, "nodehistory",
					index);
			/*if(index == worker->selfIndex) {
			 cout << "ALERT: MIGRATING TO ITSELF" << endl;
			 }*/
			int num_packages = 0;
			long total_submitted = 0;

			num_tasks = mqueue.size();
			while (total_submitted != num_tasks) {
				Package package;
				string alltasks;
				package.set_virtualpath(worker->ip);
				package.set_operation(22);
				num_packages++;
				int num_tasks_this_package = max_tasks_per_package;
				int num_tasks_left = num_tasks - total_submitted;
				if (num_tasks_left < max_tasks_per_package) {
					num_tasks_this_package = num_tasks_left;
				}
				for (int j = 0; j < num_tasks_this_package; j++) {
					//TaskQueue_item* qi = migrate_queue->remove_element();
					if (mqueue.size() < 1) {
						if (j > 0) {
							total_submitted = total_submitted + j;
							package.set_realfullpath(alltasks);
							string str = package.SerializeAsString();
							pthread_mutex_lock(&msg_lock);
							int32_t ret = worker->svrclient.svrtosvr(str,
									str.length(), index);
							pthread_mutex_unlock(&msg_lock);
						}
						//pthread_mutex_unlock (&m_lock);
						//return total_submitted;
						//pthread_exit(NULL);
						total_submitted = num_tasks;
						break;
					}
					try {
						alltasks.append(mqueue.front()->task_id);
						alltasks.append("\'\""); // Task ID
						/*stringstream num_moves_ss;
						 num_moves_ss << (mqueue.front()->num_moves + 1);
						 alltasks.append(num_moves_ss.str());  alltasks.append("\'\""); // Number of moves*/

						if (LOGGING) {
							migrate_fp << " taskid = "
									<< mqueue.front()->task_id;
							//migrate_fp << " num moves = " << (mqueue.front()->num_moves + 1);
						}
//.........这里部分代码省略.........
开发者ID:kwangiit,项目名称:matrix,代码行数:101,代码来源:matrix_server.cpp


注:本文中的TaskQueue::assign方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。