]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Use umtx to implement process sharable semaphore, to make this work,
authordavidxu <davidxu@FreeBSD.org>
Tue, 5 Jan 2010 02:37:59 +0000 (02:37 +0000)
committerdavidxu <davidxu@FreeBSD.org>
Tue, 5 Jan 2010 02:37:59 +0000 (02:37 +0000)
commit87c8a1faf252e6bbed958df4fbcbfae972bf04d9
treec7f16cd6fa7d769efff569dabd92c58350947dcf
parent6c3ad0385cac32227b87922ca96729062247ec89
Use umtx to implement process sharable semaphore, to make this work,
now type sema_t is a structure which can be put in a shared memory area,
and multiple processes can operate it concurrently.
User can either use mmap(MAP_SHARED) + sem_init(pshared=1) or use sem_open()
to initialize a shared semaphore.
Named semaphore uses file system and is located in /tmp directory, and its
file name is prefixed with 'SEMD', so now it is chroot or jail friendly.
In simplist cases, both for named and un-named semaphore, userland code
does not have to enter kernel to reduce/increase semaphore's count.
The semaphore is designed to be crash-safe, it means even if an application
is crashed in the middle of operating semaphore, the semaphore state is
still safely recovered by later use, there is no waiter counter maintained
by userland code.
The main semaphore code is in libc and libthr only has some necessary stubs,
this makes it possible that a non-threaded application can use semaphore
without linking to thread library.
Old semaphore implementation is kept libc to maintain binary compatibility.
The kernel ksem API is no longer used in the new implemenation.

Discussed on: threads@
18 files changed:
ObsoleteFiles.inc
include/Makefile
include/semaphore.h [new file with mode: 0644]
lib/libc/gen/Makefile.inc
lib/libc/gen/Symbol.map
lib/libc/gen/_pthread_stubs.c
lib/libc/gen/sem.c
lib/libc/gen/sem_new.c [new file with mode: 0644]
lib/libc/include/libc_private.h
lib/libthr/pthread.map
lib/libthr/thread/Makefile.inc
lib/libthr/thread/thr_init.c
lib/libthr/thread/thr_private.h
lib/libthr/thread/thr_sem.c
lib/libthr/thread/thr_sem_new.c [new file with mode: 0644]
sys/kern/uipc_sem.c
sys/sys/_semaphore.h
sys/sys/semaphore.h [deleted file]