Exemple #1
0
void* check_wait_queue(void* args) {
	Worker *worker = (Worker*) args;
	TaskQueue_Item *qi;
	while (ON) {
		while (wqueue.size() > 0) {
			//for(TaskQueue::iterator it = wqueue.begin(); it != wqueue.end(); ++it) {
			int size = wqueue.size();
			for (int i = 0; i < size; i++) {
				//qi = *it;
				qi = wqueue[i];
				if (qi != NULL) {
					int status = worker->check_if_task_is_ready(qi->task_id); //cout << "task = " << qi->task_id << " status = " << status << endl;
					if (status == 0) {
						//cout << "task = " << qi->task_id << " status = " << status << endl;
						int ret = worker->move_task_to_ready_queue(&qi);
						pthread_mutex_lock(&w_lock);
						wqueue[i] = NULL;
						pthread_mutex_unlock(&w_lock);
					}
					/*if(status < 0) {
					 cout << "negative numwait" << endl;
					 }*/
				}
			}
			pthread_mutex_lock(&w_lock);
			TaskQueue::iterator last = remove_if(wqueue.begin(), wqueue.end(),
					check);
			wqueue.erase(last, wqueue.end());
			pthread_mutex_unlock(&w_lock);
			sleep(1);
		}
	}
}
Exemple #2
0
map<uint32_t, NodeList> Worker::get_map(TaskQueue &mqueue) {
	map<uint32_t, NodeList> update_map;
	/*Package package;
	 package.set_operation(operation);
	 if(operation == 25) {
	 package.set_currnode(toid);
	 }*/
	uint32_t num_nodes = svrclient.memberList.size();
	for (TaskQueue::iterator it = mqueue.begin(); it != mqueue.end(); ++it) {
		uint32_t serverid = myhash(((*it)->task_id).c_str(), num_nodes);
		string str((*it)->task_id);
		str.append("\'");
		if (update_map.find(serverid) == update_map.end()) {
			str.append("\"");
			NodeList new_list;
			new_list.push_back(str);
			update_map.insert(make_pair(serverid, new_list));
		} else {
			NodeList &exist_list = update_map[serverid];
			string last_str(exist_list.back());
			if ((last_str.size() + str.size()) > STRING_THRESHOLD) {
				str.append("\"");
				exist_list.push_back(str);
			} else {
				exist_list.pop_back();
				str.append(last_str);
				exist_list.push_back(str);
			}
		}
	}
	return update_map;
}
Exemple #3
0
void TaskScheduler::updateFramesClass(TaskQueue& queue, Class* klass)
{
	for(TaskQueue::iterator it = queue.begin(); it != queue.end(); it++)
	{
		Task* task = *it;
		task->getContext()->updateFramesClass(klass);
	}
}