1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

add documentation

This commit is contained in:
Ulrich Hornung 2024-03-23 16:51:12 +01:00
parent a35dafcd30
commit 174e9a0af9
No known key found for this signature in database
GPG key ID: 64EA3BAAF1BC0603

View file

@ -105,6 +105,7 @@ pub const ALARM_TRIGGER_TIMER: u8 = 1;
pub const ALARM_TRIGGER_SIGNAL: u8 = 2; pub const ALARM_TRIGGER_SIGNAL: u8 = 2;
impl Alarm { impl Alarm {
/// use to construct alarm timer with duration
pub fn with_interval(interval: Duration) -> Self { pub fn with_interval(interval: Duration) -> Self {
let trigger = Arc::new(AtomicU8::default()); let trigger = Arc::new(AtomicU8::default());
@ -119,6 +120,11 @@ impl Alarm {
Self { interval, trigger } Self { interval, trigger }
} }
/// Returns a closure that allows to manually trigger the alarm
///
/// This is useful for cases where more than one alarm even source exists
/// In case of `dd` there is the SIGUSR1/SIGINFO case where we want to
/// trigger an manual progress report.
pub fn manual_trigger_fn(&self) -> Box<dyn Send + Sync + Fn()> { pub fn manual_trigger_fn(&self) -> Box<dyn Send + Sync + Fn()> {
let weak_trigger = Arc::downgrade(&self.trigger); let weak_trigger = Arc::downgrade(&self.trigger);
Box::new(move || { Box::new(move || {
@ -128,10 +134,17 @@ impl Alarm {
}) })
} }
/// Use this function to poll for any pending alarm event
///
/// Returns `ALARM_TRIGGER_NONE` for no pending event.
/// Returns `ALARM_TRIGGER_TIMER` if the event was triggered by timer
/// Returns `ALARM_TRIGGER_SIGNAL` if the event was triggered manually
/// by the closure returned from `manual_trigger_fn`
pub fn get_trigger(&self) -> u8 { pub fn get_trigger(&self) -> u8 {
self.trigger.swap(ALARM_TRIGGER_NONE, Relaxed) self.trigger.swap(ALARM_TRIGGER_NONE, Relaxed)
} }
// Getter function for the configured interval duration
pub fn get_interval(&self) -> Duration { pub fn get_interval(&self) -> Duration {
self.interval self.interval
} }
@ -959,6 +972,8 @@ impl<'a> BlockWriter<'a> {
} }
} }
/// depending on the command line arguments, this function
/// informs the OS to flush/discard the caches for input and/or output file.
fn flush_caches_full_length(i: &Input, o: &Output) -> std::io::Result<()> { fn flush_caches_full_length(i: &Input, o: &Output) -> std::io::Result<()> {
// TODO Better error handling for overflowing `len`. // TODO Better error handling for overflowing `len`.
if i.settings.iflags.nocache { if i.settings.iflags.nocache {