41 return (tv.tv_sec * 1000.0 + tv.tv_usec / 1000.0);
45 : _enabled(true), _interval(interval), _repeat(repeat), _expiration(0), _data(0), _disp(ed)
48 gettimeofday(&now, NULL);
65 : _enabled(true), _fd(fd), _flags(flags), _state(0), _data(0), _disp(ed)
81 pthread_mutex_init(&
_mutex, NULL);
88 pthread_mutex_t recmutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
93 pthread_mutex_init(&
_mutex, NULL);
99 pthread_mutex_destroy(&
_mutex);
104 pthread_mutex_lock(&
_mutex);
109 pthread_mutex_unlock(&
_mutex);
122 DefaultWatches::iterator wi =
_watches.begin();
125 DefaultWatches::iterator wmp = wi;
136 DefaultTimeouts::iterator ti =
_timeouts.begin();
139 DefaultTimeouts::iterator tmp = ti;
162 DefaultWatches::iterator wi =
_watches.begin();
164 for (nfd = 0; wi !=
_watches.end(); ++wi)
166 if ((*wi)->enabled())
168 fds[nfd].fd = (*wi)->descriptor();
169 fds[nfd].events = (*wi)->flags();
170 fds[nfd].revents = 0;
179 fds[nfd].events = POLLIN | POLLOUT | POLLPRI ;
180 fds[nfd].revents = 0;
184 fds[nfd].events = POLLIN | POLLOUT | POLLPRI ;
185 fds[nfd].revents = 0;
190 int wait_min = 10000;
192 DefaultTimeouts::iterator ti;
198 if ((*ti)->enabled() && (*ti)->interval() < wait_min)
199 wait_min = (*ti)->interval();
204 poll(fds, nfd, wait_min);
207 gettimeofday(&now, NULL);
209 double now_millis =
millis(now);
217 DefaultTimeouts::iterator tmp = ti;
220 if ((*ti)->enabled() && now_millis >= (*ti)->_expiration)
222 (*ti)->expired(*(*ti));
226 (*ti)->_expiration = now_millis + (*ti)->_interval;
238 for (
int j = 0; j < nfd; ++j)
240 DefaultWatches::iterator wi;
244 DefaultWatches::iterator tmp = wi;
247 if ((*wi)->enabled() && (*wi)->_fd == fds[j].fd)
251 (*wi)->_state = fds[j].revents;
253 (*wi)->ready(*(*wi));
DefaultTimeouts _timeouts
virtual ~DefaultMainLoop()
virtual ~DefaultTimeout()
DefaultWatch(int fd, int flags, DefaultMainLoop *)
static double millis(timeval tv)