Commit Graph

23 Commits

Author SHA1 Message Date
Pedro F. Giffuni
d915a14ef0 libc: further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using mis-identified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.
2017-11-25 17:12:48 +00:00
David Xu
df1f1bae9e 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.
2012-02-25 02:12:17 +00:00
David Xu
d22d46ce27 Insert read memory barriers. 2012-01-16 06:15:14 +00:00
David Xu
f4213b9006 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.
2010-09-25 01:57:47 +00:00
Antoine Brodin
dd554467bb Reapply r201145 to lib/libc/gen/sem.c 2010-01-23 12:48:46 +00:00
David Xu
3e18aa9869 forgot to remove SYM_FBP10. ;-) 2010-01-05 05:47:18 +00:00
David Xu
79aaab046d Remove unused macros. 2010-01-05 05:44:52 +00:00
David Xu
9b0f1823b5 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@
2010-01-05 02:37:59 +00:00
Antoine Brodin
13e403fdea (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
2009-12-28 22:56:30 +00:00
Stefan Farfeleder
c86b3a98fe Make __sem_timedwait() consistent with the sem_timedwait() prototype. 2005-10-18 17:24:03 +00:00
Stefan Farfeleder
d8f77b4529 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
2005-08-20 07:59:13 +00:00
Daniel Eischen
e3b4bf9411 Prevent memory leak on sem_destroy() by destroying the semaphore's
internal mutex and CV.
2004-02-06 15:15:44 +00:00
Daniel Eischen
e7f1524858 Only allow the semaphore to be taken when the value is positive.
Don't decrement it twice when it is taken.

Reported by:	kris
2004-02-06 13:54:38 +00:00
Daniel Eischen
08a6a888da Correct check for invalid semaphore on sem_destroy() (s/==/!=/).
Reported by:	kris
2004-02-05 23:32:45 +00:00
Daniel Eischen
3962ef4305 Correct the weak reference for sem_unlink. 2004-02-05 22:36:27 +00:00
Daniel Eischen
903f2e5041 Allow libc's version of sem_trywait() to work for non-pshared mutexes. 2004-02-04 15:37:48 +00:00
Daniel Eischen
5c70dac879 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).
2004-02-03 05:47:19 +00:00
David Xu
b6897522fa 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.
2004-01-17 07:15:06 +00:00
David Xu
cc3782cbc7 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.
2004-01-17 02:45:37 +00:00
Jacques Vidrine
e0554a531f 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
2003-02-16 17:29:11 +00:00
Tim J. Robbins
a91b25dc1c 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.
2003-01-14 03:36:45 +00:00
Mike Barcroft
ddb4fb5b44 Add restrict type-qualifier to sem_getvalue(). 2002-10-04 21:32:00 +00:00
Alfred Perlstein
bf4dc8772e Welcome the sem_ API to libc! 2002-09-19 01:14:08 +00:00