示例#1
0
	int Client::commit(const std::string & varname, int32_t iteration)
	{		
		Variable* v = metadataManager->getVariable(varname);
		if(v == NULL)
			return -1;

		ShmChunk* chunk = NULL;
		// get the pointer to the allocated chunk
		ChunkIndexByIteration::iterator end;
		ChunkIndexByIteration::iterator it = v->getChunksByIteration(iteration,end);

		if(it == end)
			return -2;
		try {
			chunk = dynamic_cast<ShmChunk*>(it->get());
		} catch(std::exception &e) {
			ERROR("When doing dynamic cast: " << e.what());
			return -3;
		}
		
		// we don't need to keep the chunk in the client now,
		// so we erase it from the variable.
		v->eraseChunk(it);

		// create notification message
		Message message;
		message.source = env->getID();

		message.iteration = iteration;
		message.type = MSG_VAR;
		message.handle = chunk->getHandle();
		message.object = v->getID();
                // send message
		msgQueue->send(&message,sizeof(Message),0);
                // free message
		DBG("Variable \"" << varname << "\" has been commited");

		return 0;
	}