Skip to content

Commit

Permalink
mark lock types with [[nodiscard]]
Browse files Browse the repository at this point in the history
Reviewed By: dmm-fb

Differential Revision: D51439695

fbshipit-source-id: 3422d5c62dcc175a9a35faf33502c46ae54fb32a
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Nov 19, 2023
1 parent 26a2c02 commit b7af40f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 6 additions & 5 deletions folly/SharedMutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -1835,33 +1835,34 @@ class shared_lock<

shared_lock() noexcept = default;

explicit shared_lock(mutex_type& mutex) : mutex_(std::addressof(mutex)) {
FOLLY_NODISCARD explicit shared_lock(mutex_type& mutex)
: mutex_(std::addressof(mutex)) {
lock();
}

shared_lock(mutex_type& mutex, std::defer_lock_t) noexcept
: mutex_(std::addressof(mutex)) {}

shared_lock(mutex_type& mutex, std::try_to_lock_t)
FOLLY_NODISCARD shared_lock(mutex_type& mutex, std::try_to_lock_t)
: mutex_(std::addressof(mutex)) {
try_lock();
}

shared_lock(mutex_type& mutex, std::adopt_lock_t)
FOLLY_NODISCARD shared_lock(mutex_type& mutex, std::adopt_lock_t)
: mutex_(std::addressof(mutex)) {
token_.state_ = token_type::State::LockedShared;
}

template <typename Clock, typename Duration>
shared_lock(
FOLLY_NODISCARD shared_lock(
mutex_type& mutex,
const std::chrono::time_point<Clock, Duration>& deadline)
: mutex_(std::addressof(mutex)) {
try_lock_until(deadline);
}

template <typename Rep, typename Period>
shared_lock(
FOLLY_NODISCARD shared_lock(
mutex_type& mutex, const std::chrono::duration<Rep, Period>& timeout)
: mutex_(std::addressof(mutex)) {
try_lock_for(timeout);
Expand Down
10 changes: 5 additions & 5 deletions folly/synchronization/Lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct lock_storage<Mutex, void> {
lock_storage(lock_storage&& that) noexcept
: mutex_{std::exchange(that.mutex_, nullptr)},
state_{std::exchange(that.state_, false)} {}
lock_storage(Mutex& mutex, std::adopt_lock_t)
FOLLY_NODISCARD lock_storage(Mutex& mutex, std::adopt_lock_t)
: mutex_{std::addressof(mutex)}, state_{true} {}

void operator=(lock_storage&&) = delete;
Expand Down Expand Up @@ -156,25 +156,25 @@ class lock_base //
using storage::storage;
lock_base() = default;
lock_base(lock_base&&) = default;
explicit lock_base(mutex_type& mutex) {
FOLLY_NODISCARD explicit lock_base(mutex_type& mutex) {
storage::mutex_ = std::addressof(mutex);
lock();
}
lock_base(mutex_type& mutex, std::defer_lock_t) noexcept {
storage::mutex_ = std::addressof(mutex);
}
lock_base(mutex_type& mutex, std::try_to_lock_t) {
FOLLY_NODISCARD lock_base(mutex_type& mutex, std::try_to_lock_t) {
storage::mutex_ = std::addressof(mutex);
try_lock();
}
template <typename Rep, typename Period>
lock_base(
FOLLY_NODISCARD lock_base(
mutex_type& mutex, std::chrono::duration<Rep, Period> const& timeout) {
storage::mutex_ = std::addressof(mutex);
try_lock_for(timeout);
}
template <typename Clock, typename Duration>
lock_base(
FOLLY_NODISCARD lock_base(
mutex_type& mutex,
std::chrono::time_point<Clock, Duration> const& deadline) {
storage::mutex_ = std::addressof(mutex);
Expand Down

0 comments on commit b7af40f

Please sign in to comment.