//----------------------------------------------------------------------- void DrmaManager::commitPendingGetRequests(){ pthread_mutex_lock(&pendingGetRequestsLock); vector<BspGetRequest>::iterator it = pendingGetRequests.begin(); vector<BspGetRequest> temp; for ( ;it != pendingGetRequests.end(); it++){ if ((*it).superstep() == baseProcess_->superstep()){ Registration & reg = registrations[(*it).logicSrc()]; unsigned char * srcPtr = (unsigned char *) reg.ptr(); BspGetReply reply; reply.nBytes((*it).nBytes()) .type(reg.type()) .arch(dstArch) .superstep((*it).superstep()) .dst((*it).dst()); reply.writeInMem(srcPtr + (*it).offset()); if((*it).pid() == baseProcess_->getMyPid()) addPendingGetReply(reply); else stubPool_->bspGetReply((*it).pid(), reply); } else{ temp.push_back(*it); } } pendingGetRequests.swap(temp); pthread_mutex_unlock(&pendingGetRequestsLock); }
//-------------------------------------------------------------------------------- void BspProxyStubPool::bspGetReply(const int & taskPid, const BspGetReply & reply){ int initialStackSize = lua_gettop(clientSideState); lua_getglobal(clientSideState, getTaskId(taskPid).c_str()); lua_pushstring(clientSideState, "bspGetReply"); lua_gettable(clientSideState, -2); lua_getglobal(clientSideState, getTaskId(taskPid).c_str()); lua_newtable(clientSideState); LuaUtils::setFieldOnTable(clientSideState, "dataType", reply.type(), -1); LuaUtils::setFieldOnTable(clientSideState, "arch", reply.arch(), -1); LuaUtils::setFieldOnTable(clientSideState, "nBytes", reply.nBytes(), -1); LuaUtils::setFieldOnTable(clientSideState, "superstep", reply.superstep(), -1); LuaUtils::setFieldOnTable(clientSideState, "dst", (unsigned long)reply.dst(), -1); lua_pushstring(clientSideState, "memArea");//FIXME: Add method to LuaUtils const char * memArea = (char *) reply.memArea(); lua_pushlstring(clientSideState, memArea, reply.nBytes()); lua_settable(clientSideState, -3); if (lua_pcall(clientSideState, 2, 0, 0) != 0){ cerr << "[ERROR] BspProxyStubPool::bspGetReply->Lua error: " << lua_tostring(clientSideState, -1) << endl; lua_pop(clientSideState, 1); } lua_pop(clientSideState, 1);//removes proxy from stack assert(initialStackSize == lua_gettop(clientSideState)); }
//----------------------------------------------------------------------- int BspProxyImpl::bspGetReplyWrapper(struct lua_State * state){ int n = lua_gettop(state); assert(n == 1); BspGetReply reply; reply.type(LuaUtils::getIntFromTable(state, "dataType")) .arch(LuaUtils::getIntFromTable(state, "arch")) .nBytes(LuaUtils::getIntFromTable(state, "nBytes")) .superstep(LuaUtils::getIntFromTable(state, "superstep")) .dst((void *)LuaUtils::getLongFromTable(state, "dst")); lua_pushstring(state, "memArea"); lua_gettable(state, -2); reply.writeInMem(lua_tostring(state,-1)); lua_pop(state, 1); BspProxyImpl::singleInstance->drmaManager_->addPendingGetReply(reply); return 0; }