Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: "Erik Schilling" <erik.schilling@linaro.org>
To: "Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Kent Gibson" <warthog618@gmail.com>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Viresh Kumar" <viresh.kumar@linaro.org>
Cc: <linux-gpio@vger.kernel.org>,
	"Bartosz Golaszewski" <bartosz.golaszewski@linaro.org>
Subject: Re: [libgpiod][PATCH 2/3] bindings: cxx: tests: don't use the same chip from different threads
Date: Tue, 19 Sep 2023 13:33:15 +0200	[thread overview]
Message-ID: <CVMV0TQQYGX1.1P90OHRZBIB73@ablu-work> (raw)
In-Reply-To: <20230919093142.85389-2-brgl@bgdev.pl>

On Tue Sep 19, 2023 at 11:31 AM CEST, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> There are no thread-safety guarantees in libgpiod. Let's not reuse the
> chip object created in one thread to generate info events in another but
> create a second chip for that purpose instead.
>
> Reported-by: Erik Schilling <erik.schilling@linaro.org>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Reviewed-by: Erik Schilling <erik.schilling@linaro.org>

> ---
>  bindings/cxx/tests/tests-info-event.cpp | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/bindings/cxx/tests/tests-info-event.cpp b/bindings/cxx/tests/tests-info-event.cpp
> index 249b1e8..21c0ef0 100644
> --- a/bindings/cxx/tests/tests-info-event.cpp
> +++ b/bindings/cxx/tests/tests-info-event.cpp
> @@ -3,6 +3,7 @@
>  
>  #include <catch2/catch.hpp>
>  #include <chrono>
> +#include <filesystem>
>  #include <gpiod.hpp>
>  #include <sstream>
>  #include <thread>
> @@ -17,11 +18,11 @@ using event_type = ::gpiod::info_event::event_type;
>  
>  namespace {
>  
> -void request_reconfigure_release_line(::gpiod::chip& chip)
> +void request_reconfigure_release_line(const ::std::filesystem::path& chip_path)
>  {
>  	::std::this_thread::sleep_for(::std::chrono::milliseconds(10));
>  
> -	auto request = chip
> +	auto request = ::gpiod::chip(chip_path)
>  		.prepare_request()
>  		.add_line_settings(7, ::gpiod::line_settings())
>  		.do_request();
> @@ -48,7 +49,9 @@ TEST_CASE("Lines can be watched", "[info-event][chip]")
>  		.set_num_lines(8)
>  		.build();
>  
> -	::gpiod::chip chip(sim.dev_path());
> +	const auto chip_path = sim.dev_path();
> +
> +	::gpiod::chip chip(chip_path);
>  
>  	SECTION("watch_line_info() returns line info")
>  	{
> @@ -74,7 +77,7 @@ TEST_CASE("Lines can be watched", "[info-event][chip]")
>  
>  		REQUIRE(info.direction() == direction::INPUT);
>  
> -		::std::thread thread(request_reconfigure_release_line, ::std::ref(chip));
> +		::std::thread thread(request_reconfigure_release_line, ::std::ref(chip_path));
>  
>  		REQUIRE(chip.wait_info_event(::std::chrono::seconds(1)));
>  		auto event = chip.read_info_event();


  reply	other threads:[~2023-09-19 11:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-19  9:31 [libgpiod][PATCH 1/3] tests: don't use the same chip object from different threads Bartosz Golaszewski
2023-09-19  9:31 ` [libgpiod][PATCH 2/3] bindings: cxx: tests: don't use the same chip " Bartosz Golaszewski
2023-09-19 11:33   ` Erik Schilling [this message]
2023-09-19  9:31 ` [libgpiod][PATCH 3/3] bindings: python: " Bartosz Golaszewski
2023-09-19 11:33   ` Erik Schilling
2023-09-19 11:33 ` [libgpiod][PATCH 1/3] tests: don't use the same chip object " 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=CVMV0TQQYGX1.1P90OHRZBIB73@ablu-work \
    --to=erik.schilling@linaro.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=viresh.kumar@linaro.org \
    --cc=warthog618@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