From: Erik Schilling <erik.schilling@linaro.org>
To: Linux-GPIO <linux-gpio@vger.kernel.org>
Cc: Bartosz Golaszewski <brgl@bgdev.pl>,
Viresh Kumar <viresh.kumar@linaro.org>,
Erik Schilling <erik.schilling@linaro.org>
Subject: [libgpiod][PATCH 2/3] doc: document thread safety guarantees
Date: Thu, 28 Sep 2023 16:37:29 +0200 [thread overview]
Message-ID: <20230928-rust-send-trait-v1-2-30b4f59d13cb@linaro.org> (raw)
In-Reply-To: <20230928-rust-send-trait-v1-0-30b4f59d13cb@linaro.org>
This mostly adds the information from the linked thread to the doxygen
documentation.
Summarized:
- libgpiod object's require synchronization
- individual objects may be used concurrently by different threds
Link: https://lore.kernel.org/r/CVHO091CC80Y.3KUOSLSOBVL0T@ablu-work
Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
---
include/gpiod.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/include/gpiod.h b/include/gpiod.h
index be51c3a..d86c6ac 100644
--- a/include/gpiod.h
+++ b/include/gpiod.h
@@ -42,6 +42,14 @@ extern "C" {
* methods that take a pointer as any of the subsequent arguments, the handling
* of a NULL-pointer depends on the implementation and may range from gracefully
* handling it, ignoring it or returning an error.
+ *
+ * libgpiod is thread-aware but does not provide any further thread-safety
+ * guarantees. This requires the user to ensure that at most one thread may
+ * work with an object at any time. Sharing objects across threads is allowed
+ * if a suitable synchronization mechanism serializes the access. Different,
+ * standalone objects can safely be used concurrently. Most libgpiod objects
+ * are standalone. Exceptions - such as events allocated in buffers - exist and
+ * are noted in the documentation.
*/
/**
@@ -624,6 +632,12 @@ uint64_t gpiod_info_event_get_timestamp_ns(struct gpiod_info_event *event);
* @return Returns a pointer to the line-info object associated with the event.
* The object lifetime is tied to the event object, so the pointer must
* be not be freed by the caller.
+ * @warning Thread-safety:
+ * Since the line-info object is tied to the event, different threads
+ * may not operate on the event and line-info at the same time. The
+ * line-info can be copied using ::gpiod_line_info_copy in order to
+ * create a standalone object - which then may safely be used from a
+ * different thread concurrently.
*/
struct gpiod_line_info *
gpiod_info_event_get_line_info(struct gpiod_info_event *event);
@@ -1297,6 +1311,12 @@ void gpiod_edge_event_buffer_free(struct gpiod_edge_event_buffer *buffer);
* @return Pointer to an event stored in the buffer. The lifetime of the
* event is tied to the buffer object. Users must not free the event
* returned by this function.
+ * @warning Thread-safety:
+ * Since events are tied to the buffer instance, different threads
+ * may not operate on the buffer and any associated events at the same
+ * time. Events can be copied using ::gpiod_edge_event_copy in order
+ * to create a standalone objects - which each may safely be used from
+ * a different thread concurrently.
*/
struct gpiod_edge_event *
gpiod_edge_event_buffer_get_event(struct gpiod_edge_event_buffer *buffer,
--
2.41.0
next prev parent reply other threads:[~2023-09-28 14:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-28 14:37 [libgpiod][PATCH 0/3] thread-safety doc + Rust modeling Erik Schilling
2023-09-28 14:37 ` [libgpiod][PATCH 1/3] doc: drop unneeded <p> tags Erik Schilling
2023-09-28 14:37 ` Erik Schilling [this message]
2023-09-28 14:37 ` [libgpiod][PATCH 3/3] bindings: rust: mark all owning types as `Send` Erik Schilling
2023-09-29 10:58 ` Viresh Kumar
2023-09-29 12:45 ` Bartosz Golaszewski
2023-09-29 12:47 ` Erik Schilling
2023-09-29 13:07 ` Bartosz Golaszewski
2023-10-02 7:16 ` [libgpiod][PATCH 0/3] thread-safety doc + Rust modeling Bartosz Golaszewski
2023-10-02 7:22 ` Erik Schilling
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=20230928-rust-send-trait-v1-2-30b4f59d13cb@linaro.org \
--to=erik.schilling@linaro.org \
--cc=brgl@bgdev.pl \
--cc=linux-gpio@vger.kernel.org \
--cc=viresh.kumar@linaro.org \
/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;
as well as URLs for NNTP newsgroup(s).