Re: Fixing Posix semaphores

From: Garrett Wollman (wollman_at_khavrinen.lcs.mit.edu)
Date: 12/22/04

  • Next message: Sam: "Re: Header files with enums instead of defines?"
    Date: Tue, 21 Dec 2004 22:41:45 -0500 (EST)
    To: joe@zircon.seattle.wa.us
    
    

    In article <1103681460.30309.799.camel@zircon.zircon.seattle.wa.us> you write:

    >So, there are words there that can be interpreted many different ways.
    >The most restricted way to view them is as 14-character names optionally
    >beginning with a slash. That also seems to me to be the stupidest way
    >to view them. Robert's idea of semfs seems brilliant, allowing multiple
    >name spaces for jailed processes. I plan to start thinking and working
    >on that idea shortly.

    Here is an even easier way that avoids creating a special file type...

    sem_open() can be implemented as:

            fd = shm_open(name, oflag, omode);
            if (oflag & O_CREAT) {
                    ftruncate(fd, sizeof(struct sem_private));
            }
            sem_private = mmap(fd, ...);
            sem_private->fd = fd;
            sem = malloc(sizeof *sem);
            _sem_init(sem, sem_private, value);
            return (sem);

    The underlying semaphore can then be implemented in the standard way
    with a mutex, a condition variable (or simulation thereof), and a
    counter in the shared-memory region -- no (additional) kernel code
    required. (This avoids the overhead of a system call if there is no
    need to wait.)

    Alternatively, given the current kernel implementation, you can very
    simply convert any vnode into a 20-byte flat name for the file using
    VFS_VPTOFH() -- this would require only minimal changes to the
    existing code.

    -GAWollman

    _______________________________________________
    freebsd-arch@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-arch
    To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"


  • Next message: Sam: "Re: Header files with enums instead of defines?"