Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 Dec 2004 22:41:45 -0500 (EST)
From:      Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To:        joe@zircon.seattle.wa.us
Cc:        arch@FreeBSD.org
Subject:   Re: Fixing Posix semaphores
Message-ID:  <200412220341.iBM3fj5j043952@khavrinen.lcs.mit.edu>
In-Reply-To: <1103681460.30309.799.camel@zircon.zircon.seattle.wa.us>
References:  <1102975803.30309.196.camel@zircon.zircon.seattle.wa.us> <Pine.NEB.3.96L.1041221235624.62809A-100000@fledge.watson.org> <20041222011506.GG801@straylight.m.ringlet.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200412220341.iBM3fj5j043952>