pub fn new(path: &Path) -> Result<Semalock, SemalockError> {
        OpenOptions::new()
            .write(true)
            .read(true)
            .create(true)
            .open(path)
            .map_err(|e| format!("OpenOptions::open failed: {}", e.description()))
            .and_then(move |file| {
                let fd = file.as_raw_fd();

                let file_hash = {
                    let mut s = DefaultHasher::new();
                    path.to_string_lossy().hash(&mut s);
                    s.finish()
                };

                let sem_name = format!("fast-lock-{}-{:x}", 0, file_hash);

                CString::new(sem_name)
                    .map_err(|e| format!("CString::new failed: {}", e.description()))
                    .and_then(move |sem_name_cstring| {
                        // @TODO move most of this out of unsafe
                        let sem = unsafe {
                            let sem =
                                libc::sem_open(sem_name_cstring.as_ptr(), libc::O_CREAT, 0o644, 1);

                            if sem == libc::SEM_FAILED {
                                let e = errno::errno();
                                Err(format!("sem_open {}: {}", e.0, e))
                            } else {
                                Ok(sem)
                            }
                        };

                        sem.map(|sem| Semalock {
                            fd,
                            file,
                            sem,
                            sem_name_cstring,
                        })
                    })
            })
    }
/// Creates a new `Semalock`, opening or creating the file
/// for reading and writing. A POSIX named semaphore is
/// allocated (based on the hash of the path) and is used
/// to reduce contention when acquiring exclusive file locks.
/// On Linux, this is nearly FIFO in terms of acquiring the
/// lock, though not always. Good (i.e. very minimal CPU usage)
/// performance has been tested with upto 8192 simultaneous
/// writers.
Creates a new `Semalock`, opening or creating the file
for reading and writing. A POSIX named semaphore is
allocated (based on the hash of the path) and is used
to reduce contention when acquiring exclusive file locks.
On Linux, this is nearly FIFO in terms of acquiring the
lock, though not always. Good
performance has been tested with upto 8192 simultaneous
writers.
Creates a new ` Semalock ` opening or creating the file for reading and writing . A POSIX named semaphore is allocated ( based on the hash of the path ) and is used to reduce contention when acquiring exclusive file locks . On Linux this is nearly FIFO in terms of acquiring the lock though not always . Good performance has been tested with upto 8192 simultaneous writers .
pub fn new(path: &Path) -> Result<Semalock, SemalockError> {
        OpenOptions::new()
            .write(true)
            .read(true)
            .create(true)
            .open(path)
            .map_err(|e| format!("OpenOptions::open failed: {}", e.description()))
            .and_then(move |file| {
                let fd = file.as_raw_fd();
                let file_hash = {
                    let mut s = DefaultHasher::new();
                    path.to_string_lossy().hash(&mut s);
                    s.finish()
                };
                let sem_name = format!("fast-lock-{}-{:x}", 0, file_hash);
                CString::new(sem_name)
                    .map_err(|e| format!("CString::new failed: {}", e.description()))
                    .and_then(move |sem_name_cstring| {
                        // @TODO move most of this out of unsafe
                        let sem = unsafe {
                            let sem =
                                libc::sem_open(sem_name_cstring.as_ptr(), libc::O_CREAT, 0o644, 1);
                            if sem == libc::SEM_FAILED {
                                let e = errno::errno();
                                Err(format!("sem_open {}: {}", e.0, e))
                            } else {
                                Ok(sem)
                            }
                        };
                        sem.map(|sem| Semalock {
                            fd,
                            file,
                            sem,
                            sem_name_cstring,
                        })
                    })
            })
    }
pub fn new ( path : & Path ) -> Result < Semalock , SemalockError > { OpenOptions :: new ( ) . write ( true ) . read ( true ) . create ( true ) . open ( path ) . map_err ( | e | format ! ( " " e description ( ) ) ) . and_then ( move | file | { let fd = file . as_raw_fd ( ) ; let file_hash = { let mut s = DefaultHasher :: new ( ) ; path . to_string_lossy ( ) . hash ( & mut s ) ; s . finish ( ) } ; let sem_name = format ! ( " " 0 file_hash ) ; CString :: new ( sem_name ) . map_err ( | e | format ! ( " " e description ( ) ) ) . and_then ( move | sem_name_cstring | { // @TODO move most of this out of unsafe let sem = unsafe { let sem = libc :: sem_open ( sem_name_cstring . as_ptr ( ) , libc :: O_CREAT , 0o644 , 1 ) ; if sem == libc :: SEM_FAILED { let e = errno :: errno ( ) ; Err ( format ! ( " " e 0 e ) ) } else { Ok ( sem ) } } ; sem . map ( | sem | Semalock { fd , file , sem , sem_name_cstring , } ) } ) } ) }
Creates a new `Semalock`, opening or creating the file
for reading and writing.
Creates a new ` Semalock ` opening or creating the file for reading and writing .
path
&Path