projects
/
project
/
libubox.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ustream: add ustream_pending_data accessor function
[project/libubox.git]
/
uloop.c
diff --git
a/uloop.c
b/uloop.c
index
acf46db
..
88e9c81
100644
(file)
--- a/
uloop.c
+++ b/
uloop.c
@@
-32,6
+32,7
@@
#include <stdbool.h>
#include "uloop.h"
#include <stdbool.h>
#include "uloop.h"
+#include "utils.h"
#ifdef USE_KQUEUE
#include <sys/event.h>
#ifdef USE_KQUEUE
#include <sys/event.h>
@@
-41,10
+42,6
@@
#endif
#include <sys/wait.h>
#endif
#include <sys/wait.h>
-
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-#endif
#define ULOOP_MAX_EVENTS 10
static struct list_head timeouts = LIST_HEAD_INIT(timeouts);
#define ULOOP_MAX_EVENTS 10
static struct list_head timeouts = LIST_HEAD_INIT(timeouts);
@@
-304,10
+301,9
@@
out:
static int tv_diff(struct timeval *t1, struct timeval *t2)
{
static int tv_diff(struct timeval *t1, struct timeval *t2)
{
- if (t1->tv_sec != t2->tv_sec)
- return (t1->tv_sec - t2->tv_sec) * 1000;
- else
- return (t1->tv_usec - t2->tv_usec) / 1000;
+ return
+ (t1->tv_sec - t2->tv_sec) * 1000 +
+ (t1->tv_usec - t2->tv_usec) / 1000;
}
int uloop_timeout_add(struct uloop_timeout *timeout)
}
int uloop_timeout_add(struct uloop_timeout *timeout)
@@
-341,11
+337,11
@@
int uloop_timeout_set(struct uloop_timeout *timeout, int msecs)
gettimeofday(&timeout->time, NULL);
time->tv_sec += msecs / 1000;
gettimeofday(&timeout->time, NULL);
time->tv_sec += msecs / 1000;
- time->tv_usec +=
msecs %
1000;
+ time->tv_usec +=
(msecs % 1000) *
1000;
if (time->tv_usec > 1000000) {
time->tv_sec++;
if (time->tv_usec > 1000000) {
time->tv_sec++;
- time->tv_usec %= 100000;
+ time->tv_usec %= 100000
0
;
}
return uloop_timeout_add(timeout);
}
return uloop_timeout_add(timeout);
@@
-464,9
+460,11
@@
static int uloop_get_next_timeout(struct timeval *tv)
static void uloop_process_timeouts(struct timeval *tv)
{
static void uloop_process_timeouts(struct timeval *tv)
{
- struct uloop_timeout *t, *tmp;
+ struct uloop_timeout *t;
+
+ while (!list_empty(&timeouts)) {
+ t = list_first_entry(&timeouts, struct uloop_timeout, list);
- list_for_each_entry_safe(t, tmp, &timeouts, list) {
if (tv_diff(&t->time, tv) > 0)
break;
if (tv_diff(&t->time, tv) > 0)
break;