dispenso 1.6.0
A library for task parallelism
Loading...
Searching...
No Matches
distributed_rw_lock.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
63#include <dispenso/detail/distributed_rw_lock_impl.h>
64#include <dispenso/thread_id.h>
65
66namespace dispenso {
67
88template <size_t N = 16>
89class alignas(kCacheLineSize) DistributedRWLock {
90 public:
92 void lock_shared() {
93 impl_.lock_shared(static_cast<size_t>(threadId()));
94 }
95
98 impl_.unlock_shared(static_cast<size_t>(threadId()));
99 }
100
104 return impl_.try_lock_shared(static_cast<size_t>(threadId()));
105 }
106
108 void lock() {
109 impl_.lock();
110 }
111
114 bool try_lock() {
115 return impl_.try_lock();
116 }
117
119 void unlock() {
120 impl_.unlock();
121 }
122
123 private:
124 detail::DistributedRWLockImpl<N> impl_;
125};
126
127} // namespace dispenso
DISPENSO_DLL_ACCESS uint64_t threadId()