X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Fcompat%2Fpoll.h;h=8403880cf3742c61f4c01e281a69f2f5ff9084db;hb=6d737ce48af40e77ca27cb78348e7f3042eab3ed;hp=49673cd5af643e40a10aa9173d1ff4cf489d0802;hpb=beaad64cecee395058e37c8b33dc50af99d771a4;p=lttng-tools.git diff --git a/src/common/compat/poll.h b/src/common/compat/poll.h index 49673cd5a..8403880cf 100644 --- a/src/common/compat/poll.h +++ b/src/common/compat/poll.h @@ -43,9 +43,7 @@ extern unsigned int poll_max_size; */ static inline void __lttng_poll_free(void *events) { - if (events) { - free(events); - } + free(events); } /* @@ -160,6 +158,17 @@ static inline void lttng_poll_reset(struct lttng_poll_event *events) } } +/* + * Initialize an already allocated poll event data structure. For epoll(), the + * epfd is set to -1 to indicate that it's not usable. + */ +static inline void lttng_poll_init(struct lttng_poll_event *events) +{ + lttng_poll_reset(events); + /* Set fd to -1 so if clean before created, we don't close 0. */ + events->epfd = -1; +} + /* * Clean the events structure of a lttng_poll_event. It's the caller * responsability to free the lttng_poll_event memory. @@ -168,13 +177,18 @@ static inline void lttng_poll_clean(struct lttng_poll_event *events) { int ret; - if (events) { + if (!events) { + return; + } + + if (events->epfd >= 0) { ret = close(events->epfd); if (ret) { perror("close"); } - __lttng_poll_free((void *) events->events); } + + __lttng_poll_free((void *) events->events); } #else /* HAVE_EPOLL */ @@ -314,6 +328,14 @@ extern void compat_poll_set_max_size(void); static inline void lttng_poll_reset(struct lttng_poll_event *events) {} +/* + * Initialize an already allocated poll event data structure. + */ +static inline void lttng_poll_init(struct lttng_poll_event *events) +{ + memset(events, 0, sizeof(struct lttng_poll_event)); +} + /* * Clean the events structure of a lttng_poll_event. It's the caller * responsability to free the lttng_poll_event memory.