Skip to content

Commit 62b89d6

Browse files
committed
ldd ch06: remove dummy
Signed-off-by: Gioh Kim <gurugio@gmail.com>
1 parent 1ba7e21 commit 62b89d6

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

samples/rust/rust_ldd06.rs

+3-18
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ module! {
3838
// Finally I makde CompletionInner struct and put it into Mutex.
3939
struct CompletionInner {
4040
completion: bindings::completion,
41-
dummy: usize, // nothing but to check how to use Mutex
4241
}
4342

4443
// internal info between file operations
@@ -74,7 +73,6 @@ impl CompletionDev {
7473
let dev = Arc::pin_init(pin_init!(Self {
7574
inner <- new_mutex!(CompletionInner {
7675
completion: compl,
77-
dummy: 0,
7876
}),
7977
}))?;
8078

@@ -108,9 +106,6 @@ impl file::Operations for RustFile {
108106
pr_info!("read is invoked\n");
109107

110108
let mut inner_guard = shared.inner.lock();
111-
inner_guard.dummy += 1;
112-
pr_info!("read:dummy={}\n", inner_guard.dummy);
113-
114109
unsafe {
115110
bindings::wait_for_completion(&mut inner_guard.completion);
116111
}
@@ -127,26 +122,16 @@ impl file::Operations for RustFile {
127122
pr_info!("write is invoked\n");
128123

129124
let mut inner_guard = shared.inner.lock();
130-
pr_info!("write:dummy={}\n", inner_guard.dummy);
131-
if inner_guard.dummy == 1 {
132-
pr_info!("read() is waiting for completion\n");
133-
134-
unsafe {
135-
bindings::complete(&mut inner_guard.completion);
136-
}
137-
} else if inner_guard.dummy == 0 {
138-
pr_info!("read() is not waiting for completion\n");
139-
} else {
140-
pr_info!("Something went wrong\n");
125+
unsafe {
126+
bindings::complete(&mut inner_guard.completion);
141127
}
142128

143129
// return non-zero value to avoid infinite re-try
144130
Ok(data.len())
145131
}
146132

147-
fn release(data: Self::Data, _file: &File) {
133+
fn release(_data: Self::Data, _file: &File) {
148134
pr_info!("release is invoked\n");
149-
pr_info!("release:dummy={}\n", data.inner.lock().dummy);
150135
}
151136
}
152137

0 commit comments

Comments
 (0)