Esempio n. 1
0
bool
CQ::ReapInquiryWaitAny(uint16_t ms, uint16_t &numCE, uint32_t &isrCount)
{
    struct timeval initial;

    if (gettimeofday(&initial, &TZ_NULL) != 0) {
        LOG_DBG("Cannot retrieve system time");
        throw exception();
    }

    while (CalcTimeout(ms, initial) == false) {
        if ((numCE = ReapInquiry(isrCount)) != 0) {
            return true;
        }
    }

    LOG_ERR("Timed out waiting %d ms for CE's in CQ %d", ms, GetQId());
    return false;
}
Esempio n. 2
0
void Selector::Run()
{
	while(m_loop)
	{
		struct timespec timeout;
		fd_set freads = m_freads;
		fd_set fwrites = m_fwrites;
		fd_set fexcept = m_fexcept;
		CalcTimeout(&timeout);
		int ret = pselect(m_maxfd + 1, &freads, &fwrites, &fexcept, &timeout, NULL);
		if (ret < 0)
		{
			switch(errno)
			{
				case EINTR:
					continue;
					break;
				case EBADF: /* It is possible to have a bad fd inside the set because it just changed after read took a copy of the set */
					m_err_ebadf++;
					continue;
					break;
				default:
					abort();
					break;
			}
		}

		do {
			ScopedLock lock = ScopedLock(&m_mutex);
			m_modified = false;
			//Check fd_set's
			for(std::map<int, ISelectable *>::iterator it = m_map.begin(); it != m_map.end(); it++)
			{
				int fd = it->first;
				bool work = false;
				if (FD_ISSET(fd, &freads))
				{
					it->second->DoRead(this);
					if (m_modified)
						goto skip_to_end;
					work = true;
				}
				if (FD_ISSET(fd, &fwrites))
				{
					it->second->DoWrite(this);
					if (m_modified)
						goto skip_to_end;
					work = true;
				}
				if (FD_ISSET(fd, &fexcept))
				{
					it->second->DoExcept(this);
					if (m_modified)
						goto skip_to_end;
					work = true;
				}

				if (work)
					UpdateMap(fd);
			}
					
			struct timespec now;
			if (clock_gettime(CLOCK_MONOTONIC, &now) < 0)
				abort();

			for(std::map<int, struct timespec>::iterator it = m_timeout.begin(); it != m_timeout.end(); it++)
			{
				if (Time::IsLess(&it->second, &now))
				{
					m_map[it->first]->DoTimeout(this);
					if (m_modified)
						goto skip_to_end;
					UpdateMap(it->first);
				}
			}

		} while(0);
skip_to_end:
		ReadControl();
	}
}