Skip to content

Commit

Permalink
Use pika::spinlock instead of pika::mutex in async_rw_mutex
Browse files Browse the repository at this point in the history
Allow access of async_rw_mutex from non-pika threads.
  • Loading branch information
msimberg committed May 9, 2023
1 parent b8d0ffc commit 0d4476a
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <pika/execution_base/sender.hpp>
#include <pika/execution_base/this_thread.hpp>
#include <pika/functional/unique_function.hpp>
#include <pika/synchronization/mutex.hpp>
#include <pika/synchronization/spinlock.hpp>

#include <atomic>
#include <exception>
Expand All @@ -36,11 +36,12 @@ namespace pika::execution::experimental {
template <typename T>
struct async_rw_mutex_shared_state
{
using mutex_type = pika::spinlock;
using shared_state_ptr_type = std::shared_ptr<async_rw_mutex_shared_state>;
std::atomic<bool> value_set{false};
std::optional<T> value{std::nullopt};
shared_state_ptr_type next_state{nullptr};
pika::mutex mtx{};
mutex_type mtx{};
pika::detail::small_vector<
pika::util::detail::unique_function<void(shared_state_ptr_type)>, 1>
continuations{};
Expand Down Expand Up @@ -101,17 +102,18 @@ namespace pika::execution::experimental {
template <typename F>
void add_continuation(F&& continuation)
{
std::lock_guard<pika::mutex> l(mtx);
std::lock_guard<mutex_type> l(mtx);
continuations.emplace_back(PIKA_FORWARD(F, continuation));
}
};

template <>
struct async_rw_mutex_shared_state<void>
{
using mutex_type = pika::spinlock;
using shared_state_ptr_type = std::shared_ptr<async_rw_mutex_shared_state>;
shared_state_ptr_type next_state{nullptr};
pika::mutex mtx{};
mutex_type mtx{};
pika::detail::small_vector<
pika::util::detail::unique_function<void(shared_state_ptr_type)>, 1>
continuations{};
Expand Down Expand Up @@ -144,7 +146,7 @@ namespace pika::execution::experimental {
template <typename F>
void add_continuation(F&& continuation)
{
std::lock_guard<pika::mutex> l(mtx);
std::lock_guard<mutex_type> l(mtx);
continuations.emplace_back(PIKA_FORWARD(F, continuation));
}
};
Expand Down

0 comments on commit 0d4476a

Please sign in to comment.