[][src]Crate heliograph

Safe bindings to System V semaphore sets

Note that these bindings will not work properly with semaphores that are not handled by heliograph. Even though it will not result in Undefined Behavior, it may result in unwanted results: semaphore sets handled by this library do not actually have nsems semaphores, but nsems + 1, where the additional one is used to track the reference count of the semaphore.

Examples

let file = tempfile::NamedTempFile::new().unwrap();
let key = Key::new(file.as_ref(), NonZeroU8::new(b'a').unwrap()).unwrap();
let sem = Semaphore::create(key, 1, Exclusive::No, Mode::from_bits(0o600).unwrap()).unwrap();
let sem = Arc::new(sem);
{
    let sem = sem.clone();
    std::thread::spawn(move || {
        // Wait until the semaphore gets increased
        sem.op(&[sem.at(0).remove(1)]).unwrap();
    });
}
sem.op(&[sem.at(0).add(1)]).unwrap();
// Here the thread above is unblocked

Re-exports

pub use libc;

Structs

Key

Key, used for referencing a semaphore: two semaphores built with the same key will be the same

Mode
Sem

A semaphore on which one can do an operation

SemOp

A semaphore operation, to be used in Semaphore::op

Semaphore

A System V semaphore set

Enums

Exclusive

Whether the semaphore opening should fail if it does not create the semaphore set as requested