Skip to content
Snippets Groups Projects
  1. Aug 08, 2020
    • Ahmed Abd El Mawgood's avatar
      Add (POSIX defined) struct flock · b5deadbe
      Ahmed Abd El Mawgood authored
      struct flock is posix defined locking mechanism on *nix platform
      
      Example usage (copied from https://gavv.github.io/articles/file-locks/) :
      
        #include <fcntl.h>
      
        struct flock fl;
        memset(&fl, 0, sizeof(fl));
      
        // lock in shared mode
        fl.l_type = F_RDLCK;
      
        // lock entire file
        fl.l_whence = SEEK_SET; // offset base is start of the file
        fl.l_start = 0;         // starting offset is zero
        fl.l_len = 0;           // len is zero, which is a special value representing end
                              // of file (no matter how large the file grows in future)
      
        fl.l_pid = 0; // F_SETLK(W) ignores it; F_OFD_SETLK(W) requires it to be zero
      
        // F_SETLKW specifies blocking mode
        if (fcntl(fd, F_SETLKW, &fl) == -1) {
          exit(1);
        }
      
        // atomically upgrade shared lock to exclusive lock, but only
        // for bytes in range [10; 15)
        //
        // after this call, the process will hold three lock regions:
        //  [0; 10)        - shared lock
        //  [10; 15)       - exclusive lock
        //  [15; SEEK_END) - shared lock
        fl.l_type = F_WRLCK;
        fl.l_start = 10;
        fl.l_len = 5;
      
        // F_SETLKW specifies non-blocking mode
        if (fcntl(fd, F_SETLK, &fl) == -1) {
            exit(1);
        }
      
        // release lock for bytes in range [10; 15)
        fl.l_type = F_UNLCK;
      
        if (fcntl(fd, F_SETLK, &fl) == -1) {
            exit(1);
        }
      
        // close file and release locks for all regions
        // remember that locks are released when process calls close()
        // on any descriptor for a lock file
        close(fd);
      b5deadbe
  2. Aug 04, 2019
  3. Feb 22, 2019
  4. Dec 02, 2018
  5. Aug 27, 2018
  6. Aug 26, 2018
  7. Aug 25, 2018
  8. Mar 15, 2018
  9. Mar 14, 2018
  10. Mar 09, 2018
  11. Mar 07, 2018
    • Dan Robertson's avatar
      Fix platform · 2096b851
      Dan Robertson authored and Dan Robertson's avatar Dan Robertson committed
       - Add cfg to extern crate sc. It is not used by redox.
       - Fix bad syntax in brk implementation for redox
       - nits
         - style: update brk implementation for linux
         - style: no space between not operator and ptr.is_null
         - style: should be a space around = in module path
      2096b851
  12. Mar 04, 2018
  13. Mar 03, 2018
Loading