Skip to content

Commit

Permalink
qemu: add a cleanup callback function to EventNotifier
Browse files Browse the repository at this point in the history
Adding a cleanup callback function to the EventNotifier struct
which allows users to execute event_notifier_cleanup in a
different context.

Signed-off-by: Gal Hammer <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
  • Loading branch information
Gal Hammer authored and mstsirkin committed Jan 18, 2018
1 parent 406d2aa commit f87d72f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/qemu/event_notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct EventNotifier {
int rfd;
int wfd;
#endif
void (*cleanup)(EventNotifier *);
};

typedef void EventNotifierHandler(EventNotifier *);
Expand Down
5 changes: 4 additions & 1 deletion util/event_notifier-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void event_notifier_init_fd(EventNotifier *e, int fd)
{
e->rfd = fd;
e->wfd = fd;
e->cleanup = NULL;
}
#endif

Expand Down Expand Up @@ -65,6 +66,7 @@ int event_notifier_init(EventNotifier *e, int active)
e->rfd = fds[0];
e->wfd = fds[1];
}
e->cleanup = NULL;
if (active) {
event_notifier_set(e);
}
Expand All @@ -80,10 +82,11 @@ void event_notifier_cleanup(EventNotifier *e)
{
if (e->rfd != e->wfd) {
close(e->rfd);
e->rfd = -1;
}
close(e->wfd);
e->rfd = -1;
e->wfd = -1;
e->cleanup = NULL;
}

int event_notifier_get_fd(const EventNotifier *e)
Expand Down
2 changes: 2 additions & 0 deletions util/event_notifier-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ int event_notifier_init(EventNotifier *e, int active)
{
e->event = CreateEvent(NULL, TRUE, FALSE, NULL);
assert(e->event);
e->cleanup = NULL;
return 0;
}

void event_notifier_cleanup(EventNotifier *e)
{
CloseHandle(e->event);
e->event = NULL;
e->cleanup = NULL;
}

HANDLE event_notifier_get_handle(EventNotifier *e)
Expand Down

0 comments on commit f87d72f

Please sign in to comment.