History log of /freebsd-9.3-release/lib/libc/gen/sem_new.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 267654 19-Jun-2014 gjb

Copy stable/9 to releng/9.3 as part of the 9.3-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 266327 17-May-2014 kib

MFC r265847:
Fix sem_unlink(3) to properly invalidate the semaphores name cache.

PR: standards/189353


# 266326 17-May-2014 kib

MFC r246894 (by davidxu):
Make more code be protected by internal mutex.


# 266325 17-May-2014 kib

MFC r246872 (by davidxu):

Simplify code by using flag O_EXLOCK.


# 266324 17-May-2014 kib

MFC r265845:
Style.


# 263255 17-Mar-2014 davidxu

MFC r263107:

To avoid missing a chance to cancel thread, call _pthread_testcancel at the
beginning of _sem_timedwait.

Submitted by: Eric van Gyzen &lt; eric at vangyzen dot net &gt;


# 261813 12-Feb-2014 jilles

MFC r241046: libc: Use O_CLOEXEC for various internal file descriptors.

This fixes a race condition where another thread may fork(), unintentionally
passing the descriptor to the child process.

This commit only adds O_CLOEXEC flags to open() or openat() calls where no
fcntl(fd, F_SETFD, FD_CLOEXEC) follows.


# 235035 04-May-2012 jilles

MFC r234057: sem_open: Make sure to fail an O_CREAT|O_EXCL open, even if
that semaphore is already open in this process.

If the named semaphore is already open, sem_open() only increments a
reference count and did not take the flags into account (which otherwise
happens by passing them to open()). Add an extra check for O_CREAT|O_EXCL.

PR: kern/166706


# 225736 22-Sep-2011 kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by: re (implicit)


# 213153 24-Sep-2010 davidxu

To support stack unwinding for cancellation points, add -fexceptions flag
for them, two functions _pthread_cancel_enter and _pthread_cancel_leave
are added to let thread enter and leave a cancellation point, it also
makes it possible that other functions can be cancellation points in
libraries without having to be rewritten in libthr.


# 202557 18-Jan-2010 davidxu

preserve errno when processing error cases.


# 202326 14-Jan-2010 davidxu

Also call sem_module_init in sem_close to initialize mutex
with some attributes.


# 202185 13-Jan-2010 davidxu

Return SEM_FAILED instead of NULL, though there are same, but the
SEM_FAILED is more suitable name.
In function, sem_close(), always set errno on error.


# 201715 07-Jan-2010 davidxu

Don't forget to use fourth argument if O_CREAT is set in argument oflag.
The fourth specifies initial value for the semaphore.


# 201561 05-Jan-2010 davidxu

More cleanup, remove _libc prefix because libthr no longer has stubs
referencing them.


# 201547 05-Jan-2010 davidxu

Don't check has_waiters twice, inline some small functions.
performance result on my machine:
mutex Elapsed: 902115 us; per iteration: 90 ns.
semaphore Elapsed: 958780 us; per iteration: 95 ns.


# 201546 05-Jan-2010 davidxu

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@