@@ -19,6 +19,7 @@ use kernel::{
19
19
io_buffer:: { IoBufferReader , IoBufferWriter } ,
20
20
miscdev, new_mutex, pin_init,
21
21
sync:: { Arc , ArcBorrow , Mutex } ,
22
+ types:: Opaque ,
22
23
} ;
23
24
24
25
module ! {
@@ -29,22 +30,11 @@ module! {
29
30
license: "GPL" ,
30
31
}
31
32
32
- // Fist I made CompletionDev { completion: bindings::completion }.
33
- // But it didn't work because we cannot get mutable reference to CompletionDev in read/write functions.
34
- // The argument of read/write functions is ArcBorrow<'_, CompletionDev>.
35
- // So it's not allowed to get the mutable reference to CompletionDev.
36
- // The only way to mutate through ArcBorrow is to use Mutex/RwLock/Atomic types.
37
- // (see doc.rust-lang.org/std/sync/struct.Mutex.html)
38
- // Finally I makde CompletionInner struct and put it into Mutex.
39
- struct CompletionInner {
40
- completion : bindings:: completion ,
41
- }
42
-
43
33
// internal info between file operations
44
34
#[ pin_data]
45
35
struct CompletionDev {
46
36
#[ pin]
47
- inner : Mutex < CompletionInner > ,
37
+ completion : Opaque < bindings :: completion > ,
48
38
}
49
39
50
40
// TODO: impl CompletionDev::try_new
@@ -65,15 +55,13 @@ impl CompletionDev {
65
55
unsafe {
66
56
bindings:: __init_swait_queue_head (
67
57
& mut compl. wait ,
68
- compl_name. as_char_ptr ( ) as * mut core :: ffi :: c_char ,
69
- & mut key,
58
+ compl_name. as_char_ptr ( ) ,
59
+ key. as_ptr ( ) ,
70
60
) ;
71
61
}
72
62
73
63
let dev = Arc :: pin_init ( pin_init ! ( Self {
74
- inner <- new_mutex!( CompletionInner {
75
- completion: compl,
76
- } ) ,
64
+ completion: Opaque :: new( compl) ,
77
65
} ) ) ?;
78
66
79
67
Ok ( dev)
@@ -105,9 +93,8 @@ impl file::Operations for RustFile {
105
93
) -> Result < usize > {
106
94
pr_info ! ( "read is invoked\n " ) ;
107
95
108
- let mut inner_guard = shared. inner . lock ( ) ;
109
96
unsafe {
110
- bindings:: wait_for_completion ( & mut inner_guard . completion ) ;
97
+ bindings:: wait_for_completion ( Opaque :: raw_get ( & shared . completion ) ) ;
111
98
}
112
99
113
100
Ok ( 0 )
@@ -121,9 +108,8 @@ impl file::Operations for RustFile {
121
108
) -> Result < usize > {
122
109
pr_info ! ( "write is invoked\n " ) ;
123
110
124
- let mut inner_guard = shared. inner . lock ( ) ;
125
111
unsafe {
126
- bindings:: complete ( & mut inner_guard . completion ) ;
112
+ bindings:: complete ( Opaque :: raw_get ( & shared . completion ) ) ;
127
113
}
128
114
129
115
// return non-zero value to avoid infinite re-try
0 commit comments