mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-20 19:52:16 +00:00
Refactor: move private watcher members to a union
This will save a few bytes of stack/heap for users. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
1f6fa93314
commit
e5bc49a8e6
4 files changed
+21
-14
No files matched your search
@@ -61,12 +61,19 @@ struct uev;
|
|||||||
void (*cb)(struct uev *, void *, int); \
|
void (*cb)(struct uev *, void *, int); \
|
||||||
void *arg; \
|
void *arg; \
|
||||||
\
|
\
|
||||||
/* Timer watchers, time in milliseconds */ \
|
/* Arguments for different watchers */ \
|
||||||
int timeout; \
|
union { \
|
||||||
int period; \
|
/* Timer watchers, time in milliseconds */ \
|
||||||
|
struct { \
|
||||||
|
int timeout; \
|
||||||
|
int period; \
|
||||||
|
} t; \
|
||||||
\
|
\
|
||||||
/* Signal watchers */ \
|
/* Signal watchers */ \
|
||||||
int signo; \
|
struct { \
|
||||||
|
int signo; \
|
||||||
|
} s; \
|
||||||
|
} u; \
|
||||||
\
|
\
|
||||||
/* Watcher type */ \
|
/* Watcher type */ \
|
||||||
uev_type_t
|
uev_type_t
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ int uev_signal_set(uev_t *w, int signo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Remember for callbacks and start/stop */
|
/* Remember for callbacks and start/stop */
|
||||||
w->signo = signo;
|
w->u.s.signo = signo;
|
||||||
|
|
||||||
/* Handle stopped signal watchers */
|
/* Handle stopped signal watchers */
|
||||||
if (w->fd < 0) {
|
if (w->fd < 0) {
|
||||||
@@ -129,7 +129,7 @@ int uev_signal_start(uev_t *w)
|
|||||||
if (-1 != w->fd)
|
if (-1 != w->fd)
|
||||||
uev_signal_stop(w);
|
uev_signal_stop(w);
|
||||||
|
|
||||||
return uev_signal_set(w, w->signo);
|
return uev_signal_set(w, w->u.s.signo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -123,8 +123,8 @@ int uev_timer_set(uev_t *w, int timeout, int period)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
w->timeout = timeout;
|
w->u.t.timeout = timeout;
|
||||||
w->period = period;
|
w->u.t.period = period;
|
||||||
|
|
||||||
if (w->ctx->running) {
|
if (w->ctx->running) {
|
||||||
struct itimerspec time;
|
struct itimerspec time;
|
||||||
@@ -153,7 +153,7 @@ int uev_timer_start(uev_t *w)
|
|||||||
if (-1 != w->fd)
|
if (-1 != w->fd)
|
||||||
uev_watcher_stop(w);
|
uev_watcher_stop(w);
|
||||||
|
|
||||||
return uev_timer_set(w, w->timeout, w->period);
|
return uev_timer_set(w, w->u.t.timeout, w->u.t.period);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ int uev_run(uev_ctx_t *ctx, int flags)
|
|||||||
/* Start all dormant timers */
|
/* Start all dormant timers */
|
||||||
LIST_FOREACH(w, &ctx->watchers, link) {
|
LIST_FOREACH(w, &ctx->watchers, link) {
|
||||||
if (UEV_TIMER_TYPE == w->type)
|
if (UEV_TIMER_TYPE == w->type)
|
||||||
uev_timer_set(w, w->timeout, w->period);
|
uev_timer_set(w, w->u.t.timeout, w->u.t.period);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ctx->running) {
|
while (ctx->running) {
|
||||||
@@ -282,8 +282,8 @@ int uev_run(uev_ctx_t *ctx, int flags)
|
|||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!w->period)
|
if (!w->u.t.period)
|
||||||
w->timeout = 0;
|
w->u.t.timeout = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UEV_SIGNAL_TYPE == w->type) {
|
if (UEV_SIGNAL_TYPE == w->type) {
|
||||||
@@ -300,7 +300,7 @@ int uev_run(uev_ctx_t *ctx, int flags)
|
|||||||
w->cb(w, w->arg, events[i].events & UEV_EVENT_MASK);
|
w->cb(w, w->arg, events[i].events & UEV_EVENT_MASK);
|
||||||
|
|
||||||
if (UEV_TIMER_TYPE == w->type) {
|
if (UEV_TIMER_TYPE == w->type) {
|
||||||
if (!w->timeout)
|
if (!w->u.t.timeout)
|
||||||
uev_timer_stop(w);
|
uev_timer_stop(w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user