const CEpgInfoTag *CEpg::InfoTag(int uniqueID, const CDateTime &StartTime) const { CEpgInfoTag *returnTag = NULL; CSingleLock locka(m_critSection); /* try to find the tag by UID */ if (uniqueID > 0) { for (unsigned int iEpgPtr = 0; iEpgPtr < size(); iEpgPtr++) { CEpgInfoTag *tag = at(iEpgPtr); if (tag->UniqueBroadcastID() == uniqueID) { returnTag = tag; break; } } } /* if we haven't found it, search by start time */ if (!returnTag) { for (unsigned int iEpgPtr = 0; iEpgPtr < size(); iEpgPtr++) { CEpgInfoTag *tag = at(iEpgPtr); if (tag->Start() == StartTime) { returnTag = tag; break; } } } return returnTag; }
void Eat() { std::cout << name_ << ": Begin eating" << std::endl; int lockAIndex = holdForkIndex_; int lockBIndex = (holdForkIndex_ + 1) % MAX_FORKS; std::lock(fork[lockAIndex], fork[lockBIndex]); Think(); std::lock_guard<std::mutex> locka(fork[lockAIndex], std::adopt_lock); std::cout << name_ << ": Hold fork: " << lockAIndex << std::endl; Think(); std::lock_guard<std::mutex> lockb(fork[lockBIndex], std::adopt_lock); std::cout << name_ << ": Hold fork: " << lockBIndex << std::endl; // eating std::this_thread::sleep_for(std::chrono::microseconds(10)); std::cout << name_ << " End eating" << std::endl; }