diff options
| author | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-04-05 23:37:39 -0300 |
|---|---|---|
| committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-04-07 00:22:01 -0300 |
| commit | 967fb1aca6ea9c3d3046ccd6b9fcf0f88d6999ac (patch) | |
| tree | 886a553c1f5ea139fec7600803562aa11edcfe2a /src/os/signal.c | |
| parent | fac85c17248ab8c371fb311c1dd4bc1b2a7520cf (diff) | |
| download | rneovim-967fb1aca6ea9c3d3046ccd6b9fcf0f88d6999ac.tar.gz rneovim-967fb1aca6ea9c3d3046ccd6b9fcf0f88d6999ac.tar.bz2 rneovim-967fb1aca6ea9c3d3046ccd6b9fcf0f88d6999ac.zip | |
Reimplement the event queue in event.c using klist.h
- Add a new macro to klist.h: kl_empty()
The whole point of abstract data structures is to avoid reimplementing
common actions. The emptiness test seems to be such an action.
- Add a new function attribute to func_attr.h: FUNC_ATTR_UNUSED
Some of the many functions created by the macros in klist.h may end up not
being used. Unused functions cause compilation errors as we compile with
-Werror. To mark those functions as possibly unused we can use the
FUNC_ATTR_UNUSED now.
- Pass `Event` by value
`Event` is such a small struct that I don't think we should allocate heap space
and pass it by reference. Let's use the stack and memory cache in our favor
passing it by value.
Diffstat (limited to 'src/os/signal.c')
| -rw-r--r-- | src/os/signal.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/os/signal.c b/src/os/signal.c index 2ac31060aa..503269208d 100644 --- a/src/os/signal.c +++ b/src/os/signal.c @@ -67,12 +67,11 @@ void signal_accept_deadly() rejecting_deadly = false; } -void signal_handle(Event *event) +void signal_handle(Event event) { - int signum = *(int *)event->data; + int signum = *(int *)event.data; - free(event->data); - free(event); + free(event.data); switch (signum) { case SIGINT: @@ -148,8 +147,6 @@ static void deadly_signal(int signum) static void signal_cb(uv_signal_t *handle, int signum) { - Event *event; - if (rejecting_deadly) { if (signum == SIGINT) { got_int = true; @@ -158,9 +155,10 @@ static void signal_cb(uv_signal_t *handle, int signum) return; } - event = (Event *)xmalloc(sizeof(Event)); - event->type = kEventSignal; - event->data = xmalloc(sizeof(int)); - *(int *)event->data = signum; + Event event = { + .type = kEventSignal, + .data = xmalloc(sizeof(int)) + }; + *(int *)event.data = signum; event_push(event); } |
