1 // SPDX-License-Identifier: GPL-2.0 2 // 3 // waiter-poll.c - Waiter for event notification by poll(2). 4 // 5 // Copyright (c) 2018 Takashi Sakamoto <o-takashi@sakamocchi.jp> 6 // 7 // Licensed under the terms of the GNU General Public License, version 2. 8 9 #include "waiter.h" 10 #include "misc.h" 11 12 #include <stdlib.h> 13 #include <errno.h> 14 #include <poll.h> 15 poll_prepare(struct waiter_context * waiter)16static int poll_prepare(struct waiter_context *waiter) 17 { 18 // Nothing to do because an instance of waiter has required data. 19 return 0; 20 } 21 poll_wait_event(struct waiter_context * waiter,int timeout_msec)22static int poll_wait_event(struct waiter_context *waiter, int timeout_msec) 23 { 24 int err; 25 26 err = poll(waiter->pfds, waiter->pfd_count, timeout_msec); 27 if (err < 0) 28 return -errno; 29 30 return err; 31 } 32 poll_release(struct waiter_context * waiter)33static void poll_release(struct waiter_context *waiter) 34 { 35 // Nothing to do because an instance of waiter has required data. 36 return; 37 } 38 39 const struct waiter_data waiter_poll = { 40 .ops = { 41 .prepare = poll_prepare, 42 .wait_event = poll_wait_event, 43 .release = poll_release, 44 }, 45 }; 46