Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: "Erik Schilling" <erik.schilling@linaro.org>
To: "Adrien Zinger" <zinger.ad@gmail.com>, <linux-gpio@vger.kernel.org>
Subject: Re: [libgpiod][PATCH] libgpiod: Allow to gracefully exit from a wait event
Date: Mon, 13 Nov 2023 18:39:00 +0100	[thread overview]
Message-ID: <CWXV8TMDNK59.WFY7K99MD7KQ@ablu-work> (raw)
In-Reply-To: <20231113143219.43498-1-zinger.ad@gmail.com>

On Mon Nov 13, 2023 at 3:32 PM CET, Adrien Zinger wrote:
> Add a function in core `gpiod_line_request_wait_edge_events_or` with an
> additional argument `fd` to trigger ppoll manually from another thread.
>
> It allows users to gracefully cancel and join a worker thread waiting
> for an edge event.
>
> Signed-off-by: Adrien Zinger <zinger.ad@gmail.com>
> ---
>  include/gpiod.h          | 17 ++++++++++++++
>  lib/internal.c           | 38 ++++++++++++++++++++++++------
>  lib/internal.h           |  1 +
>  lib/line-request.c       |  9 +++++++
>  tests/tests-edge-event.c | 51 ++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 109 insertions(+), 7 deletions(-)
>
> diff --git a/include/gpiod.h b/include/gpiod.h
> index d86c6ac..cbc83f9 100644
> --- a/include/gpiod.h
> +++ b/include/gpiod.h
> @@ -1176,6 +1176,23 @@ int gpiod_line_request_get_fd(struct gpiod_line_request *request);
>  int gpiod_line_request_wait_edge_events(struct gpiod_line_request *request,
>  					int64_t timeout_ns);
>  
> +/**
> + * @brief Wait for edge events on any of the requested lines or a
> + *        POLLHUP/POLLERR event on the given file descriptor.
> + * @param request GPIO line request.
> + * @param fd file descriptor from any I/O, channel, fifo, or pipe.
> + * @param timeout_ns Wait time limit in nanoseconds. If set to 0, the function
> + *                   returns immediately. If set to a negative number, the
> + *                   function blocks indefinitely until an event becomes
> + *                   available.
> + * @return 0 if wait timed out, -1 if an error occurred, 1 if an event is
> + *         pending, 2 if the file descriptor raised an event.
> + *
> + * Lines must have edge detection set for edge events to be emitted.
> + * By default edge detection is disabled.
> + */
> +int gpiod_line_request_wait_edge_events_or(struct gpiod_line_request *request,
> +					int fd, int64_t timeout_ns);

This sounds like an oddly specific API... I wonder, why does
gpiod_line_request_get_fd [1] + doing the polling in your code not work
for you? Since you already got a file descriptor for the notification
that seems like little extra work. Or did you consider that but find it
too verbose?

[1] https://libgpiod.readthedocs.io/en/latest/group__line__request.html#ga5c0dbdcd8608b76e77b78bca9a6b03d7

- Erik

  reply	other threads:[~2023-11-13 17:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-13 14:32 [libgpiod][PATCH] libgpiod: Allow to gracefully exit from a wait event Adrien Zinger
2023-11-13 17:39 ` Erik Schilling [this message]
2023-11-14 10:09   ` Adrien Zinger
2023-11-15 17:10     ` Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CWXV8TMDNK59.WFY7K99MD7KQ@ablu-work \
    --to=erik.schilling@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=zinger.ad@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox