History log of /freebsd-10.1-release/lib/libc/gen/sem.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 272461 02-Oct-2014 gjb

Copy stable/10@r272459 to releng/10.1 as part of
the 10.1-RELEASE process.

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

# 256281 10-Oct-2013 gjb

Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.

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


# 232144 25-Feb-2012 davidxu

In revision 231989, we pass a 16-bit clock ID into kernel, however
according to POSIX document, the clock ID may be dynamically allocated,
it unlikely will be in 64K forever. To make it future compatible, we
pack all timeout information into a new structure called _umtx_time, and
use fourth argument as a size indication, a zero means it is old code
using timespec as timeout value, but the new structure also includes flags
and a clock ID, so the size argument is different than before, and it is
non-zero. With this change, it is possible that a thread can sleep
on any supported clock, though current kernel code does not have such a
POSIX clock driver system.


# 230201 16-Jan-2012 davidxu

Insert read memory barriers.


# 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.


# 202883 23-Jan-2010 antoine

Reapply r201145 to lib/libc/gen/sem.c


# 201555 05-Jan-2010 davidxu

forgot to remove SYM_FBP10. ;-)


# 201553 05-Jan-2010 davidxu

Remove unused macros.


# 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@


# 201145 28-Dec-2009 antoine

(S)LIST_HEAD_INITIALIZER takes a (S)LIST_HEAD as an argument.
Fix some wrong usages.
Note: this does not affect generated binaries as this argument is not used.

PR: 137213
Submitted by: Eygene Ryabinkin (initial version)
MFC after: 1 month


# 151449 18-Oct-2005 stefanf

Make __sem_timedwait() consistent with the sem_timedwait() prototype.


# 149313 20-Aug-2005 stefanf

Include <sys/types.h> and <limits.h> ourselves, don't assume they are included
through <pthread.h>.

gen/sem.c: Prerequisite for <_semaphore.h>
net/getprotoent.c: USHRT_MAX
net/getservent.c: USHRT_MAX
stdio/ungetwc.c: MB_LEN_MAX
stdio/vfwscanf.c: MB_LEN_MAX


# 125521 06-Feb-2004 deischen

Prevent memory leak on sem_destroy() by destroying the semaphore's
internal mutex and CV.


# 125518 06-Feb-2004 deischen

Only allow the semaphore to be taken when the value is positive.
Don't decrement it twice when it is taken.

Reported by: kris


# 125509 05-Feb-2004 deischen

Correct check for invalid semaphore on sem_destroy() (s/==/!=/).

Reported by: kris


# 125502 05-Feb-2004 deischen

Correct the weak reference for sem_unlink.


# 125446 04-Feb-2004 deischen

Allow libc's version of sem_trywait() to work for non-pshared mutexes.


# 125372 03-Feb-2004 deischen

Modify the implementation of libc semaphores so that they can be
overridden by the threads library to provide a userland version
of non-pshared semaphores and cancellation points. Also add
a sem_timedwait().

The libc version of semaphores always uses kernel semaphores
regardless of whether pshared is set or not. When threads are
not present, it is difficult to get sem_wait() or sem_timedwait()
to do the right thing (since pthread_cond_timedwait() and
pthread_cond_wait() are stubs in libc and just return immediately).


# 124614 17-Jan-2004 davidxu

Backout revision 1.6, because some stub functions not in libc, and
non-threaded won't build. The cancellation point support should be
further discussed.


# 124605 17-Jan-2004 davidxu

Enable cancellation point in sem_wait, it is required by POSIX.
For pshared semaphore, this commit still does not enable cancellation
point, I think there should be a pthread_enter_cancellation_point_np
for libc to implement a safe cancellation point.


# 124530 14-Jan-2004 ru

- libc/sys/sem.c was repocopied to libc/gen/sem.c.
- sem_*(3) manpages were repocopied from libc_r.

Reviewed by: deischen
Repocopy by: markm


# 111010 16-Feb-2003 nectar

Eliminate 61 warnings emitted at WARNS=2 (leaving 53 to go).
Only warnings that could be fixed without changing the generated object
code and without restructuring the source code have been handled.

Reviewed by: /sbin/md5


# 109219 14-Jan-2003 tjr

Add the newly created semaphore to the named semaphore list in sem_open()
so that multiple opens of the same semaphore without an intervening
sem_close() return the same object, and so that sem_close() does not
segfault while trying to remove the item from the list.


# 104492 04-Oct-2002 mike

Add restrict type-qualifier to sem_getvalue().


# 103578 18-Sep-2002 alfred

Welcome the sem_ API to libc!