File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 27
27
#include <linux/err.h>
28
28
#include <linux/errname.h>
29
29
#include <linux/mutex.h>
30
+ #include <linux/rcupdate.h>
30
31
#include <linux/refcount.h>
31
32
#include <linux/sched/signal.h>
32
33
#include <linux/spinlock.h>
@@ -170,6 +171,20 @@ const char *rust_helper_dev_name(const struct device *dev)
170
171
}
171
172
EXPORT_SYMBOL_GPL (rust_helper_dev_name );
172
173
174
+ /* rcu */
175
+ void rust_helper_rcu_read_lock (void )
176
+ {
177
+ rcu_read_lock ();
178
+ }
179
+ EXPORT_SYMBOL_GPL (rust_helper_rcu_read_lock );
180
+
181
+ void rust_helper_rcu_read_unlock (void )
182
+ {
183
+ rcu_read_unlock ();
184
+ }
185
+ EXPORT_SYMBOL_GPL (rust_helper_rcu_read_unlock );
186
+ /* end rcu */
187
+
173
188
/*
174
189
* `bindgen` binds the C `size_t` type as the Rust `usize` type, so we can
175
190
* use it in contexts where Rust expects a `usize` like slice (array) indices.
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ mod arc;
11
11
mod condvar;
12
12
pub mod lock;
13
13
mod locked_by;
14
+ pub mod rcu;
14
15
15
16
pub use arc:: { Arc , ArcBorrow , UniqueArc } ;
16
17
pub use condvar:: CondVar ;
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: GPL-2.0
2
+
3
+ //! RCU support.
4
+ //!
5
+ //! C header: [`include/linux/rcupdate.h`](../../../../include/linux/rcupdate.h)
6
+
7
+ use crate :: bindings;
8
+ use core:: marker:: PhantomData ;
9
+
10
+ /// Evidence that the RCU read side lock is held on the current thread/CPU.
11
+ ///
12
+ /// The type is explicitly not `Send` because this property is per-thread/CPU.
13
+ ///
14
+ /// # Invariants
15
+ ///
16
+ /// The RCU read side lock is actually held while instances of this guard exist.
17
+ pub struct Guard {
18
+ _not_send : PhantomData < * mut ( ) > ,
19
+ }
20
+
21
+ impl Guard {
22
+ /// Acquires the RCU read side lock and returns a guard.
23
+ pub fn new ( ) -> Self {
24
+ // SAFETY: An FFI call with no additional requirements.
25
+ unsafe { bindings:: rcu_read_lock ( ) } ;
26
+ // INVARIANT: The RCU read side lock was just acquired above.
27
+ Self {
28
+ _not_send : PhantomData ,
29
+ }
30
+ }
31
+
32
+ /// Explicitly releases the RCU read side lock.
33
+ pub fn unlock ( self ) { }
34
+ }
35
+
36
+ impl Default for Guard {
37
+ fn default ( ) -> Self {
38
+ Self :: new ( )
39
+ }
40
+ }
41
+
42
+ impl Drop for Guard {
43
+ fn drop ( & mut self ) {
44
+ // SAFETY: By the type invariants, the rcu read side is locked, so it is ok to unlock it.
45
+ unsafe { bindings:: rcu_read_unlock ( ) } ;
46
+ }
47
+ }
48
+
49
+ /// Acquires the RCU read side lock.
50
+ pub fn read_lock ( ) -> Guard {
51
+ Guard :: new ( )
52
+ }
You can’t perform that action at this time.
0 commit comments