Skip to content

Commit 174e9a0

Browse files
committed
add documentation
1 parent a35dafc commit 174e9a0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/uu/dd/src/dd.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ pub const ALARM_TRIGGER_TIMER: u8 = 1;
105105
pub const ALARM_TRIGGER_SIGNAL: u8 = 2;
106106

107107
impl Alarm {
108+
/// use to construct alarm timer with duration
108109
pub fn with_interval(interval: Duration) -> Self {
109110
let trigger = Arc::new(AtomicU8::default());
110111

@@ -119,6 +120,11 @@ impl Alarm {
119120
Self { interval, trigger }
120121
}
121122

123+
/// Returns a closure that allows to manually trigger the alarm
124+
///
125+
/// This is useful for cases where more than one alarm even source exists
126+
/// In case of `dd` there is the SIGUSR1/SIGINFO case where we want to
127+
/// trigger an manual progress report.
122128
pub fn manual_trigger_fn(&self) -> Box<dyn Send + Sync + Fn()> {
123129
let weak_trigger = Arc::downgrade(&self.trigger);
124130
Box::new(move || {
@@ -128,10 +134,17 @@ impl Alarm {
128134
})
129135
}
130136

137+
/// Use this function to poll for any pending alarm event
138+
///
139+
/// Returns `ALARM_TRIGGER_NONE` for no pending event.
140+
/// Returns `ALARM_TRIGGER_TIMER` if the event was triggered by timer
141+
/// Returns `ALARM_TRIGGER_SIGNAL` if the event was triggered manually
142+
/// by the closure returned from `manual_trigger_fn`
131143
pub fn get_trigger(&self) -> u8 {
132144
self.trigger.swap(ALARM_TRIGGER_NONE, Relaxed)
133145
}
134146

147+
// Getter function for the configured interval duration
135148
pub fn get_interval(&self) -> Duration {
136149
self.interval
137150
}
@@ -959,6 +972,8 @@ impl<'a> BlockWriter<'a> {
959972
}
960973
}
961974

975+
/// depending on the command line arguments, this function
976+
/// informs the OS to flush/discard the caches for input and/or output file.
962977
fn flush_caches_full_length(i: &Input, o: &Output) -> std::io::Result<()> {
963978
// TODO Better error handling for overflowing `len`.
964979
if i.settings.iflags.nocache {

0 commit comments

Comments
 (0)