void *clientThread(void *data) { threadStart(); pthread_t pthread_self(); pid_t clientPid = *(pid_t *)data, secondClientPid = 0; int k = 0, n = 0, m = 0; long msgType = clientPid, secondMsgType = 0; getRequest(msgType, &k, &n); if (getPartner(clientPid, &secondClientPid, k, n, &m) == 1) sendErrorInfo(msgType); if (secondClientPid != clientPid) { secondMsgType = secondClientPid; if (getResources(clientPid, secondClientPid, k, n, m) == 0) { sendResources(msgType, secondClientPid); sendResources(secondMsgType, clientPid); getResourcesBack(msgType, secondMsgType, k, n + m); } else { sendErrorInfo(msgType); sendErrorInfo(secondMsgType); } } free(data); threadEnd(); return 0; }
bool isValid(string s) { int len=s.size(); if(len%2) return false; stack<char> sta; sta.push(s[0]); for(int i=1;i<len;i++){ if(sta.size()&&getPartner(sta.top())==s[i]) sta.pop(); else sta.push(s[i]); } if(sta.size()) return false; else return true; }
bool MatchMaker::getCurrentPartner(struct MatchMaker::Partner *partner) { uint32_t currentIndex; rraOk = true; if ((rraOk = get_current_partner(¤tIndex))) { rraOk = getPartner(currentIndex, partner); } if (!rraOk) { partner->id = 0; partner->name = ""; partner->index = 0; rraOk = false; } return rraOk; }