Initial revision

2002-11-26  Ulrich Drepper  <drepper@redhat.com>
	* allocatestack.c (queue_stack): Don't remove stack from list here.
	Do it in the caller.  Correct condition to prematurely terminate
	loop to free stacks.
	(__deallocate_stack): Remove stack from list here.
2002-11-26  Ulrich Drepper  <drepper@redhat.com>
	* Makefile (tests): Add tst-stack1.
	* tst-stack1.c: New file.
	* allocatestack.c (allocate_stack): Initialize the TCB on a user
	provided stack.
	* pthread_attr_getstack.c: Return bottom of the thread area.
2002-11-25  Ulrich Drepper  <drepper@redhat.com>
	* Makefile (libpthread-routines): Add pt-allocrtsig and
	pthread_kill_other_threads.
	* pt-allocrtsig.c: New file.
	* pthread_kill_other_threads.c: New file.
	* sysdeps/unix/sysv/linux/allocrtsig.c: Add additional aliases for
	all three functions.
	* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
	allocrtsig.
	* sysdeps/unix/sysv/linux/Versions (libc:GLIBC_PRIVATE): Export
	__libc_current_sigrtmin_private, __libc_current_sigrtmax_private,
	and __libc_allocate_rtsig_private.
	* Versions (libpthread): Export pthread_kill_other_threads_np,
	__libc_current_sigrtmin, and __libc_current_sigrtmax.
2002-11-24  Ulrich Drepper  <drepper@redhat.com>

	* allocatestack.c (allocate_stack): stackaddr in attribute points to
	the end of the stack.  Adjust computations.
	When mprotect call fails dequeue stack and free it.
	* pthread_attr_setstack.c: Store top of the stack in stackaddr
	attribute.
	* pthread_getattr_np.c: Likewise.

	* descr.h (IS_DETACHED): Add some more parenthesis to prevent
	surprises.

2002-11-23  Ulrich Drepper  <drepper@redhat.com>

	* sysdeps/pthread/pthread.h (pthread_self): __THROW must come before
	attribute definitions.  Patch by Luca Barbieri <ldb@ldb.ods.org>.

2002-11-22  Ulrich Drepper  <drepper@redhat.com>

	* pthread_getspecific.c: Optimize access to first 2nd-level array.
	* pthread_setspecific.c: Likewise.

2002-11-21  Ulrich Drepper  <drepper@redhat.com>

	* sysdeps/unix/sysv/linux/i386/createthread.c: Remove CLONE_ flags
	definitions.  Get them from the official place.
	* sysdeps/unix/sysv/linux/i386/fork.c: Likewise.

	* sysdeps/unix/sysv/linux/i386/createthread.c: Update CLONE_* flags.
	Use new CLONE_ flags in clone() calls.

	* sysdeps/unix/sysv/linux/fork.c: Use ARCH_FORK to actually fork.
	* sysdeps/unix/sysv/linux/i386/fork.c: New file.

	* Versions: Add pthread_* functions for libc.
	* forward.c: New file.

	* sysdeps/pthread/Makefile (libpthread-sysdeps_routines): Add
	errno-loc.
	* herrno.c: New file.
	* res.c: New file.

	* Makefile (libpthread-routines): Remove sem_post, sem_wait,
	sem_trywait, and sem_timedwait.  Add herrno and res.
	* sem_init.c: Don't initialize lock and waiters members.
	* sem_open.c: Likewise.
	* sem_post.c: Removed.
	* sem_wait.c: Removed.
	* sem_trywait.c: Removed.
	* sem_timedwait.c: Removed.
	* sysdeps/unix/sysv/linux/i386/i486/lowlevelsem.S: Complete rewrite.
	Includes full implementations of sem_post, sem_wait, sem_trywait,
	and sem_timedwait.
	* sysdeps/unix/sysv/linux/i386/lowlevelsem.h (lll_sem_post): Adjust
	for new implementation.
	* sysdeps/unix/sysv/linux/internaltypes.h (struct sem): Remove lock
	and waiters fields.

	* tst-sem3.c: Improve error message.
	* tst-signal3.c: Likewise.

	* init.c (__pthread_initialize_minimal): Use set_tid_address syscall
	to tell the kernel about the termination futex and to initialize tid
	member.  Don't initialize main_thread.
	* descr.h (struct pthread): Remove main_thread member.
	* cancelllation.c (__do_cancel): Remove code handling main thread.
	The main thread is not special anymore.

	* allocatestack.c (__reclaim_stacks): Mark stacks as unused.  Add
	size of the stacks to stack_cache_actsize.

	* pt-readv.c: Add missing "defined".
	* pt-sigwait.c: Likewise.
	* pt-writev.c: Likewise.

2002-11-09  Ulrich Drepper  <drepper@redhat.com>

	* Versions: Export __connect from libpthread.
	Patch by Luca Barbieri <ldb@ldb.ods.org>.

	* Makefile (libpthread-routines): Add pt-raise.
	* sysdeps/unix/sysv/linux/raise.c: New file.
	* sysdeps/unix/sysv/linux/pt-raise.c: New file.
	* sysdeps/generic/pt-raise.c: New file.

	* pthread_cond_init.c: Initialize all data elements of the condvar
	structure.  Patch by Luca Barbieri <ldb@ldb.ods.org>.

	* pthread_attr_init.c: Actually implement 2.0 compatibility version.
	* pthread_create.c: Likewise.

	* Makefile (tests): Add tst-key1, tst-key2, tst-key3.
	* tst-key1.c: New file.
	* tst-key2.c: New file.
	* tst-key3.c: New file.

	* Versions: Export pthread_detach for version GLIBC_2.0.
	Reported by Saurabh Desai <sdesai@austin.ibm.com>.

2002-11-08  Ulrich Drepper  <drepper@redhat.com>

	* pthread_key_create.c: Terminate search after an unused key was found.
	Patch by Luca Barbieri <ldb@ldb.ods.org>.

	* sysdeps/unix/sysv/linux/i386/pthread_once.S: Return zero.
	Patch by Luca Barbieri <ldb@ldb.ods.org>.

2002-10-10  Ulrich Drepper  <drepper@redhat.com>

	* sysdeps/unix/sysv/linux/i386/i486/lowlevelsem.S: Use slow generic
	dynamic lookup for errno in PIC.

	* allocatestack.c (get_cached_stack): Rearrange code slightly to
	release the stack lock as soon as possible.
	Call _dl_allocate_tls_init for TCB from the cache to re-initialize
	the static TLS block.
	(allocate_stack): Call _dl_allocate_tls_init for user-provided stack.

	* cancellation.c: Renamed from cancelation.c.
	* Makefile: Adjust accordingly.
	* pthreadP.h (CANCELLATION_P): Renamed from CANCELATION_P.
	* cleanup_defer.c: Use CANCELLATION_P.
	* pthread_testcancel.c: Likewise.
	* descr.h: Fix spelling in comments.
	* init.c: Likewise.
	* pthread_getattr_np.c: Likewise.
	* pthread_getschedparam.c: Likewise.
	* pthread_setschedparam.c: Likewise.
	* Versions: Likewise.

	* pt-pselect.c: New file.
	* Makefile (libpthread-routines): Add pt-pselect.
	* Versions: Add pselect.

	* tst-cancel4.c: New file.
	* Makefile (tests): Add tst-cancel4.

2002-10-09  Ulrich Drepper  <drepper@redhat.com>

	* pthread_mutex_lock.c: Always record lock ownership.
	* pthread_mutex_timedlock.c: Likewise.
	* pthread_mutex_trylock.c: Likewise.

	* pt-readv.c: New file.
	* pt-writev.c: New file.
	* pt-creat.c: New file.
	* pt-msgrcv.c: New file.
	* pt-msgsnd.c: New file.
	* pt-poll.c: New file.
	* pt-select.c: New file.
	* pt-sigpause.c: New file.
	* pt-sigsuspend.c: New file.
	* pt-sigwait.c: New file.
	* pt-sigwaitinfo.c: New file.
	* pt-waitid.c: New file.
	* Makefile (libpthread-routines): Add pt-readv, pt-writev, pt-creat,
	pt-msgrcv, pt-msgsnd, pt-poll, pt-select, pt-sigpause, pt-sigsuspend,
	pt-sigwait, pt-sigwaitinfo, and pt-waitid.
	* Versions: Add all the new functions.

	* tst-exit1.c: New file.
	* Makefile (tests): Add tst-exit1.

	* sem_timedwait.c: Minor optimization for more optimal fastpath.

2002-10-08  Ulrich Drepper  <drepper@redhat.com>

	* pt-fcntl.c: Only enable asynchronous cancellation for F_SETLKW.

	* pthread_join.c: Enable asynchronous cancellation around lll_wait_tid
	call.  pthread_join is an official cancellation point.
	* pthread_timedjoin.c: Likewise.

	* pthread_cond_wait.c: Revert order in which internal lock are dropped
	and the condvar's mutex are retrieved.
	* pthread_cond_timedwait.c: Likewise.
	Reported by dice@saros.East.Sun.COM.

2002-10-07  Ulrich Drepper  <drepper@redhat.com>

	* pthreadP.h: Cut out all type definitions and move them...
	* sysdeps/unix/sysv/linux/internaltypes.h: ...here.  New file.
	* pthreadP.h: Include <internaltypes.h>.

	* sysdeps/unix/sysv/linux/i386/lowlevelsem.h (lll_sem_post): Little
	performance tweaks.

	* sem_trywait.c: Shuffle #includes around to get right order.
	* sem_timedwait.c: Likewise.
	* sem_post.c: Likewise.
	* sem_wait.c: Likewise.

	* nptl 0.3 released.

	* Makefile (tests): Add tst-signal3.
	* tst-signal3.c: New file.

2002-10-05  Ulrich Drepper  <drepper@redhat.com>

	* sysdeps/unix/sysv/linux/i386/lowlevelsem.h: Tell the compiler that
	the asms modify the sem object.
	(__lll_sem_timedwait): Now takes struct sem* as first parameter.

	* sysdeps/unix/sysv/linux/i386/bits/semaphore.h (sem_t): Don't expose
	the actual members.
	* pthreadP.h (struct sem): New type.  Actual semaphore type.
	* semaphoreP.h: Include pthreadP.h.
	* sem_getvalue.c: Adjust to sem_t change.
	* sem_init.c: Likewise.
	* sem_open.c: Likewise.
	* sem_post.c: Likewise.
	* sem_timedwait.c: Likewise.
	* sem_trywait.c: Likewise.
	* sem_wait.c: Likewise.

2002-10-04  Ulrich Drepper  <drepper@redhat.com>

	* Makefile (tests): Add tst-basic2, tst-exec1, tst-exec3, tst-exec3.
	* tst-basic2.c: New file.
	* tst-exec1.c: New file.
	* tst-exec2.c: New file.
	* tst-exec3.c: New file.

	* tst-fork1.c: Remove extra */.

	* nptl 0.2 released.  The API for IA-32 is complete.
This commit is contained in:
Ulrich Drepper 2002-11-26 22:50:54 +00:00
parent 6938e63f71
commit 76a50749f7
352 changed files with 29447 additions and 0 deletions

92
nptl/ANNOUNCE Normal file
View File

@ -0,0 +1,92 @@
Now that the Linux kernel is once again able to run all the tests we
have and since glibc 2.3 was released it was time for a new code drop.
I've uploaded the second code drop for the Native POSIX Thread
Library:
ftp://people.redhat.com/drepper/nptl/nptl-0.2.tar.bz2
You need
- the latest of Linus' kernel from BitKeeper (or 2.5.41 when it
is released);
- glibc 2.3
- the very latest in tools such as
+ gcc either from the current development branch or the gcc 3.2
from Red Hat Linux 8;
+ binutils preferrably from CVS, from H.J. Lu's latest release for
Linux, or from RHL 8.
Compiling glibc should proceed smoothly. But there are a number of
tests which fail, mostly because some functionality is missing in
glibc. Ignore those errors. It is only important that all tests in
nptl/ are passing. Run
make subdirs=nptl check
to run all thread tests.
This version features several improvements:
- all APIs are now implemented;
- fork handling has been improved; stacks in the child are freed;
atfork handlers are removed if they were registered from a module
which gets unloaded.
- pthread_tryjoin_np and pthread_timedjoin_np are implemented
- TSD handling corrected and optimized.
- many more tests which also test the underlying kernel implementation.
- the build infrastructure has been implemented so that the DSO and
archives are built in usable form and with correct named.
- libthread_db has been implemented. This is the library which is
needed by all program which need to get access to internals of
libpthread (mainly debuggers).
- the CPU clock functions are implemented
The white paper hasn't yet been updated. It's still available at
http://people.redhat.com/drepper/nptl-design.pdf
This release should be ready for some serious testing. I know it is
hard to compile which I why I'm looking into providing binary RPMs.
They can be used on non-critical systems. I'll only be able to
provide binaries for RHL8 based systems, though, and the kernel still
must be installed separately.
The next steps will include:
- write more tests and fix the bugs which are discovered this way
- update the white paper
- write and run more performance tests
- port to IA-64
Interested parties are once again invited to join the mailing we
created:
phil-list@redhat.com
Go to
https://listman.redhat.com/mailman/listinfo/phil-list
to subscribe, unsubscribe, or review the archive.

1
nptl/Banner Normal file
View File

@ -0,0 +1 @@
nptl 0.9 by Ulrich Drepper

259
nptl/ChangeLog Normal file
View File

@ -0,0 +1,259 @@
2002-11-26 Ulrich Drepper <drepper@redhat.com>
* allocatestack.c (queue_stack): Don't remove stack from list here.
Do it in the caller. Correct condition to prematurely terminate
loop to free stacks.
(__deallocate_stack): Remove stack from list here.
2002-11-26 Ulrich Drepper <drepper@redhat.com>
* Makefile (tests): Add tst-stack1.
* tst-stack1.c: New file.
* allocatestack.c (allocate_stack): Initialize the TCB on a user
provided stack.
* pthread_attr_getstack.c: Return bottom of the thread area.
2002-11-25 Ulrich Drepper <drepper@redhat.com>
* Makefile (libpthread-routines): Add pt-allocrtsig and
pthread_kill_other_threads.
* pt-allocrtsig.c: New file.
* pthread_kill_other_threads.c: New file.
* sysdeps/unix/sysv/linux/allocrtsig.c: Add additional aliases for
all three functions.
* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove
allocrtsig.
* sysdeps/unix/sysv/linux/Versions (libc:GLIBC_PRIVATE): Export
__libc_current_sigrtmin_private, __libc_current_sigrtmax_private,
and __libc_allocate_rtsig_private.
* Versions (libpthread): Export pthread_kill_other_threads_np,
__libc_current_sigrtmin, and __libc_current_sigrtmax.
2002-11-24 Ulrich Drepper <drepper@redhat.com>
* allocatestack.c (allocate_stack): stackaddr in attribute points to
the end of the stack. Adjust computations.
When mprotect call fails dequeue stack and free it.
* pthread_attr_setstack.c: Store top of the stack in stackaddr
attribute.
* pthread_getattr_np.c: Likewise.
* descr.h (IS_DETACHED): Add some more parenthesis to prevent
surprises.
2002-11-23 Ulrich Drepper <drepper@redhat.com>
* sysdeps/pthread/pthread.h (pthread_self): __THROW must come before
attribute definitions. Patch by Luca Barbieri <ldb@ldb.ods.org>.
2002-11-22 Ulrich Drepper <drepper@redhat.com>
* pthread_getspecific.c: Optimize access to first 2nd-level array.
* pthread_setspecific.c: Likewise.
2002-11-21 Ulrich Drepper <drepper@redhat.com>
* sysdeps/unix/sysv/linux/i386/createthread.c: Remove CLONE_ flags
definitions. Get them from the official place.
* sysdeps/unix/sysv/linux/i386/fork.c: Likewise.
* sysdeps/unix/sysv/linux/i386/createthread.c: Update CLONE_* flags.
Use new CLONE_ flags in clone() calls.
* sysdeps/unix/sysv/linux/fork.c: Use ARCH_FORK to actually fork.
* sysdeps/unix/sysv/linux/i386/fork.c: New file.
* Versions: Add pthread_* functions for libc.
* forward.c: New file.
* sysdeps/pthread/Makefile (libpthread-sysdeps_routines): Add
errno-loc.
* herrno.c: New file.
* res.c: New file.
* Makefile (libpthread-routines): Remove sem_post, sem_wait,
sem_trywait, and sem_timedwait. Add herrno and res.
* sem_init.c: Don't initialize lock and waiters members.
* sem_open.c: Likewise.
* sem_post.c: Removed.
* sem_wait.c: Removed.
* sem_trywait.c: Removed.
* sem_timedwait.c: Removed.
* sysdeps/unix/sysv/linux/i386/i486/lowlevelsem.S: Complete rewrite.
Includes full implementations of sem_post, sem_wait, sem_trywait,
and sem_timedwait.
* sysdeps/unix/sysv/linux/i386/lowlevelsem.h (lll_sem_post): Adjust
for new implementation.
* sysdeps/unix/sysv/linux/internaltypes.h (struct sem): Remove lock
and waiters fields.
* tst-sem3.c: Improve error message.
* tst-signal3.c: Likewise.
* init.c (__pthread_initialize_minimal): Use set_tid_address syscall
to tell the kernel about the termination futex and to initialize tid
member. Don't initialize main_thread.
* descr.h (struct pthread): Remove main_thread member.
* cancelllation.c (__do_cancel): Remove code handling main thread.
The main thread is not special anymore.
* allocatestack.c (__reclaim_stacks): Mark stacks as unused. Add
size of the stacks to stack_cache_actsize.
* pt-readv.c: Add missing "defined".
* pt-sigwait.c: Likewise.
* pt-writev.c: Likewise.
2002-11-09 Ulrich Drepper <drepper@redhat.com>
* Versions: Export __connect from libpthread.
Patch by Luca Barbieri <ldb@ldb.ods.org>.
* Makefile (libpthread-routines): Add pt-raise.
* sysdeps/unix/sysv/linux/raise.c: New file.
* sysdeps/unix/sysv/linux/pt-raise.c: New file.
* sysdeps/generic/pt-raise.c: New file.
* pthread_cond_init.c: Initialize all data elements of the condvar
structure. Patch by Luca Barbieri <ldb@ldb.ods.org>.
* pthread_attr_init.c: Actually implement 2.0 compatibility version.
* pthread_create.c: Likewise.
* Makefile (tests): Add tst-key1, tst-key2, tst-key3.
* tst-key1.c: New file.
* tst-key2.c: New file.
* tst-key3.c: New file.
* Versions: Export pthread_detach for version GLIBC_2.0.
Reported by Saurabh Desai <sdesai@austin.ibm.com>.
2002-11-08 Ulrich Drepper <drepper@redhat.com>
* pthread_key_create.c: Terminate search after an unused key was found.
Patch by Luca Barbieri <ldb@ldb.ods.org>.
* sysdeps/unix/sysv/linux/i386/pthread_once.S: Return zero.
Patch by Luca Barbieri <ldb@ldb.ods.org>.
2002-10-10 Ulrich Drepper <drepper@redhat.com>
* sysdeps/unix/sysv/linux/i386/i486/lowlevelsem.S: Use slow generic
dynamic lookup for errno in PIC.
* allocatestack.c (get_cached_stack): Rearrange code slightly to
release the stack lock as soon as possible.
Call _dl_allocate_tls_init for TCB from the cache to re-initialize
the static TLS block.
(allocate_stack): Call _dl_allocate_tls_init for user-provided stack.
* cancellation.c: Renamed from cancelation.c.
* Makefile: Adjust accordingly.
* pthreadP.h (CANCELLATION_P): Renamed from CANCELATION_P.
* cleanup_defer.c: Use CANCELLATION_P.
* pthread_testcancel.c: Likewise.
* descr.h: Fix spelling in comments.
* init.c: Likewise.
* pthread_getattr_np.c: Likewise.
* pthread_getschedparam.c: Likewise.
* pthread_setschedparam.c: Likewise.
* Versions: Likewise.
* pt-pselect.c: New file.
* Makefile (libpthread-routines): Add pt-pselect.
* Versions: Add pselect.
* tst-cancel4.c: New file.
* Makefile (tests): Add tst-cancel4.
2002-10-09 Ulrich Drepper <drepper@redhat.com>
* pthread_mutex_lock.c: Always record lock ownership.
* pthread_mutex_timedlock.c: Likewise.
* pthread_mutex_trylock.c: Likewise.
* pt-readv.c: New file.
* pt-writev.c: New file.
* pt-creat.c: New file.
* pt-msgrcv.c: New file.
* pt-msgsnd.c: New file.
* pt-poll.c: New file.
* pt-select.c: New file.
* pt-sigpause.c: New file.
* pt-sigsuspend.c: New file.
* pt-sigwait.c: New file.
* pt-sigwaitinfo.c: New file.
* pt-waitid.c: New file.
* Makefile (libpthread-routines): Add pt-readv, pt-writev, pt-creat,
pt-msgrcv, pt-msgsnd, pt-poll, pt-select, pt-sigpause, pt-sigsuspend,
pt-sigwait, pt-sigwaitinfo, and pt-waitid.
* Versions: Add all the new functions.
* tst-exit1.c: New file.
* Makefile (tests): Add tst-exit1.
* sem_timedwait.c: Minor optimization for more optimal fastpath.
2002-10-08 Ulrich Drepper <drepper@redhat.com>
* pt-fcntl.c: Only enable asynchronous cancellation for F_SETLKW.
* pthread_join.c: Enable asynchronous cancellation around lll_wait_tid
call. pthread_join is an official cancellation point.
* pthread_timedjoin.c: Likewise.
* pthread_cond_wait.c: Revert order in which internal lock are dropped
and the condvar's mutex are retrieved.
* pthread_cond_timedwait.c: Likewise.
Reported by dice@saros.East.Sun.COM.
2002-10-07 Ulrich Drepper <drepper@redhat.com>
* pthreadP.h: Cut out all type definitions and move them...
* sysdeps/unix/sysv/linux/internaltypes.h: ...here. New file.
* pthreadP.h: Include <internaltypes.h>.
* sysdeps/unix/sysv/linux/i386/lowlevelsem.h (lll_sem_post): Little
performance tweaks.
* sem_trywait.c: Shuffle #includes around to get right order.
* sem_timedwait.c: Likewise.
* sem_post.c: Likewise.
* sem_wait.c: Likewise.
* nptl 0.3 released.
* Makefile (tests): Add tst-signal3.
* tst-signal3.c: New file.
2002-10-05 Ulrich Drepper <drepper@redhat.com>
* sysdeps/unix/sysv/linux/i386/lowlevelsem.h: Tell the compiler that
the asms modify the sem object.
(__lll_sem_timedwait): Now takes struct sem* as first parameter.
* sysdeps/unix/sysv/linux/i386/bits/semaphore.h (sem_t): Don't expose
the actual members.
* pthreadP.h (struct sem): New type. Actual semaphore type.
* semaphoreP.h: Include pthreadP.h.
* sem_getvalue.c: Adjust to sem_t change.
* sem_init.c: Likewise.
* sem_open.c: Likewise.
* sem_post.c: Likewise.
* sem_timedwait.c: Likewise.
* sem_trywait.c: Likewise.
* sem_wait.c: Likewise.
2002-10-04 Ulrich Drepper <drepper@redhat.com>
* Makefile (tests): Add tst-basic2, tst-exec1, tst-exec3, tst-exec3.
* tst-basic2.c: New file.
* tst-exec1.c: New file.
* tst-exec2.c: New file.
* tst-exec3.c: New file.
* tst-fork1.c: Remove extra */.
* nptl 0.2 released. The API for IA-32 is complete.

49
nptl/DESIGN-barrier.txt Normal file
View File

@ -0,0 +1,49 @@
Barriers pseudocode
===================
int pthread_barrier_wait(barrier_t * barrier);
struct barrier_t {
unsigned int lock:
- internal mutex
unsigned int left;
- current barrier count, # of threads still needed.
unsigned int init_count;
- number of threads needed for the barrier to continue.
unsigned int curr_event;
- generation count
}
pthread_barrier_wait(barrier_t *barrier)
{
unsigned int event;
lll_lock(barrier->lock);
if (!--barrier->left) {
barrier->left = barrier->init_count;
barrier->curr_event++;
futex_wake(&barrier->curr_event, INT_MAX)
lll_unlock(barrier->lock);
return BARRIER_SERIAL_THREAD;
}
event = barrier->curr_event;
for (;;) {
lll_unlock(barrier->lock);
futex_wait(&barrier->curr_event, event)
lll_lock(barrier->lock);
if (event != barrier->curr_event)
break;
}
lll_unlock(barrier->lock);
return 0;
}

90
nptl/DESIGN-condvar.txt Normal file
View File

@ -0,0 +1,90 @@
Conditional Variable pseudocode.
================================
int pthread_cond_timedwait (pthread_cond_t *cv, pthread_mutex_t *mutex);
int pthread_cond_signal (pthread_cond_t *cv);
int pthread_cond_broadcast (pthread_cond_t *cv);
struct pthread_cond_t {
unsigned int lock:
internal mutex
unsigned int nr_wakers:
number of threads signalled to be woken up.
unsigned int nr_sleepers:
number of threads waiting for the cv.
}
#define ALL_THREADS (1 << (BITS_PER_LONG-1))
cond_wait_timeout(cv, mutex, timeout):
{
lll_lock(cv->lock);
mutex_unlock(mutex);
cv->nr_sleepers++;
for (;;) {
if (cv->nr_wakers) {
cv->nr_wakers--;
break;
}
val = cv->nr_wakers;
lll_unlock(cv->lock);
ret = FUTEX WAIT (cv->nr_wakers, val, timeout)
lll_lock(cv->lock);
if (ret == TIMEOUT)
break;
ret = 0;
}
if (!--cv->nr_sleepers)
cv->nr_wakers = 0; /* no memory of wakeups */
lll_unlock(cv->lock);
mutex_lock(mutex);
return ret;
}
cond_signal(cv)
{
int do_wakeup = 0;
lll_lock(cv->lock);
if (cv->nr_sleepers) {
if (!++cv->nr_wakers) /* overflow detection for the nutcase */
cv->nr_wakers = ALL_THREADS;
do_wakeup = 1;
}
lll_unlock(cv->lock);
if (do_wakeup)
FUTEX WAKE (cv->nr_wakers, 1)
}
cond_broadcast(cv)
{
int do_wakeup = 0;
lll_lock(cv->lock);
if (cv->nr_sleepers) {
cv->nr_wakers |= ALL_THREADS;
do_wakeup = 1;
}
lll_unlock(cv->lock);
if (do_wakeup)
FUTEX WAKE (cv->nr_wakers, ALL_THREADS);
}
weaknesses of the implementation:
it might generate spurious wakeups in the broadcast case, but those are
allowed by POSIX.

109
nptl/DESIGN-rwlock.txt Normal file
View File

@ -0,0 +1,109 @@
Reader Writer Locks pseudocode
==============================
pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
struct pthread_rwlock_t {
unsigned int lock:
- internal mutex
unsigned int writers_preferred;
- locking mode: 0 recursive, readers preferred
1 nonrecursive, writers preferred
unsigned int readers;
- number of read-only references various threads have
pthread_t writer;
- descriptor of the writer or 0
unsigned int readers_wakeup;
- 'all readers should wake up' futex.
unsigned int writer_wakeup;
- 'one writer should wake up' futex.
unsigned int nr_readers_queued;
- number of readers queued up.
unsigned int nr_writers_queued;
- number of writers queued up.
}
pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
{
lll_lock(rwlock->lock);
for (;;) {
if (!rwlock->writer && (!rwlock->nr_writers_queued ||
!rwlock->writers_preferred))
break;
rwlock->nr_readers_queued++;
lll_unlock(rwlock->lock);
futex_wait(&rwlock->readers_wakeup, 0)
lll_lock(rwlock->lock);
if (!--rwlock->nr_readers_queued)
rwlock->readers_wakeup = 0;
}
rwlock->readers++;
lll_unlock(rwlock->lock);
}
pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
{
int result = EBUSY;
lll_lock(rwlock->lock);
if (!rwlock->writer && (!rwlock->nr_writers_queued ||
!rwlock->writers_preferred))
rwlock->readers++;
lll_unlock(rwlock->lock);
return result;
}
pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
{
lll_lock(rwlock->lock);
for (;;) {
if (!rwlock->writer && !rwlock->readers)
break;
rwlock->nr_writers_queued++;
lll_unlock(rwlock->lock);
futex_wait(&rwlock->writer_wakeup, 0);
lll_lock(rwlock->lock);
rwlock->nr_writers_queued--;
rwlock->writer_wakeup = 0;
}
rwlock->writer = pthread_self();
lll_unlock(rwlock->lock);
}
pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
{
lll_lock(rwlock->lock);
if (rwlock->writer)
rwlock->writer = 0;
else
rwlock->readers--;
if (!rwlock->readers) {
if (rwlock->nr_writers_queued) {
rwlock->writer_wakeup = 1;
futex_wake(&rwlock->writer_wakeup, 1);
} else
if (rwlock->nr_readers_queued) {
rwlock->readers_wakeup = 1;
futex_wake(&rwlock->readers_wakeup, MAX_INT);
}
}
lll_unlock(rwlock->lock);
}

67
nptl/DESIGN-sem-old.txt Normal file
View File

@ -0,0 +1,67 @@
Semaphores pseudocode
==============================
int sem_wait(sem_t * sem);
int sem_trywait(sem_t * sem);
int sem_post(sem_t * sem);
int sem_getvalue(sem_t * sem, int * sval);
struct sem_t {
unsigned int lock:
- internal mutex
unsigned int count;
- current semaphore count, also used as a futex
unsigned int waiters;
- number of threads queued in sem_wait().
}
sem_wait(sem_t *sem)
{
lll_lock(sem->lock);
for (;;) {
if (sem->count)
break;
sem->waiters++;
lll_unlock(sem->lock);
futex_wait(&sem->count, 0)
lll_lock(sem->lock);
sem->waiters--;
}
sem->count--;
lll_unlock(sem->lock);
}
sem_post(sem_t *sem)
{
lll_lock(sem->lock);
sem->count++;
if (sem->waiters)
futex_wake(&sem->count, sem->count);
lll_unlock(sem->lock);
}
sem_trywait(sem_t *sem)
{
lll_lock(sem->lock);
if (sem->count) {
sem->count--;
lll_unlock(sem->lock);
return 0;
} else {
lll_unlock(sem->lock);
return -EAGAIN;
}
}
sem_getvalue(sem_t *sem, int *sval)
{
*sval = sem->count;
read_barrier();
}

45
nptl/DESIGN-sem.txt Normal file
View File

@ -0,0 +1,45 @@
Semaphores pseudocode
==============================
int sem_wait(sem_t * sem);
int sem_trywait(sem_t * sem);
int sem_post(sem_t * sem);
int sem_getvalue(sem_t * sem, int * sval);
struct sem_t {
unsigned int count;
- current semaphore count, also used as a futex
}
sem_wait(sem_t *sem)
{
for (;;) {
if (atomic_decrement_if_positive(sem->count))
break;
futex_wait(&sem->count, 0)
}
}
sem_post(sem_t *sem)
{
n = atomic_increment(sem->count);
futex_wake(&sem->count, n);
}
sem_trywait(sem_t *sem)
{
if (atomic_decrement_if_positive(sem->count)) {
return 0;
} else {
return EAGAIN;
}
}
sem_getvalue(sem_t *sem, int *sval)
{
*sval = sem->count;
read_barrier();
}

30
nptl/Makeconfig Normal file
View File

@ -0,0 +1,30 @@
# Copyright (C) 2002 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.
# Makeconfig fragment for linuxthreads add-on.
# This gets included at the end of the main glibc Makeconfig.
have-thread-library = yes
shared-thread-library = $(common-objpfx)nptl/libpthread.so \
$(common-objpfx)nptl/libpthread_nonshared.a
static-thread-library = $(common-objpfx)nptl/libpthread.a
bounded-thread-library = $(common-objpfx)nptl/libpthread_b.a
rpath-dirs += nptl

226
nptl/Makefile Normal file
View File

@ -0,0 +1,226 @@
# Copyright (C) 2002 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.
#
# Sub-makefile for NPTL portion of the library.
#
subdir := nptl
nptl-version := $(shell sed -n 's/^.*$(subdir) \([0-9.]*\).*$$/\1/p' Banner)
headers := pthread.h semaphore.h
extra-libs := libpthread
extra-libs-others := $(extra-libs)
routines = alloca_cutoff forward
shared-only-routines = forward
libpthread-routines = init events \
pthread_create pthread_exit pthread_detach \
pthread_join pthread_tryjoin pthread_timedjoin \
pthread_self pthread_equal pthread_yield \
pthread_getconcurrency pthread_setconcurrency \
pthread_getschedparam pthread_setschedparam \
pthread_attr_init pthread_attr_destroy \
pthread_attr_getdetachstate pthread_attr_setdetachstate \
pthread_attr_getguardsize pthread_attr_setguardsize \
pthread_attr_getschedparam pthread_attr_setschedparam \
pthread_attr_getschedpolicy pthread_attr_setschedpolicy \
pthread_attr_getinheritsched \
pthread_attr_setinheritsched \
pthread_attr_getscope pthread_attr_setscope \
pthread_attr_getstackaddr pthread_attr_setstackaddr \
pthread_attr_getstacksize pthread_attr_setstacksize \
pthread_attr_getstack pthread_attr_setstack \
pthread_getattr_np \
pthread_mutex_init pthread_mutex_destroy \
pthread_mutex_lock pthread_mutex_trylock \
pthread_mutex_timedlock pthread_mutex_unlock \
pthread_mutexattr_init pthread_mutexattr_destroy \
pthread_mutexattr_getpshared \
pthread_mutexattr_setpshared \
pthread_mutexattr_gettype pthread_mutexattr_settype \
pthread_rwlock_init pthread_rwlock_destroy \
pthread_rwlock_tryrdlock pthread_rwlock_trywrlock \
pthread_rwlockattr_init pthread_rwlockattr_destroy \
pthread_rwlockattr_getpshared \
pthread_rwlockattr_setpshared \
pthread_rwlockattr_getkind_np \
pthread_rwlockattr_setkind_np \
pthread_cond_init pthread_cond_destroy \
pthread_cond_wait pthread_cond_timedwait \
pthread_cond_signal pthread_cond_broadcast \
pthread_condattr_init pthread_condattr_destroy \
pthread_condattr_getpshared pthread_condattr_setpshared \
pthread_spin_init pthread_spin_destroy \
pthread_spin_lock pthread_spin_trylock \
pthread_spin_unlock \
pthread_barrier_init pthread_barrier_destroy \
pthread_barrier_wait \
pthread_barrierattr_init pthread_barrierattr_destroy \
pthread_barrierattr_getpshared \
pthread_barrierattr_setpshared \
pthread_key_create pthread_key_delete \
pthread_getspecific pthread_setspecific \
pthread_sigmask pthread_kill \
pthread_cancel pthread_testcancel \
pthread_setcancelstate pthread_setcanceltype \
pthread_once \
old_pthread_atfork\
pthread_getcpuclockid \
pthread_clock_gettime pthread_clock_settime \
sem_init sem_destroy \
sem_open sem_close sem_unlink \
sem_getvalue \
cleanup cleanup_defer \
pt-longjmp \
cancellation \
lowlevellock lowlevelmutex lowlevelcond lowlevelrwlock \
lowlevelsem \
pt-vfork \
pt-write pt-read pt-close pt-fcntl pt-accept pt-connect \
pt-recv pt-recvfrom pt-recvmsg pt-send pt-sendmsg \
pt-sendto pt-fsync pt-lseek pt-lseek64 pt-msync \
pt-nanosleep pt-open pt-open64 pt-pause pt-pread \
pt-pread64 pt-pwrite pt-pwrite64 pt-tcdrain pt-system \
pt-wait pt-waitpid pt-readv pt-writev pt-creat \
pt-msgrcv pt-msgsnd pt-poll pt-select pt-sigpause \
pt-sigsuspend pt-sigwait pt-sigwaitinfo pt-waitid \
pt-pselect pt-raise \
flockfile ftrylockfile funlockfile \
sigaction \
herrno res pt-allocrtsig \
pthread_kill_other_threads
libpthread-nonshared = pthread_atfork
tests = tst-mutex1 tst-mutex2 tst-mutex3 tst-mutex4 tst-mutex5 tst-mutex6 \
tst-mutex7 \
tst-spin1 tst-spin2 tst-spin3 \
tst-cond1 tst-cond2 tst-cond3 tst-cond4 tst-cond5 tst-cond6 \
tst-rwlock1 tst-rwlock2 tst-rwlock3 tst-rwlock4 tst-rwlock5 \
tst-rwlock6 tst-rwlock7 \
tst-once1 tst-once2 \
tst-key1 tst-key2 tst-key3 \
tst-sem1 tst-sem2 tst-sem3 tst-sem4 tst-sem5 \
tst-barrier1 tst-barrier2 tst-barrier3 \
tst-basic1 tst-basic2 \
tst-join1 tst-join2 tst-join3 \
tst-tsd1 tst-tsd2 \
tst-fork1 \
tst-atfork1 \
tst-cancel1 tst-cancel2 tst-cancel3 tst-cancel4 \
tst-flock1 tst-flock2 \
tst-signal1 tst-signal2 tst-signal3 \
tst-exec1 tst-exec2 tst-exec3 \
tst-exit1 \
tst-stack1 \
tst-unload
LDFLAGS-pthread.so = -Wl,--enable-new-dtags,-z,nodelete,-z,initfirst
include ../Makeconfig
ifeq ($(build-shared),yes)
others: $(objpfx)libpthread_nonshared.a
endif
$(objpfx)libpthread_nonshared.a: $(addprefix $(objpfx),$(addsuffix .os,$(libpthread-nonshared)))
$(AR) $(ARFLAGS) $@ $^
ifeq ($(build-shared),yes)
extra-objs += crti.o
omit-deps += crti
CFLAGS-pt-initfini.s = -g0 -fPIC -fno-inline-functions
endif
include ../Rules
# What we install as libc.so for programs to link against is in fact a
# link script. It contains references for the various libraries we need.
# The libc.so object is not complete since some functions are only defined
# in libc_nonshared.a.
# We need to use absolute paths since otherwise local copies (if they exist)
# of the files are taken by the linker.
install: $(inst_libdir)/libpthread.so
$(inst_libdir)/libpthread.so: $(objpfx)libpthread.so$(libpthread.so-version) \
$(inst_libdir)/$(patsubst %,$(libtype.oS),\
$(libprefix)pthread) \
$(+force)
(echo '/* GNU ld script';\
echo ' Use the shared library, but some functions are only in';\
echo ' the static library, so try that secondarily. */';\
echo 'GROUP ( $(slibdir)/libpthread.so$(libpthread.so-version)' \
'$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)pthread)'\
')' \
) > $@.new
mv -f $@.new $@
$(inst_libdir)/libpthread_nonshared.a: $(objpfx)libpthread_nonshared.a
$(do-install)
CFLAGS-tst-unload.c += -DPREFIX=\"$(objpfx)\"
extra-B-pthread.so = -B$(common-objpfx)linuxthreads/
$(objpfx)libpthread.so: $(objpfx)crti.o
$(objpfx)libpthread.so: +preinit += $(objpfx)crti.o
# Depend on libc.so so a DT_NEEDED is generated in the shared objects.
# This ensures they will load libc.so for needed symbols if loaded by
# a statically-linked program that hasn't already loaded it.
$(objpfx)libpthread.so: $(common-objpfx)libc.so \
$(common-objpfx)libc_nonshared.a
# Make sure we link with the thread library.
ifeq ($(build-shared),yes)
$(addprefix $(objpfx), \
$(filter-out $(tests-static), \
$(tests) $(test-srcs))): $(objpfx)libpthread.so \
$(objpfx)libpthread_nonshared.a
$(objpfx)tst-unload: $(common-objpfx)dlfcn/libdl.so
else
$(addprefix $(objpfx),$(tests) $(test-srcs)): $(objpfx)libpthread.a
endif
ifeq ($(build-shared),yes)
vpath pt-initfini.c $(full_config_sysdirs)
$(objpfx)pt-initfini.s: pt-initfini.c
$(compile.c) -S $(CFLAGS-pt-initfini.s) -finhibit-size-directive \
$(patsubst -f%,-fno-%,$(exceptions)) -o $@
# We only have one kind of startup code files. Static binaries and
# shared libraries are build using the PIC version.
$(objpfx)crti.S: $(objpfx)pt-initfini.s
sed -n -e '1,/@HEADER_ENDS/p' \
-e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
-e '/@TRAILER_BEGINS/,$$p' $< > $@
$(objpfx)defs.h: $(objpfx)pt-initfini.s
sed -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
$(AWK) -f ../csu/defs.awk > $@
$(objpfx)crti.o: $(objpfx)crti.S $(objpfx)defs.h
$(compile.S) -g0 $(ASFLAGS-.os) -o $@
generated += crti.S defs.h pt-initfini.s
endif

24
nptl/TODO Normal file
View File

@ -0,0 +1,24 @@
- we should probably extend pthread_mutexattr_t with a field to create a
single linked list of all instances. This requires changing the
pthread_mutexattr_* functions.
- a new attribute for mutexes: number of times we spin before calling
sys_futex
- in case a thread calls 'fork' the stacks of all the other threads in
the child process are currently list. Instead they should be recovered
and added to the stack cache. This can be done by adding another global
list (maybe one per cluster) which lists all running threads and which
is processed by the child branch of fork. All the stacks are simply
added to the stack cache.
- test with threaded process terminating and semadj (?) being applied
only after all threads are gone
- raise sends the signal to calling thread or process?

26
nptl/TODO-kernel Normal file
View File

@ -0,0 +1,26 @@
- setuid/setgid must effect process
+ test syscalls (getuid) afterwards
+ test core file content
+ use UID/GID in access(2), chmod(2), chown(2), link(2)
- nice level is process property
- process file creation mask (mkdir, mkfifo, open, creat) after umask call
- getppid(() must return process ID of parent process of the thread
group leader
+ test syscall
+ test core file content (psinfo)
- rlimit should be process-wide and SIGXCPU should be sent if all threads
together exceed the limit
- getrusage() must return resource utilization for the process
- sigaltstack must be per-thread (???)
I've an interpretation request outstanding
- the scheduler must be thread group-aware, i.e., it has to give time to
the thread group not proportional to the number of threads.

205
nptl/Versions Normal file
View File

@ -0,0 +1,205 @@
libc {
GLIBC_2.0 {
pthread_attr_destroy;
pthread_attr_getdetachstate; pthread_attr_setdetachstate;
pthread_attr_getinheritsched; pthread_attr_setinheritsched;
pthread_attr_getschedparam; pthread_attr_setschedparam;
pthread_attr_getschedpolicy; pthread_attr_setschedpolicy;
pthread_attr_getscope; pthread_attr_setscope;
pthread_condattr_destroy; pthread_condattr_init;
pthread_cond_broadcast; pthread_cond_destroy;
pthread_cond_init; pthread_cond_signal; pthread_cond_wait;
pthread_equal; pthread_exit;
pthread_getschedparam; pthread_setschedparam;
pthread_mutex_destroy; pthread_mutex_init;
pthread_mutex_lock; pthread_mutex_unlock;
pthread_self;
pthread_setcancelstate; pthread_setcanceltype;
}
GLIBC_2.1 {
pthread_attr_init;
}
}
libpthread {
GLIBC_2.0 {
pthread_create; pthread_join; pthread_self; pthread_equal;
pthread_exit; pthread_detach;
pthread_getschedparam; pthread_setschedparam;
pthread_attr_init; pthread_attr_destroy;
pthread_attr_getdetachstate; pthread_attr_setdetachstate;
pthread_attr_getschedparam; pthread_attr_setschedparam;
pthread_attr_getschedpolicy; pthread_attr_setschedpolicy;
pthread_attr_getinheritsched; pthread_attr_setinheritsched;
pthread_attr_getscope; pthread_attr_setscope;
pthread_mutex_init; pthread_mutex_destroy;
pthread_mutex_lock; pthread_mutex_trylock; pthread_mutex_unlock;
pthread_mutexattr_init; pthread_mutexattr_destroy;
pthread_cond_init; pthread_cond_destroy;
pthread_cond_wait; pthread_cond_timedwait;
pthread_cond_signal; pthread_cond_broadcast;
pthread_condattr_destroy; pthread_condattr_init;
pthread_cancel; pthread_testcancel;
pthread_setcancelstate; pthread_setcanceltype;
pthread_sigmask; pthread_kill;
pthread_key_create; pthread_key_delete;
pthread_getspecific; pthread_setspecific;
pthread_once;
pthread_atfork;
flockfile; funlockfile; ftrylockfile;
# Non-standard POSIX1.x functions.
pthread_mutexattr_getkind_np; pthread_mutexattr_setkind_np;
# Protected names for functions used in other shared objects.
__pthread_mutex_init; __pthread_mutex_destroy;
__pthread_mutex_lock; __pthread_mutex_trylock; __pthread_mutex_unlock;
__pthread_mutexattr_init; __pthread_mutexattr_destroy;
__pthread_mutexattr_settype;
__pthread_key_create; __pthread_getspecific; __pthread_setspecific;
__pthread_once; __pthread_atfork;
_IO_flockfile; _IO_ftrylockfile; _IO_funlockfile;
# Hidden entry point (through macros).
#_pthread_cleanup_pop; _pthread_cleanup_pop_restore; _pthread_cleanup_push;
#_pthread_cleanup_push_defer;
# Semaphores.
sem_destroy; sem_getvalue; sem_init; sem_post; sem_trywait; sem_wait;
# Special fork handling.
fork; __fork; vfork;
# Cancellation points.
close; __close; fcntl; __fcntl; read; __read; write; __write; accept;
connect; __connect; recv; recvfrom; recvmsg; send; __send; sendmsg; sendto;
fsync; lseek; __lseek; msync; nanosleep; open; __open; pause; tcdrain;
system; wait; __wait; waitpid;
# Hidden entry point (through macros).
_pthread_cleanup_push; _pthread_cleanup_pop;
_pthread_cleanup_push_defer; _pthread_cleanup_pop_restore;
pthread_kill_other_threads_np;
# The error functions.
__errno_location; __h_errno_location;
# Functions which previously have been overwritten.
sigwait; sigaction; __sigaction; _exit; _Exit; longjmp; siglongjmp;
raise;
}
GLIBC_2.1 {
pthread_create;
pthread_attr_init;
pthread_attr_getguardsize; pthread_attr_setguardsize;
pthread_attr_getstackaddr; pthread_attr_setstackaddr;
pthread_attr_getstacksize; pthread_attr_setstacksize;
pthread_mutexattr_gettype; pthread_mutexattr_settype;
pthread_rwlock_init; pthread_rwlock_destroy;
pthread_rwlock_rdlock; pthread_rwlock_wrlock; pthread_rwlock_unlock;
pthread_rwlock_tryrdlock; pthread_rwlock_trywrlock;
__pthread_rwlock_init; __pthread_rwlock_destroy;
__pthread_rwlock_rdlock; __pthread_rwlock_wrlock; __pthread_rwlock_unlock;
__pthread_rwlock_tryrdlock; __pthread_rwlock_trywrlock;
pthread_rwlockattr_init; pthread_rwlockattr_destroy;
pthread_rwlockattr_getpshared; pthread_rwlockattr_setpshared;
pthread_rwlockattr_getkind_np; pthread_rwlockattr_setkind_np;
pthread_getconcurrency; pthread_setconcurrency;
# Semaphores.
sem_destroy; sem_getvalue; sem_init; sem_post; sem_trywait; sem_wait;
__libc_current_sigrtmin; __libc_current_sigrtmax;
__libc_allocate_rtsig;
}
GLIBC_2.1.1 {
sem_close; sem_open; sem_unlink;
}
GLIBC_2.1.2 {
__vfork;
}
GLIBC_2.2 {
pthread_mutexattr_getpshared; pthread_mutexattr_setpshared;
pthread_condattr_getpshared; pthread_condattr_setpshared;
# New functions from IEEE Std. 1003.1-2001.
pthread_mutex_timedlock;
pthread_rwlock_timedrdlock; pthread_rwlock_timedwrlock;
pthread_attr_getstack; pthread_attr_setstack;
pthread_spin_destroy; pthread_spin_init; pthread_spin_lock;
pthread_spin_trylock; pthread_spin_unlock;
pthread_barrier_init; pthread_barrier_destroy; pthread_barrier_wait;
pthread_barrierattr_destroy; pthread_barrierattr_init;
pthread_barrierattr_getpshared; pthread_barrierattr_setpshared;
sem_timedwait;
pthread_yield;
pthread_getcpuclockid;
# Cancellation points.
lseek64; open64; __open64; pread; pread64; __pread64; pwrite; pwrite64;
__pwrite64;
# Names used internally.
__pthread_rwlock_init; __pthread_rwlock_destroy;
__pthread_rwlock_rdlock; __pthread_rwlock_tryrdlock;
__pthread_rwlock_wrlock; __pthread_rwlock_trywrlock;
__pthread_rwlock_unlock;
__res_state;
}
GLIBC_2.2.3 {
# Extensions.
pthread_getattr_np;
}
GLIBC_2.2.6 {
# Cancellation wrapper
__nanosleep;
}
# XXX Adjust number for final release.
GLIBC_2.3.1 {
# Proposed API extensions.
pthread_tryjoin_np; pthread_timedjoin_np;
creat; poll; pselect; readv; select; sigpause; sigsuspend; sigwait;
sigwaitinfo; waitid; writev;
}
GLIBC_PRIVATE {
__pthread_initialize_minimal; __pthread_cleanup_upto;
__pthread_clock_gettime; __pthread_clock_settime;
}
}

36
nptl/alloca_cutoff.c Normal file
View File

@ -0,0 +1,36 @@
/* Determine whether block of given size can be allocated on the stack or not.
Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <alloca.h>
#include <stdlib.h>
#include <sys/param.h>
#include <pthreadP.h>
int
__libc_alloca_cutoff (size_t size)
{
return size <= (MIN (__MAX_ALLOCA_CUTOFF,
THREAD_GETMEM (THREAD_SELF, stackblock_size) / 4
/* The main thread, before the thread library is
initialized, has zero in the stackblock_size
element. Since it is the main thread we can
assume the maximum available stack space. */
?: __MAX_ALLOCA_CUTOFF * 4));
}

507
nptl/allocatestack.c Normal file
View File

@ -0,0 +1,507 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/param.h>
#include <tls.h>
/* Most architectures have exactly one stack pointer. Some have more. */
#define STACK_VARIABLES void *stackaddr
/* How to pass the values to the 'create_thread' function. */
#define STACK_VARIABLES_ARGS stackaddr
/* How to declare function which gets there parameters. */
#define STACK_VARIABLES_PARMS void *stackaddr
/* Default alignment of stack. */
#ifndef STACK_ALIGN
# define STACK_ALIGN __alignof__ (long double)
#endif
/* Default value for minimal stack size after allocating thread
descriptor and guard. */
#ifndef MINIMAL_REST_STACK
# define MINIMAL_REST_STACK 4096
#endif
/* Cache handling for not-yet free stacks. */
/* Maximum size in kB of cache. */
static size_t stack_cache_maxsize = 40 * 1024 * 1024; /* 40MiBi by default. */
static size_t stack_cache_actsize;
/* Mutex protecting this variable. */
static lll_lock_t stack_cache_lock = LLL_LOCK_INITIALIZER;
/* List of queued stack frames. */
static LIST_HEAD (stack_cache);
/* List of the stacks in use. */
static LIST_HEAD (stack_used);
/* List of the threads with user provided stacks in use. */
LIST_HEAD (__stack_user);
/* Number of threads running. */
static unsigned int nptl_nthreads = 1;
/* Check whether the stack is still used or not. */
#define FREE_P(descr) ((descr)->tid == 0)
/* We create a double linked list of all cache entries. Double linked
because this allows removing entries from the end. */
/* Get a stack frame from the cache. We have to match by size since
some blocks might be too small or far too large. */
static struct pthread *
get_cached_stack (size_t *sizep, void **memp)
{
size_t size = *sizep;
struct pthread *result = NULL;
list_t *entry;
lll_lock (stack_cache_lock);
/* Search the cache for a matching entry. We search for the
smallest stack which has at least the required size. Note that
in normal situations the size of all allocated stacks is the
same. As the very least there are only a few different sizes.
Therefore this loop will exit early most of the time with an
exact match. */
list_for_each (entry, &stack_cache)
{
struct pthread *curr;
curr = list_entry(entry, struct pthread, header.data.list);
if (FREE_P (curr) && curr->stackblock_size >= size)
{
if (curr->stackblock_size == size)
{
result = curr;
break;
}
if (result->stackblock_size > curr->stackblock_size)
result = curr;
}
}
if (__builtin_expect (result == NULL, 0)
/* Make sure the size difference is not too excessive. In that
case we do not use the block. */
|| __builtin_expect (result->stackblock_size > 4 * size, 0))
{
/* Release the lock. */
lll_unlock (stack_cache_lock);
return NULL;
}
/* Dequeue the entry. */
list_del (&result->header.data.list);
/* And add to the list of stacks in use. */
list_add (&result->header.data.list, &stack_used);
/* One more thread. */
++nptl_nthreads;
/* And decrease the cache size. */
stack_cache_actsize -= result->stackblock_size;
/* Release the lock early. */
lll_unlock (stack_cache_lock);
*sizep = result->stackblock_size;
*memp = result->stackblock;
/* Cancellation handling is back to the default. */
result->cancelhandling = 0;
result->cleanup = NULL;
/* No pending event. */
result->nextevent = NULL;
/* Clear the DTV. */
dtv_t *dtv = GET_DTV (result);
memset (dtv, '\0', (dtv[-1].counter + 1) * sizeof (dtv_t));
/* Re-initialize the TLS. */
return _dl_allocate_tls_init (result);
}
/* Add a stack frame which is not used anymore to the stack. Must be
called with the cache lock held. */
static void
queue_stack (struct pthread *stack)
{
/* We unconditionally add the stack to the list. The memory may
still be in use but it will not be reused until the kernel marks
the stack as not used anymore. */
list_add (&stack->header.data.list, &stack_cache);
stack_cache_actsize += stack->stackblock_size;
if (__builtin_expect (stack_cache_actsize > stack_cache_maxsize, 0))
{
/* We reduce the size of the cache. Remove the last entries
until the size is below the limit. */
list_t *entry;
list_t *prev;
/* Search from the end of the list. */
list_for_each_prev_safe (entry, prev, &stack_cache)
{
struct pthread *curr;
curr = list_entry(entry, struct pthread, header.data.list);
if (FREE_P (curr))
{
/* Unlink the block. */
list_del (entry);
/* Account for the freed memory. */
stack_cache_actsize -= curr->stackblock_size;
/* Free the memory associated with the ELF TLS. */
_dl_deallocate_tls (curr, false);
/* Remove this block. This should never fail. If it
does something is really wrong. */
if (munmap (curr->stackblock, curr->stackblock_size) != 0)
abort ();
/* Maybe we have freed enough. */
if (stack_cache_actsize <= stack_cache_maxsize)
break;
}
}
}
}
static int
allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
void **stack)
{
struct pthread *pd;
size_t size;
size_t pagesize = __sysconf (_SC_PAGESIZE);
assert (attr != NULL);
assert (powerof2 (pagesize));
assert (TCB_ALIGNMENT >= STACK_ALIGN);
/* Get the stack size from the attribute if it is set. Otherwise we
use the default we determined at start time. */
size = attr->stacksize ?: __default_stacksize;
/* Get memory for the stack. */
if (__builtin_expect (attr->flags & ATTR_FLAG_STACKADDR, 0))
{
uintptr_t adj;
/* If the user also specified the size of the stack make sure it
is large enough. */
if (attr->stacksize != 0
&& attr->stacksize < (__static_tls_size + MINIMAL_REST_STACK))
return EINVAL;
/* Adjust stack size for alignment of the TLS block. */
adj = ((uintptr_t) attr->stackaddr) & (__static_tls_align - 1);
assert (size > adj);
/* The user provided some memory. Let's hope it matches the
size... We do not allocate guard pages if the user provided
the stack. It is the user's responsibility to do this if it
is wanted. */
pd = (struct pthread *) (((uintptr_t) attr->stackaddr - adj)
& ~(__alignof (struct pthread) - 1)) - 1;
/* The user provided stack memory need not be cleared. */
memset (pd, '\0', sizeof (struct pthread));
/* The first TSD block is included in the TCB. */
pd->specific[0] = pd->specific_1stblock;
/* Initialize the lock. */
pd->lock = LLL_LOCK_INITIALIZER;
/* Remember the stack-related values. Signal that this stack
must not be put into the stack cache. */
pd->stackblock = (char *) attr->stackaddr - size;
pd->stackblock_size = size - adj;
/* This is a user-provided stack. */
pd->user_stack = true;
/* Allocate the DTV for this thread. */
if (_dl_allocate_tls (pd) == NULL)
/* Something went wrong. */
return errno;
lll_lock (stack_cache_lock);
/* And add to the list of stacks in use. */
list_add (&pd->header.data.list, &__stack_user);
/* One more thread. */
++nptl_nthreads;
lll_unlock (stack_cache_lock);
}
else
{
/* Allocate some anonymous memory. If possible use the
cache. */
size_t guardsize;
size_t reqsize;
void *mem;
/* Adjust the stack size for alignment. */
size &= ~(__static_tls_align - 1);
assert (size != 0);
/* Make sure the size of the stack is enough for the guard and
eventually the thread descriptor. */
guardsize = (attr->guardsize + pagesize - 1) & ~(pagesize - 1);
if (__builtin_expect (size < (guardsize + __static_tls_size
+ MINIMAL_REST_STACK), 0))
/* The stack is too small (or the guard too large). */
return EINVAL;
reqsize = size;
pd = get_cached_stack (&size, &mem);
if (pd == NULL)
{
mem = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (__builtin_expect (mem == MAP_FAILED, 0))
return errno;
/* 'size' is guaranteed to be greater than zero. So we can
never get a NULL pointer back from MMAP. */
assert (mem != NULL);
/* Place the thread descriptor at the end of the stack. */
pd = (struct pthread *) ((char *) mem + size) - 1;
/* Remember the stack-related values. */
pd->stackblock = mem;
pd->stackblock_size = size;
/* We allocated the first block thread-specific data array.
This address will not change for the lifetime of this
descriptor. */
pd->specific[0] = pd->specific_1stblock;
/* Initialize the lock. */
pd->lock = LLL_LOCK_INITIALIZER;
/* Allocate the DTV for this thread. */
if (_dl_allocate_tls (pd) == NULL)
{
/* Something went wrong. */
int err = errno;
/* Free the stack memory we just allocated. */
munmap (mem, size);
return err;
}
lll_lock (stack_cache_lock);
/* And add to the list of stacks in use. */
list_add (&pd->header.data.list, &stack_used);
/* One more thread. */
++nptl_nthreads;
lll_unlock (stack_cache_lock);
/* Note that all of the stack and the thread descriptor is
zeroed. This means we do not have to initialize fields
with initial value zero. This is specifically true for
the 'tid' field which is always set back to zero once the
stack is not used anymore and for the 'guardsize' field
which will be read next. */
}
/* Create or resize the guard area if necessary. */
if (__builtin_expect (guardsize > pd->guardsize, 0))
{
if (mprotect (mem, guardsize, PROT_NONE) != 0)
{
int err;
mprot_error:
err = errno;
lll_lock (stack_cache_lock);
/* Remove the thread from the list. */
list_del (&pd->header.data.list);
/* The thread is gone. */
--nptl_nthreads;
lll_unlock (stack_cache_lock);
/* Free the memory regardless of whether the size of the
cache is over the limit or not. If this piece of
memory caused problems we better do not use it
anymore. Uh, and we ignore possible errors. There
is nothing we could do. */
(void) munmap (mem, size);
return err;
}
pd->guardsize = guardsize;
}
else if (__builtin_expect (pd->guardsize - guardsize > size - reqsize,
0))
{
/* The old guard area is too large. */
if (mprotect ((char *) mem + guardsize,
pd->guardsize - guardsize,
PROT_READ | PROT_WRITE | PROT_EXEC) != 0)
goto mprot_error;
pd->guardsize = guardsize;
}
}
/* We place the thread descriptor at the end of the stack. */
*pdp = pd;
#if TLS_TCB_AT_TP
/* The stack begin before the TCB and the static TLS block. */
*stack = ((char *) (pd + 1) - __static_tls_size);
#else
# error "Implement me"
#endif
return 0;
}
/* This is how the function is called. We do it this way to allow
other variants of the function to have more parameters. */
#define ALLOCATE_STACK(attr, pd) allocate_stack (attr, pd, &stackaddr)
void
__deallocate_stack (struct pthread *pd)
{
lll_lock (stack_cache_lock);
/* Remove the thread from the list of threads with user defined
stacks. */
list_del (&pd->header.data.list);
/* Not much to do. Just free the mmap()ed memory. Note that we do
not reset the 'used' flag in the 'tid' field. This is done by
the kernel. If no thread has been created yet this field is
still zero. */
if (__builtin_expect (! pd->user_stack, 1))
(void) queue_stack (pd);
else
/* Free the memory associated with the ELF TLS. */
_dl_deallocate_tls (pd, false);
/* One less thread. */
--nptl_nthreads;
lll_unlock (stack_cache_lock);
}
/* In case of a fork() call the memory allocation in the child will be
the same but only one thread is running. All stacks except that of
the one running thread are not used anymore. We have to recycle
them. */
void
__reclaim_stacks (void)
{
struct pthread *self = (struct pthread *) THREAD_SELF;
/* No locking necessary. The caller is the only stack in use. */
/* Mark all stacks except the still running one as free. */
list_t *runp;
list_for_each (runp, &stack_used)
{
struct pthread *curp;
curp = list_entry (runp, struct pthread, header.data.list);
if (curp != self)
{
/* This marks the stack as free. */
curp->tid = 0;
/* Account for the size of the stack. */
stack_cache_actsize += curp->stackblock_size;
}
}
/* Add the stack of all running threads to the cache. */
list_splice (&stack_used, &stack_cache);
/* Remove the entry for the current thread to from the cache list
and add it to the list of running threads. Which of the two
lists is decided by the user_stack flag. */
list_del (&self->header.data.list);
/* Re-initialize the lists for all the threads. */
INIT_LIST_HEAD (&stack_used);
INIT_LIST_HEAD (&__stack_user);
if (__builtin_expect (THREAD_GETMEM (self, user_stack), 0))
list_add (&self->header.data.list, &__stack_user);
else
list_add (&self->header.data.list, &stack_used);
/* There is one thread running. */
nptl_nthreads = 1;
/* Initialize the lock. */
stack_cache_lock = LLL_LOCK_INITIALIZER;
}

109
nptl/atomic.h Normal file
View File

@ -0,0 +1,109 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#ifndef _ATOMIC_H
#define _ATOMIC_H 1
#include <stdlib.h>
#include <bits/atomic.h>
#ifndef atomic_compare_and_exchange_acq
# define atomic_compare_and_exchange_acq(mem, newval, oldval) \
({ __typeof (__arch_compare_and_exchange_8_acq (mem, newval, oldval)) \
__result; \
if (sizeof (*mem) == 1) \
__result = __arch_compare_and_exchange_8_acq (mem, newval, oldval); \
else if (sizeof (*mem) == 2) \
__result = __arch_compare_and_exchange_16_acq (mem, newval, oldval); \
else if (sizeof (*mem) == 4) \
__result = __arch_compare_and_exchange_32_acq (mem, newval, oldval); \
else if (sizeof (*mem) == 8) \
__result = __arch_compare_and_exchange_64_acq (mem, newval, oldval); \
else \
abort (); \
__result; })
#endif
#ifndef atomic_compare_and_exchange_rel
# define atomic_compare_and_exchange_rel(mem, oldval, newval) \
compare_and_exchange_acq (mem, oldval, newval)
#endif
#ifndef atomic_exchange_and_add
# define atomic_exchange_and_add(mem, value) \
({ __typeof (*mem) __oldval; \
__typeof (mem) __memp = (mem); \
__typeof (*mem) __value = (value); \
\
do \
__oldval = (*__memp); \
while (compare_and_exchange_acq (__memp, __oldval + __value, __oldval)); \
\
__value; })
#endif
#ifndef atomic_add
# define atomic_add(mem, value) (void) exchange_and_add (mem, value)
#endif
#ifndef atomic_increment
# define atomic_increment(mem) atomic_add (mem, 1)
#endif
#ifndef atomic_decrement
# define atomic_decrement(mem) atomic_add (mem, -1)
#endif
#ifndef atomic_set_bit
# define atomic_set_bit(mem, bit) \
(void) ({ __typeof (mem) __memp = (mem); \
while (1) \
{ \
__typeof (*mem) __oldval = *__memp; \
\
if (compare_and_exchange_acq (__memp, __oldval | 1 << bit, \
__oldval) == 0) \
break; \
}})
#endif
#ifndef atomic_full_barrier
# define full_barrier() __asm ("" ::: "memory")
#endif
#ifndef atomic_read_barrier
# define read_barrier() full_barrier()
#endif
#ifndef atomic_write_barrier
# define write_barrier() full_barrier()
#endif
#endif /* atomic.h */

92
nptl/cancellation.c Normal file
View File

@ -0,0 +1,92 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <setjmp.h>
#include <stdlib.h>
#include "pthreadP.h"
/* This function is responsible for calling all registered cleanup
handlers and then terminate the thread. This includes dellocating
the thread-specific data. The implementation is complicated by the
fact that we have to handle to cancellation handler registration
methods: exceptions using try/finally and setjmp.
The setjmp method is always available. The user might compile some
code which uses this method because no modern compiler is
available. So we have to handle these first since we cannot call
the cleanup handlers if the stack frames are gone. At the same
time this opens a hole for the register exception handler blocks
since now they might be in danger of using an overwritten stack
frame. The advise is to only use new or only old style cancellation
handling. */
void
__do_cancel (char *currentframe)
{
struct pthread *self = THREAD_SELF;
/* Cleanup the thread-local storage. */
__cleanup_thread (self, currentframe);
/* Throw an exception. */
// XXX TBI
/* If throwing an exception didn't work try the longjmp. */
__libc_longjmp (self->cancelbuf, 1);
/* NOTREACHED */
}
void
__cleanup_thread (struct pthread *self, char *currentframe)
{
struct _pthread_cleanup_buffer *cleanups;
/* Call all registered cleanup handlers. */
cleanups = THREAD_GETMEM (self, cleanup);
if (__builtin_expect (cleanups != NULL, 0))
{
struct _pthread_cleanup_buffer *last;
while (FRAME_LEFT (currentframe, cleanups))
{
last = cleanups;
cleanups = cleanups->__prev;
if (cleanups == NULL || FRAME_LEFT (last, cleanups))
{
cleanups = NULL;
break;
}
}
while (cleanups != NULL)
{
/* Call the registered cleanup function. */
cleanups->__routine (cleanups->__arg);
last = cleanups;
cleanups = cleanups->__prev;
if (FRAME_LEFT (last, cleanups))
break;
}
}
}

63
nptl/cleanup.c Normal file
View File

@ -0,0 +1,63 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <stdlib.h>
#include "pthreadP.h"
void
_pthread_cleanup_push (buffer, routine, arg)
struct _pthread_cleanup_buffer *buffer;
void (*routine) (void *);
void *arg;
{
struct pthread *self = THREAD_SELF;
buffer->__routine = routine;
buffer->__arg = arg;
buffer->__prev = THREAD_GETMEM (self, cleanup);
if (buffer->__prev != NULL && FRAME_LEFT (buffer, buffer->__prev))
buffer->__prev = NULL;
THREAD_SETMEM (self, cleanup, buffer);
}
extern void _GI_pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer,
void (*routine) (void *), void *arg)
attribute_hidden;
strong_alias (_pthread_cleanup_push, _GI_pthread_cleanup_push)
void
_pthread_cleanup_pop (buffer, execute)
struct _pthread_cleanup_buffer *buffer;
int execute;
{
struct pthread *self __attribute ((unused)) = THREAD_SELF;
THREAD_SETMEM (self, cleanup, buffer->__prev);
/* If necessary call the cleanup routine after we removed the
current cleanup block from the list. */
if (execute)
buffer->__routine (buffer->__arg);
}
extern void _GI_pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer,
int execute) attribute_hidden;
strong_alias (_pthread_cleanup_pop, _GI_pthread_cleanup_pop)

86
nptl/cleanup_defer.c Normal file
View File

@ -0,0 +1,86 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include "pthreadP.h"
#include <atomic.h>
void
_pthread_cleanup_push_defer (buffer, routine, arg)
struct _pthread_cleanup_buffer *buffer;
void (*routine) (void *);
void *arg;
{
struct pthread *self = THREAD_SELF;
buffer->__routine = routine;
buffer->__arg = arg;
buffer->__prev = THREAD_GETMEM (self, cleanup);
if (buffer->__prev != NULL && FRAME_LEFT (buffer, buffer->__prev))
buffer->__prev = NULL;
int cancelhandling = THREAD_GETMEM (self, cancelhandling);
/* Disable asynchronous cancellation for now. */
if (__builtin_expect (cancelhandling & CANCELTYPE_BITMASK, 0))
{
while (atomic_compare_and_exchange_acq (&self->cancelhandling,
cancelhandling
& ~CANCELTYPE_BITMASK,
cancelhandling) != 0)
cancelhandling = self->cancelhandling;
}
buffer->__canceltype = (cancelhandling & CANCELTYPE_BITMASK
? PTHREAD_CANCEL_ASYNCHRONOUS
: PTHREAD_CANCEL_DEFERRED);
THREAD_SETMEM (self, cleanup, buffer);
}
void
_pthread_cleanup_pop_restore (buffer, execute)
struct _pthread_cleanup_buffer *buffer;
int execute;
{
struct pthread *self = THREAD_SELF;
THREAD_SETMEM (self, cleanup, buffer->__prev);
int cancelhandling;
if (__builtin_expect (buffer->__canceltype != PTHREAD_CANCEL_DEFERRED, 0)
&& ((cancelhandling = THREAD_GETMEM (self, cancelhandling))
& CANCELTYPE_BITMASK) == 0)
{
while (atomic_compare_and_exchange_acq (&self->cancelhandling,
cancelhandling
| CANCELTYPE_BITMASK,
cancelhandling) != 0)
cancelhandling = self->cancelhandling;
CANCELLATION_P (self);
}
/* If necessary call the cleanup routine after we removed the
current cleanup block from the list. */
if (execute)
buffer->__routine (buffer->__arg);
}

5
nptl/configure vendored Normal file
View File

@ -0,0 +1,5 @@
# This is only to keep the GNU C library configure mechanism happy.
#
# Perhaps some day we need a real configuration script for different
# kernel versions or so.
exit 0

179
nptl/descr.h Normal file
View File

@ -0,0 +1,179 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#ifndef _DESCR_H
#define _DESCR_H 1
#include <limits.h>
#include <sched.h>
#include <setjmp.h>
#include <stdbool.h>
#include <sys/types.h>
#include <hp-timing.h>
#include <list.h>
#include <lowlevellock.h>
#include <pthreaddef.h>
#include "../nptl_db/thread_db.h"
#ifndef TCB_ALIGNMENT
# define TCB_ALIGNMENT sizeof (double)
#endif
/* We keep thread specific data in a special data structure, a two-level
array. The top-level array contains pointers to dynamically allocated
arrays of a certain number of data pointers. So we can implement a
sparse array. Each dynamic second-level array has
PTHREAD_KEY_2NDLEVEL_SIZE
entries. This value shouldn't be too large. */
#define PTHREAD_KEY_2NDLEVEL_SIZE 32
/* We need to address PTHREAD_KEYS_MAX key with PTHREAD_KEY_2NDLEVEL_SIZE
keys in each subarray. */
#define PTHREAD_KEY_1STLEVEL_SIZE \
((PTHREAD_KEYS_MAX + PTHREAD_KEY_2NDLEVEL_SIZE - 1) \
/ PTHREAD_KEY_2NDLEVEL_SIZE)
/* Thread descriptor data structure. */
struct pthread
{
/* XXX Remove this union for IA-64 style TLS module */
union
{
struct
{
void *tcb; /* Pointer to the TCB. This is not always
the address of this thread descriptor. */
union dtv *dtvp;
struct pthread *self; /* Pointer to this structure */
list_t list;
} data;
void *__padding[16];
} header;
/* Two-level array for the thread-specific data. */
struct pthread_key_data
{
/* Sequence number. We use uintptr_t to not require padding on
32- and 64-bit machines. On 64-bit machines it helps to avoid
wrapping, too. */
uintptr_t seq;
/* Data pointer. */
void *data;
} *specific[PTHREAD_KEY_1STLEVEL_SIZE];
/* We allocate one block of references here. This should be enough
to avoid allocating any memory dynamically for most applications. */
struct pthread_key_data specific_1stblock[PTHREAD_KEY_2NDLEVEL_SIZE];
/* Flag which is set when specific data is set. */
bool specific_used;
/* True if the user provided the stack. */
bool user_stack;
/* True if events must be reported. */
bool report_events;
/* Lock to syncronize access to the descriptor. */
lll_lock_t lock;
#if HP_TIMING_AVAIL
/* Offset of the CPU clock at start thread start time. */
hp_timing_t cpuclock_offset;
#endif
/* If the thread waits to join another one the ID of the latter is
stored here.
In case a thread is detached this field contains a pointer of the
TCB if the thread itself. This is something which cannot happen
in normal operation. */
struct pthread *joinid;
/* Check whether a thread is detached. */
#define IS_DETACHED(pd) ((pd)->joinid == (pd))
/* List of cleanup buffers. */
struct _pthread_cleanup_buffer *cleanup;
/* Flags determining processing of cancellation. */
int cancelhandling;
/* Bit set if cancellation is disabled. */
#define CANCELSTATE_BIT 0
#define CANCELSTATE_BITMASK 0x01
/* Bit set if asynchronous cancellation mode is selected. */
#define CANCELTYPE_BIT 1
#define CANCELTYPE_BITMASK 0x02
/* Bit set if canceled. */
#define CANCELED_BIT 2
#define CANCELED_BITMASK 0x04
/* Bit set if thread is exiting. */
#define EXITING_BIT 3
#define EXITING_BITMASK 0x08
/* Bit set if thread terminated and TCB is freed. */
#define TERMINATED_BIT 4
#define TERMINATED_BITMASK 0x10
/* Mask for the rest. Helps the compiler to optimize. */
#define CANCEL_RESTMASK 0xffffffe0
#define CANCEL_ENABLED_AND_CANCELED(value) \
(((value) & (CANCELSTATE_BITMASK | CANCELED_BITMASK | EXITING_BITMASK \
| CANCEL_RESTMASK | TERMINATED_BITMASK)) == CANCELED_BITMASK)
#define CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS(value) \
(((value) & (CANCELSTATE_BITMASK | CANCELTYPE_BITMASK | CANCELED_BITMASK \
| EXITING_BITMASK | CANCEL_RESTMASK | TERMINATED_BITMASK)) \
== (CANCELTYPE_BITMASK | CANCELED_BITMASK))
/* Setjmp buffer to be used if try/finally is not available. */
sigjmp_buf cancelbuf;
#define HAVE_CANCELBUF 1
/* Thread ID - which is also a 'is this thread descriptor (and
therefore stack) used' flag. */
pid_t tid;
/* Flags. Including those copied from the thread attribute. */
int flags;
/* The result of the thread function. */
void *result;
/* Scheduling parameters for the new thread. */
struct sched_param schedparam;
int schedpolicy;
/* Start position of the code to be executed and the argument passed
to the function. */
void *(*start_routine) (void *);
void *arg;
/* Debug state. */
td_eventbuf_t eventbuf;
/* Next descriptor with a pending event. */
struct pthread *nextevent;
/* If nonzero pointer to area allocated for the stack and its
size. */
void *stackblock;
size_t stackblock_size;
/* Size of the included guard area. */
size_t guardsize;
} __attribute ((aligned (TCB_ALIGNMENT)));
#endif /* descr.h */

32
nptl/events.c Normal file
View File

@ -0,0 +1,32 @@
/* Event functions used while debugging.
Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* The functions contained here do nothing, they just return. */
#include "pthreadP.h"
void
__nptl_create_event (void)
{
}
void
__nptl_death_event (void)
{
}

31
nptl/flockfile.c Normal file
View File

@ -0,0 +1,31 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <pthread.h>
#include <stdio.h>
#include <libio.h>
void
flockfile (stream)
FILE *stream;
{
pthread_mutex_lock (stream->_lock);
}
strong_alias (flockfile, _IO_flockfile)

151
nptl/forward.c Normal file
View File

@ -0,0 +1,151 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <dlfcn.h>
#include <pthread.h>
#include <stdlib.h>
#include <shlib-compat.h>
#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3_2)
static void *libpthread_handle;
static void
test_loaded (void)
{
void *h = __libc_dlopen_mode ("libpthread.so.0", RTLD_LAZY | RTLD_NOLOAD);
libpthread_handle = h ?: (void *) -1l;
}
#define FORWARD3(name, rettype, decl, params, defaction, version) \
rettype \
__noexport_##name decl \
{ \
if (libpthread_handle == NULL) \
test_loaded (); \
\
if (libpthread_handle == (void *) -1l) \
defaction; \
\
static __typeof (name) *p; \
p = __libc_dlsym (libpthread_handle, #name); \
\
return p params; \
} \
compat_symbol (libc, __noexport_##name, name, version)
#define FORWARD2(name, decl, params, defretval, version) \
FORWARD3 (name, int, decl, params, return defretval, version)
#define FORWARD(name, decl, params, defretval) \
FORWARD2 (name, decl, params, defretval, GLIBC_2_0)
FORWARD (pthread_attr_destroy, (pthread_attr_t *attr), (attr), 0);
FORWARD2 (pthread_attr_init, (pthread_attr_t *attr), (attr), 0, GLIBC_2_1);
FORWARD (pthread_attr_getdetachstate,
(const pthread_attr_t *attr, int *detachstate), (attr, detachstate),
0);
FORWARD (pthread_attr_setdetachstate, (pthread_attr_t *attr, int detachstate),
(attr, detachstate), 0);
FORWARD (pthread_attr_getinheritsched,
(const pthread_attr_t *attr, int *inherit), (attr, inherit), 0);
FORWARD (pthread_attr_setinheritsched, (pthread_attr_t *attr, int inherit),
(attr, inherit), 0);
FORWARD (pthread_attr_getschedparam,
(const pthread_attr_t *attr, struct sched_param *param),
(attr, param), 0);
FORWARD (pthread_attr_setschedparam,
(pthread_attr_t *attr, const struct sched_param *param),
(attr, param), 0);
FORWARD (pthread_attr_getschedpolicy,
(const pthread_attr_t *attr, int *policy), (attr, policy), 0);
FORWARD (pthread_attr_setschedpolicy, (pthread_attr_t *attr, int policy),
(attr, policy), 0);
FORWARD (pthread_attr_getscope,
(const pthread_attr_t *attr, int *scope), (attr, scope), 0);
FORWARD (pthread_attr_setscope, (pthread_attr_t *attr, int scope),
(attr, scope), 0);
FORWARD (pthread_condattr_destroy, (pthread_condattr_t *attr), (attr), 0);
FORWARD (pthread_condattr_init, (pthread_condattr_t *attr), (attr), 0);
FORWARD (pthread_cond_broadcast, (pthread_cond_t *cond), (cond), 0);
FORWARD (pthread_cond_destroy, (pthread_cond_t *cond), (cond), 0);
FORWARD (pthread_cond_init,
(pthread_cond_t *cond, const pthread_condattr_t *cond_attr),
(cond, cond_attr), 0);
FORWARD (pthread_cond_signal, (pthread_cond_t *cond), (cond), 0);
FORWARD (pthread_cond_wait, (pthread_cond_t *cond, pthread_mutex_t *mutex),
(cond, mutex), 0);
FORWARD (pthread_equal, (pthread_t thread1, pthread_t thread2),
(thread1, thread2), 1);
FORWARD3 (pthread_exit, void, (void *retval), (retval), exit (EXIT_SUCCESS),
GLIBC_2_0);
FORWARD (pthread_getschedparam,
(pthread_t target_thread, int *policy, struct sched_param *param),
(target_thread, policy, param), 0);
FORWARD (pthread_setschedparam,
(pthread_t target_thread, int policy,
const struct sched_param *param), (target_thread, policy, param), 0);
FORWARD (pthread_mutex_destroy, (pthread_mutex_t *mutex), (mutex), 0);
FORWARD (pthread_mutex_init,
(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr),
(mutex, mutexattr), 0);
FORWARD (pthread_mutex_lock, (pthread_mutex_t *mutex), (mutex), 0);
FORWARD (pthread_mutex_unlock, (pthread_mutex_t *mutex), (mutex), 0);
FORWARD (pthread_self, (void), (), 0);
FORWARD (pthread_setcancelstate, (int state, int *oldstate), (state, oldstate),
0);
FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0);
#endif

31
nptl/ftrylockfile.c Normal file
View File

@ -0,0 +1,31 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <pthread.h>
#include <stdio.h>
#include <libio.h>
int
ftrylockfile (stream)
FILE *stream;
{
return pthread_mutex_trylock (stream->_lock);
}
strong_alias (ftrylockfile, _IO_ftrylockfile)

31
nptl/funlockfile.c Normal file
View File

@ -0,0 +1,31 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <pthread.h>
#include <stdio.h>
#include <libio.h>
void
funlockfile (stream)
FILE *stream;
{
pthread_mutex_unlock (stream->_lock);
}
strong_alias (funlockfile, _IO_funlockfile)

36
nptl/herrno.c Normal file
View File

@ -0,0 +1,36 @@
/* Copyright (C) 1996,97,98,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <features.h>
#include <netdb.h>
#undef h_errno
#include <tls.h>
/* We need to have the error status variable of the resolver
accessible in the libc. */
extern __thread int h_errno;
/* When threaded, h_errno may be a per-thread variable. */
int *
weak_const_function
__h_errno_location (void)
{
return &h_errno;
}

172
nptl/init.c Normal file
View File

@ -0,0 +1,172 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include <limits.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/resource.h>
#include <pthreadP.h>
#include <atomic.h>
#include <ldsodefs.h>
#include <tls.h>
#include <fork.h>
#include <version.h>
/* XXX For the time being... */
#define __NR_set_tid_address 258
/* Default stack size. */
size_t __default_stacksize attribute_hidden;
/* Size and alignment of static TLS block. */
size_t __static_tls_size;
size_t __static_tls_align;
/* Version of the library, used in libthread_db to detect mismatches. */
static const char nptl_version[] = VERSION;
#if defined USE_TLS && !defined SHARED
extern void __libc_setup_tls (size_t tcbsize, size_t tcbalign);
#endif
/* For asynchronous cancellation we use a signal. This is the handler. */
static void
sigcancel_handler (int sig __attribute ((unused)))
{
struct pthread *self = THREAD_SELF;
while (1)
{
/* We are canceled now. When canceled by another thread this flag
is already set but if the signal is directly send (internally or
from another process) is has to be done here. */
int oldval = THREAD_GETMEM (self, cancelhandling);
int newval = oldval | CANCELED_BITMASK;
if (oldval == newval || (oldval & EXITING_BITMASK) != 0)
/* Already canceled or exiting. */
break;
if (atomic_compare_and_exchange_acq (&self->cancelhandling, newval,
oldval) == 0)
{
/* Set the return value. */
THREAD_SETMEM (self, result, PTHREAD_CANCELED);
/* Make sure asynchronous cancellation is still enabled. */
if ((newval & CANCELTYPE_BITMASK) != 0)
{
/* The thread is exiting now. */
atomic_bit_set (&self->cancelhandling, EXITING_BIT);
/* Run the registered destructors and terminate the
thread. */
__do_cancel (CURRENT_STACK_FRAME);
}
break;
}
}
}
void
#ifdef SHARED
__attribute ((constructor))
#endif
__pthread_initialize_minimal (void)
{
struct sigaction sa;
struct rlimit limit;
#ifdef USE_TLS
struct pthread *pd;
#endif
#ifndef SHARED
/* Unlike in the dynamically linked case the dynamic linker has not
taken care of initializing the TLS data structures. */
__libc_setup_tls (TLS_TCB_SIZE, TLS_TCB_ALIGN);
#endif
/* Minimal initialization of the thread descriptor. */
pd = THREAD_SELF;
pd->tid = INTERNAL_SYSCALL (set_tid_address, 1, &pd->tid);
THREAD_SETMEM (pd, specific[0], &pd->specific_1stblock[0]);
THREAD_SETMEM (pd, user_stack, true);
if (LLL_LOCK_INITIALIZER != 0)
THREAD_SETMEM (pd, lock, LLL_LOCK_INITIALIZER);
#if HP_TIMING_AVAIL
THREAD_SETMEM (pd, cpuclock_offset, GL(dl_cpuclock_offset));
#endif
/* Add the main thread to the list of all running threads. No need
to get the lock we are alone so far. */
list_add (&pd->header.data.list, &__stack_user);
/* Install the cancellation signal handler. If for some reason we
cannot install the handler we do not abort. Maybe we should, but
it is only asynchronous cancellation which is affected. */
sa.sa_handler = sigcancel_handler;
sa.sa_flags = 0;
/* Avoid another cancellation signal when we process one. */
sigemptyset (&sa.sa_mask);
sigaddset (&sa.sa_mask, SIGCANCEL);
(void) __libc_sigaction (SIGCANCEL, &sa, NULL);
/* Determine the default allowed stack size. This is the size used
in case the user does not specify one. */
if (getrlimit (RLIMIT_STACK, &limit) != 0
|| limit.rlim_cur == RLIM_INFINITY)
/* The system limit is not usable. Use an architecture-specific
default. */
limit.rlim_cur = ARCH_STACK_DEFAULT_SIZE;
#ifdef NEED_SEPARATE_REGISTER_STACK
__default_stacksize = MAX (limit.rlim_cur / 2, PTHREAD_STACK_MIN);
#else
__default_stacksize = MAX (limit.rlim_cur, PTHREAD_STACK_MIN);
#endif
/* The maximum page size better should be a multiple of the page
size. */
assert (__default_stacksize % __sysconf (_SC_PAGESIZE) == 0);
/* Get the size of the static and alignment requirements for the TLS
block. */
_dl_get_tls_static_info (&__static_tls_size, &__static_tls_align);
/* Make sure the size takes all the alignments into account. */
if (STACK_ALIGN > __static_tls_align)
__static_tls_align = STACK_ALIGN;
__static_tls_size = roundup (__static_tls_size, __static_tls_align);
/* Register the fork generation counter with the libc. */
__register_pthread_fork_handler (&__fork_generation, __reclaim_stacks);
}

27
nptl/old_pthread_atfork.c Normal file
View File

@ -0,0 +1,27 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <shlib-compat.h>
#if SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_3)
# define __pthread_atfork __dyn_pthread_atfork
# include "pthread_atfork.c"
# undef __pthread_atfork
compat_symbol (libpthread, __dyn_pthread_atfork, pthread_atfork, GLIBC_2_0);
#endif

749
nptl/perf.c Normal file
View File

@ -0,0 +1,749 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#define _GNU_SOURCE 1
#include <argp.h>
#include <error.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <pthread.h>
#include <signal.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/types.h>
#ifndef MAX_THREADS
# define MAX_THREADS 100000
#endif
#ifndef DEFAULT_THREADS
# define DEFAULT_THREADS 50
#endif
#define OPT_TO_THREAD 300
#define OPT_TO_PROCESS 301
#define OPT_SYNC_SIGNAL 302
#define OPT_SYNC_JOIN 303
#define OPT_TOPLEVEL 304
static const struct argp_option options[] =
{
{ NULL, 0, NULL, 0, "\
This is a test for threads so we allow ther user to selection the number of \
threads which are used at any one time. Independently the total number of \
rounds can be selected. This is the total number of threads which will have \
run when the process terminates:" },
{ "threads", 't', "NUMBER", 0, "Number of threads used at once" },
{ "starts", 's', "NUMBER", 0, "Total number of working threads" },
{ "toplevel", OPT_TOPLEVEL, "NUMBER", 0,
"Number of toplevel threads which start the other threads; this \
implies --sync-join" },
{ NULL, 0, NULL, 0, "\
Each thread can do one of two things: sleep or do work. The latter is 100% \
CPU bound. The work load is the probability a thread does work. All values \
from zero to 100 (inclusive) are valid. How often each thread repeats this \
can be determined by the number of rounds. The work cost determines how long \
each work session (not sleeping) takes. If it is zero a thread would \
effectively nothing. By setting the number of rounds to zero the thread \
does no work at all and pure thread creation times can be measured." },
{ "workload", 'w', "PERCENT", 0, "Percentage of time spent working" },
{ "workcost", 'c', "NUMBER", 0,
"Factor in the cost of each round of working" },
{ "rounds", 'r', "NUMBER", 0, "Number of rounds each thread runs" },
{ NULL, 0, NULL, 0, "\
There are a number of different methods how thread creation can be \
synchronized. Synchronization is necessary since the number of concurrently \
running threads is limited." },
{ "sync-signal", OPT_SYNC_SIGNAL, NULL, 0,
"Synchronize using a signal (default)" },
{ "sync-join", OPT_SYNC_JOIN, NULL, 0, "Synchronize using pthread_join" },
{ NULL, 0, NULL, 0, "\
One parameter for each threads execution is the size of the stack. If this \
parameter is not used the system's default stack size is used. If many \
threads are used the stack size should be chosen quite small." },
{ "stacksize", 'S', "BYTES", 0, "Size of threads stack" },
{ "guardsize", 'g', "BYTES", 0,
"Size of stack guard area; must fit into the stack" },
{ NULL, 0, NULL, 0, "Signal options:" },
{ "to-thread", OPT_TO_THREAD, NULL, 0, "Send signal to main thread" },
{ "to-process", OPT_TO_PROCESS, NULL, 0,
"Send signal to process (default)" },
{ NULL, 0, NULL, 0, "Administrative options:" },
{ "progress", 'p', NULL, 0, "Show signs of progress" },
{ "timing", 'T', NULL, 0,
"Measure time from startup to the last thread finishing" },
{ NULL, 0, NULL, 0, NULL }
};
/* Prototype for option handler. */
static error_t parse_opt (int key, char *arg, struct argp_state *state);
/* Data structure to communicate with argp functions. */
static struct argp argp =
{
options, parse_opt
};
static unsigned long int threads = DEFAULT_THREADS;
static unsigned long int workload = 75;
static unsigned long int workcost = 20;
static unsigned long int rounds = 10;
static long int starts = 5000;
static unsigned long int stacksize;
static long int guardsize = -1;
static bool progress;
static bool timing;
static bool to_thread;
static unsigned long int toplevel = 1;
static long int running;
static pthread_mutex_t running_mutex = PTHREAD_MUTEX_INITIALIZER;
static pid_t pid;
static pthread_t tmain;
static clockid_t cl;
static struct timespec start_time;
static pthread_mutex_t sum_mutex = PTHREAD_MUTEX_INITIALIZER;
unsigned int sum;
static enum
{
sync_signal,
sync_join
}
sync_method;
/* We use 64bit values for the times. */
typedef unsigned long long int hp_timing_t;
/* Attributes for all created threads. */
static pthread_attr_t attr;
static void *
work (void *arg)
{
unsigned long int i;
unsigned int state = (unsigned long int) arg;
for (i = 0; i < rounds; ++i)
{
/* Determine what to do. */
unsigned int rnum;
/* Equal distribution. */
do
rnum = rand_r (&state);
while (rnum >= UINT_MAX - (UINT_MAX % 100));
rnum %= 100;
if (rnum < workload)
{
int j;
int a[4] = { i, rnum, i + rnum, rnum - i };
if (progress)
write (STDERR_FILENO, "c", 1);
for (j = 0; j < workcost; ++j)
{
a[0] += a[3] >> 12;
a[1] += a[2] >> 20;
a[2] += a[1] ^ 0x3423423;
a[3] += a[0] - a[1];
}
pthread_mutex_lock (&sum_mutex);
sum += a[0] + a[1] + a[2] + a[3];
pthread_mutex_unlock (&sum_mutex);
}
else
{
/* Just sleep. */
struct timespec tv;
tv.tv_sec = 0;
tv.tv_nsec = 10000000;
if (progress)
write (STDERR_FILENO, "w", 1);
nanosleep (&tv, NULL);
}
}
return NULL;
}
static void *
thread_function (void *arg)
{
work (arg);
pthread_mutex_lock (&running_mutex);
if (--running <= 0 && starts <= 0)
{
/* We are done. */
if (progress)
write (STDERR_FILENO, "\n", 1);
if (timing)
{
struct timespec end_time;
if (clock_gettime (cl, &end_time) == 0)
{
end_time.tv_sec -= start_time.tv_sec;
end_time.tv_nsec -= start_time.tv_nsec;
if (end_time.tv_nsec < 0)
{
end_time.tv_nsec += 1000000000;
--end_time.tv_sec;
}
printf ("\nRuntime: %lu.%09lu seconds\n",
(unsigned long int) end_time.tv_sec,
(unsigned long int) end_time.tv_nsec);
}
}
printf ("Result: %08x\n", sum);
exit (0);
}
pthread_mutex_unlock (&running_mutex);
if (sync_method == sync_signal)
{
if (to_thread)
/* This code sends a signal to the main thread. */
pthread_kill (tmain, SIGUSR1);
else
/* Use this code to test sending a signal to the process. */
kill (pid, SIGUSR1);
}
if (progress)
write (STDERR_FILENO, "f", 1);
return NULL;
}
struct start_info
{
unsigned int starts;
unsigned int threads;
};
static void *
start_threads (void *arg)
{
struct start_info *si = arg;
unsigned int starts = si->starts;
pthread_t ths[si->threads];
unsigned int state = starts;
unsigned int n;
unsigned int i = 0;
int err;
if (progress)
write (STDERR_FILENO, "T", 1);
memset (ths, '\0', sizeof (pthread_t) * si->threads);
while (starts-- > 0)
{
if (ths[i] != 0)
{
/* Wait for the threads in the order they were created. */
err = pthread_join (ths[i], NULL);
if (err != 0)
error (EXIT_FAILURE, err, "cannot join thread");
if (progress)
write (STDERR_FILENO, "f", 1);
}
err = pthread_create (&ths[i], &attr, work,
(void *) (rand_r (&state) + starts + i));
if (err != 0)
error (EXIT_FAILURE, err, "cannot start thread");
if (progress)
write (STDERR_FILENO, "t", 1);
if (++i == si->threads)
i = 0;
}
n = i;
do
{
if (ths[i] != 0)
{
err = pthread_join (ths[i], NULL);
if (err != 0)
error (EXIT_FAILURE, err, "cannot join thread");
if (progress)
write (STDERR_FILENO, "f", 1);
}
if (++i == si->threads)
i = 0;
}
while (i != n);
if (progress)
write (STDERR_FILENO, "F", 1);
return NULL;
}
int
main (int argc, char *argv[])
{
int remaining;
sigset_t ss;
pthread_t th;
pthread_t *ths = NULL;
int empty = 0;
int last;
bool cont = true;
/* Parse and process arguments. */
argp_parse (&argp, argc, argv, 0, &remaining, NULL);
if (sync_method == sync_join)
{
ths = (pthread_t *) calloc (threads, sizeof (pthread_t));
if (ths == NULL)
error (EXIT_FAILURE, errno,
"cannot allocate memory for thread descriptor array");
last = threads;
}
else
{
ths = &th;
last = 1;
}
if (toplevel > threads)
{
printf ("resetting number of toplevel threads to %lu to not surpass number to concurrent threads\n",
threads);
toplevel = threads;
}
if (timing)
{
if (clock_getcpuclockid (0, &cl) != 0
|| clock_gettime (cl, &start_time) != 0)
timing = false;
}
/* We need this later. */
pid = getpid ();
tmain = pthread_self ();
/* We use signal SIGUSR1 for communication between the threads and
the main thread. We only want sychronous notification. */
if (sync_method == sync_signal)
{
sigemptyset (&ss);
sigaddset (&ss, SIGUSR1);
if (sigprocmask (SIG_BLOCK, &ss, NULL) != 0)
error (EXIT_FAILURE, errno, "cannot set signal mask");
}
/* Create the thread attributes. */
pthread_attr_init (&attr);
/* If the user provided a stack size use it. */
if (stacksize != 0
&& pthread_attr_setstacksize (&attr, stacksize) != 0)
puts ("could not set stack size; will use default");
/* And stack guard size. */
if (guardsize != -1
&& pthread_attr_setguardsize (&attr, guardsize) != 0)
puts ("invalid stack guard size; will use default");
/* All threads are created detached if we are not using pthread_join
to synchronize. */
if (sync_method != sync_join)
pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
if (sync_method == sync_signal)
{
while (1)
{
int err;
bool do_wait = false;
pthread_mutex_lock (&running_mutex);
if (starts-- < 0)
cont = false;
else
do_wait = ++running >= threads && starts > 0;
pthread_mutex_unlock (&running_mutex);
if (! cont)
break;
if (progress)
write (STDERR_FILENO, "t", 1);
err = pthread_create (&ths[empty], &attr, thread_function,
(void *) starts);
if (err != 0)
error (EXIT_FAILURE, err, "cannot start thread %lu", starts);
if (++empty == last)
empty = 0;
if (do_wait)
sigwaitinfo (&ss, NULL);
}
/* Do nothing anymore. On of the threads will terminate the program. */
sigfillset (&ss);
sigdelset (&ss, SIGINT);
while (1)
sigsuspend (&ss);
}
else
{
pthread_t ths[toplevel];
struct start_info si[toplevel];
unsigned int i;
for (i = 0; i < toplevel; ++i)
{
unsigned int child_starts = starts / (toplevel - i);
unsigned int child_threads = threads / (toplevel - i);
int err;
si[i].starts = child_starts;
si[i].threads = child_threads;
err = pthread_create (&ths[i], &attr, start_threads, &si[i]);
if (err != 0)
error (EXIT_FAILURE, err, "cannot start thread");
starts -= child_starts;
threads -= child_threads;
}
for (i = 0; i < toplevel; ++i)
{
int err = pthread_join (ths[i], NULL);
if (err != 0)
error (EXIT_FAILURE, err, "cannot join thread");
}
/* We are done. */
if (progress)
write (STDERR_FILENO, "\n", 1);
if (timing)
{
struct timespec end_time;
if (clock_gettime (cl, &end_time) == 0)
{
end_time.tv_sec -= start_time.tv_sec;
end_time.tv_nsec -= start_time.tv_nsec;
if (end_time.tv_nsec < 0)
{
end_time.tv_nsec += 1000000000;
--end_time.tv_sec;
}
printf ("\nRuntime: %lu.%09lu seconds\n",
(unsigned long int) end_time.tv_sec,
(unsigned long int) end_time.tv_nsec);
}
}
printf ("Result: %08x\n", sum);
exit (0);
}
/* NOTREACHED */
return 0;
}
/* Handle program arguments. */
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
unsigned long int num;
long int snum;
switch (key)
{
case 't':
num = strtoul (arg, NULL, 0);
if (num < MAX_THREADS)
threads = num;
else
printf ("\
number of threads limited to %u; recompile with a higher limit if necessary",
MAX_THREADS);
break;
case 'w':
num = strtoul (arg, NULL, 0);
if (num <= 100)
workload = num;
else
puts ("workload must be between 0 and 100 percent");
break;
case 'c':
workcost = strtoul (arg, NULL, 0);
break;
case 'r':
rounds = strtoul (arg, NULL, 0);
break;
case 's':
starts = strtoul (arg, NULL, 0);
break;
case 'S':
num = strtoul (arg, NULL, 0);
if (num >= PTHREAD_STACK_MIN)
stacksize = num;
else
printf ("minimum stack size is %d\n", PTHREAD_STACK_MIN);
break;
case 'g':
snum = strtol (arg, NULL, 0);
if (snum < 0)
printf ("invalid guard size %s\n", arg);
else
guardsize = snum;
break;
case 'p':
progress = true;
break;
case 'T':
timing = true;
break;
case OPT_TO_THREAD:
to_thread = true;
break;
case OPT_TO_PROCESS:
to_thread = false;
break;
case OPT_SYNC_SIGNAL:
sync_method = sync_signal;
break;
case OPT_SYNC_JOIN:
sync_method = sync_join;
break;
case OPT_TOPLEVEL:
num = strtoul (arg, NULL, 0);
if (num < MAX_THREADS)
toplevel = num;
else
printf ("\
number of threads limited to %u; recompile with a higher limit if necessary",
MAX_THREADS);
sync_method = sync_join;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static hp_timing_t
get_clockfreq (void)
{
/* We read the information from the /proc filesystem. It contains at
least one line like
cpu MHz : 497.840237
or also
cpu MHz : 497.841
We search for this line and convert the number in an integer. */
static hp_timing_t result;
int fd;
/* If this function was called before, we know the result. */
if (result != 0)
return result;
fd = open ("/proc/cpuinfo", O_RDONLY);
if (__builtin_expect (fd != -1, 1))
{
/* XXX AFAIK the /proc filesystem can generate "files" only up
to a size of 4096 bytes. */
char buf[4096];
ssize_t n;
n = read (fd, buf, sizeof buf);
if (__builtin_expect (n, 1) > 0)
{
char *mhz = memmem (buf, n, "cpu MHz", 7);
if (__builtin_expect (mhz != NULL, 1))
{
char *endp = buf + n;
int seen_decpoint = 0;
int ndigits = 0;
/* Search for the beginning of the string. */
while (mhz < endp && (*mhz < '0' || *mhz > '9') && *mhz != '\n')
++mhz;
while (mhz < endp && *mhz != '\n')
{
if (*mhz >= '0' && *mhz <= '9')
{
result *= 10;
result += *mhz - '0';
if (seen_decpoint)
++ndigits;
}
else if (*mhz == '.')
seen_decpoint = 1;
++mhz;
}
/* Compensate for missing digits at the end. */
while (ndigits++ < 6)
result *= 10;
}
}
close (fd);
}
return result;
}
int
clock_getcpuclockid (pid_t pid, clockid_t *clock_id)
{
/* We don't allow any process ID but our own. */
if (pid != 0 && pid != getpid ())
return EPERM;
#ifdef CLOCK_PROCESS_CPUTIME_ID
/* Store the number. */
*clock_id = CLOCK_PROCESS_CPUTIME_ID;
return 0;
#else
/* We don't have a timer for that. */
return ENOENT;
#endif
}
#define HP_TIMING_NOW(Var) __asm__ __volatile__ ("rdtsc" : "=A" (Var))
/* Get current value of CLOCK and store it in TP. */
int
clock_gettime (clockid_t clock_id, struct timespec *tp)
{
int retval = -1;
switch (clock_id)
{
case CLOCK_PROCESS_CPUTIME_ID:
{
static hp_timing_t freq;
hp_timing_t tsc;
/* Get the current counter. */
HP_TIMING_NOW (tsc);
if (freq == 0)
{
freq = get_clockfreq ();
if (freq == 0)
return EINVAL;
}
/* Compute the seconds. */
tp->tv_sec = tsc / freq;
/* And the nanoseconds. This computation should be stable until
we get machines with about 16GHz frequency. */
tp->tv_nsec = ((tsc % freq) * UINT64_C (1000000000)) / freq;
retval = 0;
}
break;
default:
errno = EINVAL;
break;
}
return retval;
}

40
nptl/pt-accept.c Normal file
View File

@ -0,0 +1,40 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/socket.h>
#include "pthreadP.h"
int
accept (int fd, __SOCKADDR_ARG addr, socklen_t *addr_len)
{
int oldtype;
int result;
CANCEL_ASYNC (oldtype);
result = __libc_accept (fd, addr, addr_len);
CANCEL_RESET (oldtype);
return result;
}

50
nptl/pt-allocrtsig.c Normal file
View File

@ -0,0 +1,50 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <signal.h>
/* These are defined in libc. We want to have only one definition
so we "forward" the calls. */
extern int __libc_current_sigrtmin_private (void);
extern int __libc_current_sigrtmax_private (void);
extern int __libc_allocate_rtsig_private (int high);
/* We reserve __SIGRTMIN for use as the cancelation signal. This
signal is used internally. */
int
__libc_current_sigrtmin (void)
{
return __libc_current_sigrtmin_private ();
}
int
__libc_current_sigrtmax (void)
{
return __libc_current_sigrtmax_private ();
}
int
__libc_allocate_rtsig (int high)
{
return __libc_allocate_rtsig_private (high);
}

45
nptl/pt-close.c Normal file
View File

@ -0,0 +1,45 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <unistd.h>
#include "pthreadP.h"
int
__close (int fd)
{
int oldtype;
int result;
CANCEL_ASYNC (oldtype);
#ifdef INLINE_SYSCALL
result = INLINE_SYSCALL (close, 1, fd);
#else
result = __libc_close (fd);
#endif
CANCEL_RESET (oldtype);
return result;
}
strong_alias (__close, close)

41
nptl/pt-connect.c Normal file
View File

@ -0,0 +1,41 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/socket.h>
#include "pthreadP.h"
int
__connect (int fd, __CONST_SOCKADDR_ARG addr, socklen_t addr_len)
{
int oldtype;
int result;
CANCEL_ASYNC (oldtype);
result = __libc_connect (fd, addr, addr_len);
CANCEL_RESET (oldtype);
return result;
}
strong_alias (__connect, connect)

45
nptl/pt-creat.c Normal file
View File

@ -0,0 +1,45 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sysdep.h>
#include <unistd.h>
#include "pthreadP.h"
int
creat (const char *pathname, mode_t mode)
{
int result;
int oldtype;
CANCEL_ASYNC (oldtype);
#if defined INLINE_SYSCALL && defined __NR_creat
result = INLINE_SYSCALL (creat, 2, pathname, mode);
#else
result = __libc_open (pathname, O_WRONLY|O_CREAT|O_TRUNC, mode);
#endif
CANCEL_RESET (oldtype);
return result;
}

54
nptl/pt-fcntl.c Normal file
View File

@ -0,0 +1,54 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sysdep.h>
#include <unistd.h>
#include "pthreadP.h"
int
__fcntl (int fd, int cmd, ...)
{
int oldtype;
int result;
va_list ap;
if (cmd == F_SETLKW)
CANCEL_ASYNC (oldtype);
va_start (ap, cmd);
#ifdef INLINE_SYSCALL
result = INLINE_SYSCALL (fcntl, 3, fd, cmd, va_arg (ap, long int));
#else
result = __libc_fcntl (fd, cmd, va_arg (ap, long int));
#endif
va_end (ap);
if (cmd == F_SETLKW)
CANCEL_RESET (oldtype);
return result;
}
strong_alias (__fcntl, fcntl)

44
nptl/pt-fsync.c Normal file
View File

@ -0,0 +1,44 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <unistd.h>
#include "pthreadP.h"
int
fsync (int fd)
{
int oldtype;
int result;
CANCEL_ASYNC (oldtype);
#ifdef INLINE_SYSCALL
result = INLINE_SYSCALL (fsync, 1, fd);
#else
result = __libc_fsync (fd);
#endif
CANCEL_RESET (oldtype);
return result;
}

65
nptl/pt-longjmp.c Normal file
View File

@ -0,0 +1,65 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <setjmp.h>
#include <stdlib.h>
#include "pthreadP.h"
void
__pthread_cleanup_upto (__jmp_buf target, char *targetframe)
{
struct pthread *self = THREAD_SELF;
struct _pthread_cleanup_buffer *cbuf;
for (cbuf = THREAD_GETMEM (self, cleanup);
cbuf != NULL && _JMPBUF_UNWINDS (target, cbuf);
cbuf = cbuf->__prev)
{
#if _STACK_GROWS_DOWN
if ((char *) cbuf <= targetframe)
{
cbuf = NULL;
break;
}
#elif _STACK_GROWS_UP
if ((char *) cbuf >= targetframe)
{
cbuf = NULL;
break;
}
#else
# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
#endif
/* Call the cleanup code. */
cbuf->__routine (cbuf->__arg);
}
THREAD_SETMEM (self, cleanup, cbuf);
}
void
longjmp (jmp_buf env, int val)
{
__libc_longjmp (env, val);
}
weak_alias (longjmp, siglongjmp)

45
nptl/pt-lseek.c Normal file
View File

@ -0,0 +1,45 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <unistd.h>
#include "pthreadP.h"
off_t
__lseek (int fd, off_t offset, int whence)
{
int oldtype;
off_t result;
CANCEL_ASYNC (oldtype);
#ifdef INLINE_SYSCALL
result = INLINE_SYSCALL (lseek, 3, fd, offset, whence);
#else
result = __libc_lseek (fd, offset, whence);
#endif
CANCEL_RESET (oldtype);
return result;
}
strong_alias (__lseek, lseek)

40
nptl/pt-lseek64.c Normal file
View File

@ -0,0 +1,40 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <unistd.h>
#include "pthreadP.h"
off64_t
lseek64 (int fd, off64_t offset, int whence)
{
int oldtype;
off64_t result;
CANCEL_ASYNC (oldtype);
result = __libc_lseek64 (fd, offset, whence);
CANCEL_RESET (oldtype);
return result;
}

40
nptl/pt-msgrcv.c Normal file
View File

@ -0,0 +1,40 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/msg.h>
#include "pthreadP.h"
int
msgrcv (int msqid, void *msgp, size_t msgsz, long int msgtyp, int msgflg)
{
int oldtype;
int result;
CANCEL_ASYNC (oldtype);
result = __libc_msgrcv (msqid, msgp, msgsz, msgtyp, msgflg);
CANCEL_RESET (oldtype);
return result;
}

46
nptl/pt-msgsnd.c Normal file
View File

@ -0,0 +1,46 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/msg.h>
#include <ipc_priv.h>
#include "pthreadP.h"
int
msgsnd (int msqid, const void *msgp, size_t msgsz, int msgflg)
{
int result;
int oldtype;
CANCEL_ASYNC (oldtype);
#ifdef INLINE_SYSCALL
result = INLINE_SYSCALL (ipc, 5, IPCOP_msgsnd, msqid, msgsz,
msgflg, (void *) msgp);
#else
result = __libc_msgsnd (msqid, msgp, msgsz, msgflg);
#endif
CANCEL_RESET (oldtype);
return result;
}

44
nptl/pt-msync.c Normal file
View File

@ -0,0 +1,44 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/mman.h>
#include "pthreadP.h"
int
msync (void *addr, size_t length, int flags)
{
int oldtype;
int result;
CANCEL_ASYNC (oldtype);
#ifdef INLINE_SYSCALL
result = INLINE_SYSCALL (msync, 3, addr, length, flags);
#else
result = __libc_msync (addr, length, flags);
#endif
CANCEL_RESET (oldtype);
return result;
}

45
nptl/pt-nanosleep.c Normal file
View File

@ -0,0 +1,45 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <time.h>
#include "pthreadP.h"
int
__nanosleep (const struct timespec *requested_time, struct timespec *remaining)
{
int oldtype;
int result;
CANCEL_ASYNC (oldtype);
#ifdef INLINE_SYSCALL
result = INLINE_SYSCALL (nanosleep, 2, requested_time, remaining);
#else
result = __libc_nanosleep (requested_time, remaining);
#endif
CANCEL_RESET (oldtype);
return result;
}
strong_alias (__nanosleep, nanosleep)

53
nptl/pt-open.c Normal file
View File

@ -0,0 +1,53 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sysdep.h>
#include <unistd.h>
#include "pthreadP.h"
int
__open (const char *pathname, int flags, ...)
{
int oldtype;
int result;
va_list ap;
va_start (ap, flags);
CANCEL_ASYNC (oldtype);
#ifdef INLINE_SYSCALL
result = INLINE_SYSCALL (open, 3, pathname, flags,
va_arg (ap, __typeof ((mode_t) 0 + 0)));
#else
result = __libc_open (pathname, flags,
va_arg (ap, __typeof ((mode_t) 0 + 0)));
#endif
CANCEL_RESET (oldtype);
va_end (ap);
return result;
}
strong_alias (__open, open)

54
nptl/pt-open64.c Normal file
View File

@ -0,0 +1,54 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sysdep.h>
#include <unistd.h>
#include "pthreadP.h"
int
__open64 (const char *pathname, int flags, ...)
{
int oldtype;
int result;
va_list ap;
va_start (ap, flags);
CANCEL_ASYNC (oldtype);
#if defined INLINE_SYSCALL && defined O_LARGEFILE
result = INLINE_SYSCALL (open, 3, pathname, flags | O_LARGEFILE,
va_arg (ap, __typeof ((mode_t) 0 + 0)));
#else
result = __libc_open64 (pathname, flags,
va_arg (ap, __typeof ((mode_t) 0 + 0)));
#endif
CANCEL_RESET (oldtype);
va_end (ap);
return result;
}
strong_alias (__open64, open64)

40
nptl/pt-pause.c Normal file
View File

@ -0,0 +1,40 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <unistd.h>
#include "pthreadP.h"
int
pause (void)
{
int oldtype;
int result;
CANCEL_ASYNC (oldtype);
result = __libc_pause ();
CANCEL_RESET (oldtype);
return result;
}

44
nptl/pt-poll.c Normal file
View File

@ -0,0 +1,44 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/poll.h>
#include "pthreadP.h"
int
poll (struct pollfd *fds, nfds_t nfds, int timeout)
{
int result;
int oldtype;
CANCEL_ASYNC (oldtype);
#ifdef INLINE_SYSCALL
result = INLINE_SYSCALL (poll, 3, fds, nfds, timeout);
#else
result = __poll (fds, nfds, timeout);
#endif
CANCEL_RESET (oldtype);
return result;
}

40
nptl/pt-pread.c Normal file
View File

@ -0,0 +1,40 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <unistd.h>
#include "pthreadP.h"
ssize_t
pread (int fd, void *buf, size_t count, off_t offset)
{
int oldtype;
ssize_t result;
CANCEL_ASYNC (oldtype);
result = __libc_pread (fd, buf, count, offset);
CANCEL_RESET (oldtype);
return result;
}

41
nptl/pt-pread64.c Normal file
View File

@ -0,0 +1,41 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <unistd.h>
#include "pthreadP.h"
ssize_t
__pread64 (int fd, void *buf, size_t count, off64_t offset)
{
int oldtype;
ssize_t result;
CANCEL_ASYNC (oldtype);
result = __libc_pread64 (fd, buf, count, offset);
CANCEL_RESET (oldtype);
return result;
}
strong_alias (__pread64, pread64)

41
nptl/pt-pselect.c Normal file
View File

@ -0,0 +1,41 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/select.h>
#include "pthreadP.h"
int
pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
const struct timespec *timeout, const sigset_t *sigmask)
{
int result;
int oldtype;
CANCEL_ASYNC (oldtype);
result = __pselect (nfds, readfds, writefds, exceptfds, timeout, sigmask);
CANCEL_RESET (oldtype);
return result;
}

40
nptl/pt-pwrite.c Normal file
View File

@ -0,0 +1,40 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <unistd.h>
#include "pthreadP.h"
ssize_t
pwrite (int fd, const void *buf, size_t count, off_t offset)
{
int oldtype;
ssize_t result;
CANCEL_ASYNC (oldtype);
result = __libc_pwrite (fd, buf, count, offset);
CANCEL_RESET (oldtype);
return result;
}

41
nptl/pt-pwrite64.c Normal file
View File

@ -0,0 +1,41 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <unistd.h>
#include "pthreadP.h"
ssize_t
__pwrite64 (int fd, const void *buf, size_t count, off64_t offset)
{
int oldtype;
ssize_t result;
CANCEL_ASYNC (oldtype);
result = __libc_pwrite64 (fd, buf, count, offset);
CANCEL_RESET (oldtype);
return result;
}
strong_alias (__pwrite64, pwrite64)

45
nptl/pt-read.c Normal file
View File

@ -0,0 +1,45 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <unistd.h>
#include "pthreadP.h"
ssize_t
__read (int fd, void *buf, size_t count)
{
int oldtype;
ssize_t result;
CANCEL_ASYNC (oldtype);
#ifdef INLINE_SYSCALL
result = INLINE_SYSCALL (read, 3, fd, buf, count);
#else
result = __libc_read (fd, buf, count);
#endif
CANCEL_RESET (oldtype);
return result;
}
strong_alias (__read, read)

58
nptl/pt-readv.c Normal file
View File

@ -0,0 +1,58 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/uio.h>
#include "pthreadP.h"
/* Not all versions of the kernel support the large number of records. */
#ifndef UIO_FASTIOV
# define UIO_FASTIOV 8 /* 8 is a safe number. */
#endif
ssize_t
readv (fd, vector, count)
int fd;
const struct iovec *vector;
int count;
{
int oldtype;
ssize_t result;
CANCEL_ASYNC (oldtype);
#ifdef INTERNAL_SYSCALL
result = INTERNAL_SYSCALL (readv, 3, fd, vector, count);
if (INTERNAL_SYSCALL_ERROR_P (result)
&& __builtin_expect (count > UIO_FASTIOV, 0))
#elif defined INLINE_SYSCALL
result = INLINE_SYSCALL (readv, 3, fd, vector, count);
if (result < 0 && errno == EINVAL
&& __builtin_expect (count > UIO_FASTIOV, 0))
#endif
result = __libc_readv (fd, vector, count);
CANCEL_RESET (oldtype);
return result;
}

40
nptl/pt-recv.c Normal file
View File

@ -0,0 +1,40 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/socket.h>
#include "pthreadP.h"
ssize_t
recv (int fd, __ptr_t buf, size_t n, int flags)
{
int oldtype;
ssize_t result;
CANCEL_ASYNC (oldtype);
result = __libc_recv (fd, buf, n, flags);
CANCEL_RESET (oldtype);
return result;
}

41
nptl/pt-recvfrom.c Normal file
View File

@ -0,0 +1,41 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/socket.h>
#include "pthreadP.h"
ssize_t
recvfrom (int fd, __ptr_t buf, size_t n, int flags, __SOCKADDR_ARG addr,
socklen_t *addr_len)
{
int oldtype;
ssize_t result;
CANCEL_ASYNC (oldtype);
result = __libc_recvfrom (fd, buf, n, flags, addr, addr_len);
CANCEL_RESET (oldtype);
return result;
}

40
nptl/pt-recvmsg.c Normal file
View File

@ -0,0 +1,40 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/socket.h>
#include "pthreadP.h"
ssize_t
recvmsg (int fd, struct msghdr *message, int flags)
{
int oldtype;
ssize_t result;
CANCEL_ASYNC (oldtype);
result = __libc_recvmsg (fd, message, flags);
CANCEL_RESET (oldtype);
return result;
}

46
nptl/pt-select.c Normal file
View File

@ -0,0 +1,46 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <unistd.h>
#include "pthreadP.h"
int
select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout)
{
int result;
int oldtype;
CANCEL_ASYNC (oldtype);
#if defined INLINE_SYSCALL && defined __NR__newselect
result = INLINE_SYSCALL (_newselect, 5, nfds, readfds, writefds, exceptfds,
timeout);
#else
result = __select (nfds, readfds, writefds, exceptfds, timeout);
#endif
CANCEL_RESET (oldtype);
return result;
}

41
nptl/pt-send.c Normal file
View File

@ -0,0 +1,41 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/socket.h>
#include "pthreadP.h"
ssize_t
__send (int fd, const __ptr_t buf, size_t n, int flags)
{
int oldtype;
ssize_t result;
CANCEL_ASYNC (oldtype);
result = __libc_send (fd, buf, n, flags);
CANCEL_RESET (oldtype);
return result;
}
strong_alias (__send, send)

40
nptl/pt-sendmsg.c Normal file
View File

@ -0,0 +1,40 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/socket.h>
#include "pthreadP.h"
ssize_t
sendmsg (int fd, const struct msghdr *message, int flags)
{
int oldtype;
ssize_t result;
CANCEL_ASYNC (oldtype);
result = __libc_sendmsg (fd, message, flags);
CANCEL_RESET (oldtype);
return result;
}

41
nptl/pt-sendto.c Normal file
View File

@ -0,0 +1,41 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/socket.h>
#include "pthreadP.h"
ssize_t
sendto (int fd, const __ptr_t buf, size_t n, int flags,
__CONST_SOCKADDR_ARG addr, socklen_t addr_len)
{
int oldtype;
ssize_t result;
CANCEL_ASYNC (oldtype);
result = __libc_sendto (fd, buf, n, flags, addr, addr_len);
CANCEL_RESET (oldtype);
return result;
}

32
nptl/pt-siglongjmp.c Normal file
View File

@ -0,0 +1,32 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <setjmp.h>
#include "pthreadP.h"
void
siglongjmp (sigjmp_buf env, int val)
{
/* XXX Do we have to reset the signal mask before calling the
destructors. */
__pthread_cleanup_upto (env->__jmpbuf);
__libc_siglongjmp (env, val);
}

41
nptl/pt-sigpause.c Normal file
View File

@ -0,0 +1,41 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include <sysdep.h>
#include "pthreadP.h"
#undef sigpause
int
sigpause (int mask)
{
int oldtype;
int result;
CANCEL_ASYNC (oldtype);
result = sigpause (mask);
CANCEL_RESET (oldtype);
return result;
}

44
nptl/pt-sigsuspend.c Normal file
View File

@ -0,0 +1,44 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <sysdep.h>
#include "pthreadP.h"
int
sigsuspend (const sigset_t *set)
{
int result;
int oldtype;
CANCEL_ASYNC (oldtype);
#ifdef INLINE_SYSCALL
result = INLINE_SYSCALL (rt_sigsuspend, 2, set, _NSIG / 8);
#else
result = __sigsuspend (set);
#endif
CANCEL_RESET (oldtype);
return result;
}

45
nptl/pt-sigtimedwait.c Normal file
View File

@ -0,0 +1,45 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <sysdep.h>
#include "pthreadP.h"
int
sigtimedwait (const sigset_t *set, siginfo_t *info,
const struct timespec *timeout)
{
int result;
int oldtype;
CANCEL_ASYNC (oldtype);
#ifdef INLINE_SYSCALL
result = INLINE_SYSCALL (rt_sigtimedwait, 4, set, info, timeout, _NSIG / 8);
#else
result = __sigtimedwait (set, info, timeout);
#endif
CANCEL_RESET (oldtype);
return result;
}

60
nptl/pt-sigwait.c Normal file
View File

@ -0,0 +1,60 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <sysdep.h>
#include "pthreadP.h"
int
sigwait (const sigset_t *set, int *sig)
{
int result;
int oldtype;
CANCEL_ASYNC (oldtype);
#ifdef INTERNAL_SYSCALL
result = INTERNAL_SYSCALL (rt_sigtimedwait, 4, set, NULL, NULL, _NSIG / 8);
if (! INTERNAL_SYSCALL_ERROR_P (result))
{
*sig = result;
result = 0;
}
else
result = INTERNAL_SYSCALL_ERRNO (result);
#elif defined INLINE_SYSCALL
result = INLINE_SYSCALL (rt_sigtimedwait, 4, set, NULL, NULL, _NSIG / 8);
if (result != -1)
{
*sig = result;
result = 0;
}
else
result = errno;
#else
result = __sigwait (set, sig);
#endif
CANCEL_RESET (oldtype);
return result;
}

44
nptl/pt-sigwaitinfo.c Normal file
View File

@ -0,0 +1,44 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <sysdep.h>
#include "pthreadP.h"
int
sigwaitinfo (const sigset_t *set, siginfo_t *info)
{
int result;
int oldtype;
CANCEL_ASYNC (oldtype);
#ifdef INLINE_SYSCALL
result = INLINE_SYSCALL (rt_sigtimedwait, 4, set, info, NULL, _NSIG / 8);
#else
result = __sigwaitinfo (set, info);
#endif
CANCEL_RESET (oldtype);
return result;
}

40
nptl/pt-system.c Normal file
View File

@ -0,0 +1,40 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <stdlib.h>
#include "pthreadP.h"
int
system (const char *line)
{
int oldtype;
int result;
CANCEL_ASYNC (oldtype);
result = __libc_system (line);
CANCEL_RESET (oldtype);
return result;
}

40
nptl/pt-tcdrain.c Normal file
View File

@ -0,0 +1,40 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <termios.h>
#include "pthreadP.h"
int
tcdrain (int fd)
{
int oldtype;
int result;
CANCEL_ASYNC (oldtype);
result = __libc_tcdrain (fd);
CANCEL_RESET (oldtype);
return result;
}

41
nptl/pt-wait.c Normal file
View File

@ -0,0 +1,41 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/wait.h>
#include "pthreadP.h"
pid_t
__wait (__WAIT_STATUS_DEFN stat_loc)
{
int oldtype;
pid_t result;
CANCEL_ASYNC (oldtype);
result = __libc_wait (stat_loc);
CANCEL_RESET (oldtype);
return result;
}
strong_alias (__wait, wait)

41
nptl/pt-waitid.c Normal file
View File

@ -0,0 +1,41 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/wait.h>
#include "pthreadP.h"
int
waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
{
int oldtype;
int result;
CANCEL_ASYNC (oldtype);
result = __waitid (idtype, id, infop, options);
CANCEL_RESET (oldtype);
return result;
}
strong_alias (__wait, wait)

40
nptl/pt-waitpid.c Normal file
View File

@ -0,0 +1,40 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/wait.h>
#include "pthreadP.h"
pid_t
waitpid (pid_t pid, int *stat_loc, int options)
{
int oldtype;
pid_t result;
CANCEL_ASYNC (oldtype);
result = __libc_waitpid (pid, stat_loc, options);
CANCEL_RESET (oldtype);
return result;
}

45
nptl/pt-write.c Normal file
View File

@ -0,0 +1,45 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <unistd.h>
#include "pthreadP.h"
ssize_t
__write (int fd, const void *buf, size_t count)
{
int oldtype;
ssize_t result;
CANCEL_ASYNC (oldtype);
#ifdef INLINE_SYSCALL
result = INLINE_SYSCALL (write, 3, fd, buf, count);
#else
result = __libc_write (fd, buf, count);
#endif
CANCEL_RESET (oldtype);
return result;
}
strong_alias (__write, write)

58
nptl/pt-writev.c Normal file
View File

@ -0,0 +1,58 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include <stdlib.h>
#include <sysdep.h>
#include <sys/uio.h>
#include "pthreadP.h"
/* Not all versions of the kernel support the large number of records. */
#ifndef UIO_FASTIOV
# define UIO_FASTIOV 8 /* 8 is a safe number. */
#endif
ssize_t
writev (fd, vector, count)
int fd;
const struct iovec *vector;
int count;
{
int oldtype;
ssize_t result;
CANCEL_ASYNC (oldtype);
#ifdef INTERNAL_SYSCALL
result = INTERNAL_SYSCALL (writev, 3, fd, vector, count);
if (INTERNAL_SYSCALL_ERROR_P (result)
&& __builtin_expect (count > UIO_FASTIOV, 0))
#elif defined INLINE_SYSCALL
result = INLINE_SYSCALL (writev, 3, fd, vector, count);
if (result < 0 && errno == EINVAL
&& __builtin_expect (count > UIO_FASTIOV, 0))
#endif
result = __libc_writev (fd, vector, count);
CANCEL_RESET (oldtype);
return result;
}

182
nptl/pthreadP.h Normal file
View File

@ -0,0 +1,182 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#ifndef _PTHREADP_H
#define _PTHREADP_H 1
#include <pthread.h>
#include <setjmp.h>
#include <stdint.h>
#include <sys/syscall.h>
#include "descr.h"
#include <tls.h>
#include <lowlevellock.h>
#include <stackinfo.h>
#include <internaltypes.h>
/* Internal variables. */
/* Default stack size. */
extern size_t __default_stacksize attribute_hidden;
/* Size and alignment of static TLS block. */
extern size_t __static_tls_size attribute_hidden;
extern size_t __static_tls_align attribute_hidden;
/* Thread descriptor handling. */
extern list_t __stack_user attribute_hidden;
/* Attribute handling. */
extern struct pthread_attr *__attr_list attribute_hidden;
extern lll_lock_t __attr_list_lock attribute_hidden;
/* First available RT signal. */
extern int __current_sigrtmin attribute_hidden;
/* Last available RT signal. */
extern int __current_sigrtmax attribute_hidden;
/* Concurrency handling. */
extern int __concurrency_level attribute_hidden;
/* Thread-local data key handling. */
extern struct pthread_key_struct __pthread_keys[PTHREAD_KEYS_MAX]
attribute_hidden;
/* The library can run in debugging mode where it performs a lot more
tests. */
extern int __pthread_debug attribute_hidden;
#define DEBUGGING_P __builtin_expect (__pthread_debug, 0)
/* Cancellation test. */
#define CANCELLATION_P(self) \
do { \
int cancelhandling = THREAD_GETMEM (self, cancelhandling); \
if (CANCEL_ENABLED_AND_CANCELED (cancelhandling)) \
{ \
THREAD_SETMEM (self, result, PTHREAD_CANCELED); \
__do_cancel (CURRENT_STACK_FRAME); \
} \
} while (0)
/* Set cancellation mode to asynchronous. */
#define CANCEL_ASYNC(oldtype) \
pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype)
/* Reset to previous cancellation mode. */
#define CANCEL_RESET(oldtype) \
pthread_setcanceltype (oldtype, NULL)
/* Function performing the cancellation. */
extern void __do_cancel (char *currentframe)
__attribute ((visibility ("hidden"), noreturn, regparm (1)));
extern void __cleanup_thread (struct pthread *self, char *currentframe)
__attribute ((visibility ("hidden"), regparm (2)));
/* Test whether stackframe is still active. */
#ifdef _STACK_GROWS_DOWN
# define FRAME_LEFT(frame, other) ((char *) frame >= (char *) other)
#elif _STACK_GROWS_UP
# define FRAME_LEFT(frame, other) ((char *) frame <= (char *) other)
#else
# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
#endif
/* Internal prototypes. */
/* Thread list handling. */
extern struct pthread *__find_in_stack_list (struct pthread *pd)
attribute_hidden;
/* Deallocate a thread's stack after optionally making sure the thread
descriptor is still valid. */
extern void __free_tcb (struct pthread *pd) attribute_hidden;
/* Free allocated stack. */
extern void __deallocate_stack (struct pthread *pd) attribute_hidden;
/* Mark all the stacks except for the current one as available. This
function also re-initializes the lock for the stack cache. */
extern void __reclaim_stacks (void) attribute_hidden;
/* longjmp handling. */
extern void __pthread_cleanup_upto (__jmp_buf target, char *targetframe);
/* Functions with versioned interfaces. */
extern int __pthread_create_2_1 (pthread_t *newthread,
const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg);
extern int __pthread_create_2_0 (pthread_t *newthread,
const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg);
extern int __pthread_attr_init_2_1 (pthread_attr_t *attr);
extern int __pthread_attr_init_2_0 (pthread_attr_t *attr);
/* Event handlers for libthread_db interface. */
extern void __nptl_create_event (void) attribute_hidden;
extern void __nptl_death_event (void) attribute_hidden;
/* Namespace save aliases. */
extern int __pthread_mutex_init (pthread_mutex_t *__mutex,
__const pthread_mutexattr_t *__mutexattr);
extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex);
extern int __pthread_mutex_trylock (pthread_mutex_t *_mutex);
extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex);
extern int __pthread_mutexattr_init (pthread_mutexattr_t *attr);
extern int __pthread_mutexattr_destroy (pthread_mutexattr_t *attr);
extern int __pthread_mutexattr_settype (pthread_mutexattr_t *attr, int kind);
extern int __pthread_attr_getstackaddr (__const pthread_attr_t *__restrict
__attr, void **__restrict __stackaddr);
extern int __pthread_attr_setstackaddr (pthread_attr_t *__attr,
void *__stackaddr);
extern int __pthread_attr_getstacksize (__const pthread_attr_t *__restrict
__attr,
size_t *__restrict __stacksize);
extern int __pthread_attr_setstacksize (pthread_attr_t *__attr,
size_t __stacksize);
extern int __pthread_attr_getstack (__const pthread_attr_t *__restrict __attr,
void **__restrict __stackaddr,
size_t *__restrict __stacksize);
extern int __pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
size_t __stacksize);
extern int __pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
__const pthread_rwlockattr_t *__restrict
__attr);
extern int __pthread_rwlock_destroy (pthread_rwlock_t *__rwlock);
extern int __pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock);
extern int __pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock);
extern int __pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock);
extern int __pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock);
extern int __pthread_rwlock_unlock (pthread_rwlock_t *__rwlock);
extern int __pthread_key_create (pthread_key_t *key, void (*destr) (void *));
extern void *__pthread_getspecific (pthread_key_t key);
extern int __pthread_setspecific (pthread_key_t key, const void *value);
extern int __pthread_once (pthread_once_t *once_control,
void (*init_routine) (void));
extern int __pthread_atfork (void (*prepare) (void), void (*parent) (void),
void (*child) (void));
#endif /* pthreadP.h */

46
nptl/pthread_atfork.c Normal file
View File

@ -0,0 +1,46 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include "pthreadP.h"
#include <fork.h>
/* This is defined by newer gcc version unique for each module. */
extern void *__dso_handle __attribute__ ((__weak__));
/* Hide the symbol so that no definition but the one locally in the
executable or DSO is used. */
int
#ifndef __pthread_atfork
/* Don't mark the compatibility function as hidden. */
attribute_hidden
#endif
__pthread_atfork (prepare, parent, child)
void (*prepare) (void);
void (*parent) (void);
void (*child) (void);
{
return __register_atfork (prepare, parent, child,
&__dso_handle == NULL ? NULL : __dso_handle);
}
#ifndef __pthread_atfork
extern int pthread_atfork (void (*prepare) (void), void (*parent) (void),
void (*child) (void)) attribute_hidden;
strong_alias (__pthread_atfork, pthread_atfork)
#endif

View File

@ -0,0 +1,66 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "pthreadP.h"
int
pthread_attr_destroy (attr)
pthread_attr_t *attr;
{
/* Enqueue the attributes to the list of all known variables. */
if (DEBUGGING_P)
{
struct pthread_attr *iattr;
struct pthread_attr *prevp = NULL;
struct pthread_attr *runp;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
lll_lock (__attr_list_lock);
runp = __attr_list;
while (runp != NULL && runp != iattr)
{
prevp = runp;
runp = runp->next;
}
if (runp != NULL)
{
if (prevp == NULL)
__attr_list = iattr->next;
else
prevp->next = iattr->next;
}
lll_unlock (__attr_list_lock);
if (runp == NULL)
/* Not a valid attribute. */
return EINVAL;
}
return 0;
}

View File

@ -0,0 +1,38 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include "pthreadP.h"
int
pthread_attr_getdetachstate (attr, detachstate)
const pthread_attr_t *attr;
int *detachstate;
{
struct pthread_attr *iattr;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
*detachstate = (iattr->flags & ATTR_FLAG_DETACHSTATE
? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE);
return 0;
}

View File

@ -0,0 +1,37 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include "pthreadP.h"
int
pthread_attr_getguardsize (attr, guardsize)
const pthread_attr_t *attr;
size_t *guardsize;
{
struct pthread_attr *iattr;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
*guardsize = iattr->guardsize;
return 0;
}

View File

@ -0,0 +1,39 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include "pthreadP.h"
int
pthread_attr_getinheritsched (attr, inherit)
const pthread_attr_t *attr;
int *inherit;
{
struct pthread_attr *iattr;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
/* Store the current values. */
*inherit = (iattr->flags & ATTR_FLAG_NOTINHERITSCHED
? PTHREAD_EXPLICIT_SCHED : PTHREAD_INHERIT_SCHED);
return 0;
}

View File

@ -0,0 +1,39 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include <string.h>
#include "pthreadP.h"
int
pthread_attr_getschedparam (attr, param)
const pthread_attr_t *attr;
struct sched_param *param;
{
struct pthread_attr *iattr;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
/* Copy the current values. */
memcpy (param, &iattr->schedparam, sizeof (struct sched_param));
return 0;
}

View File

@ -0,0 +1,38 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include "pthreadP.h"
int
pthread_attr_getschedpolicy (attr, policy)
const pthread_attr_t *attr;
int *policy;
{
struct pthread_attr *iattr;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
/* Store the current values. */
*policy = iattr->schedpolicy;
return 0;
}

View File

@ -0,0 +1,39 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include "pthreadP.h"
int
pthread_attr_getscope (attr, scope)
const pthread_attr_t *attr;
int *scope;
{
struct pthread_attr *iattr;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
/* Store the current values. */
*scope = (iattr->flags & ATTR_FLAG_SCOPEPROCESS
? PTHREAD_SCOPE_PROCESS : PTHREAD_SCOPE_SYSTEM);
return 0;
}

View File

@ -0,0 +1,41 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include "pthreadP.h"
int
__pthread_attr_getstack (attr, stackaddr, stacksize)
const pthread_attr_t *attr;
void **stackaddr;
size_t *stacksize;
{
struct pthread_attr *iattr;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
/* Store the result. */
*stackaddr = (char *) iattr->stackaddr - iattr->stacksize;
*stacksize = iattr->stacksize;
return 0;
}
strong_alias (__pthread_attr_getstack, pthread_attr_getstack)

View File

@ -0,0 +1,49 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include <errno.h>
#include "pthreadP.h"
int
__pthread_attr_getstackaddr (attr, stackaddr)
const pthread_attr_t *attr;
void **stackaddr;
{
struct pthread_attr *iattr;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
/* XXX This function has a stupid definition. The standard
specifies no error value but what is if no stack address was set?
We return an error anyway. */
if ((iattr->flags & ATTR_FLAG_STACKADDR) == 0)
return EINVAL;
/* Store the result. */
*stackaddr = iattr->stackaddr;
return 0;
}
strong_alias (__pthread_attr_getstackaddr, pthread_attr_getstackaddr)
link_warning (pthread_attr_getstackaddr,
"the use of `pthread_attr_getstackaddr' is deprecated, use `pthread_attr_getstack'")

View File

@ -0,0 +1,40 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include "pthreadP.h"
int
__pthread_attr_getstacksize (attr, stacksize)
const pthread_attr_t *attr;
size_t *stacksize;
{
struct pthread_attr *iattr;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
/* If the user has not set a stack size we return what the system
will use as the default. */
*stacksize = iattr->stacksize ?: __default_stacksize;
return 0;
}
strong_alias (__pthread_attr_getstacksize, pthread_attr_getstacksize)

97
nptl/pthread_attr_init.c Normal file
View File

@ -0,0 +1,97 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "pthreadP.h"
#include <shlib-compat.h>
struct pthread_attr *__attr_list;
lll_lock_t __attr_list_lock = LLL_LOCK_INITIALIZER;
int
__pthread_attr_init_2_1 (attr)
pthread_attr_t *attr;
{
struct pthread_attr *iattr;
/* Many elements are initialized to zero so let us do it all at
once. This also takes care of clearing the bytes which are not
internally used. */
memset (attr, '\0', __SIZEOF_PTHREAD_ATTR_T);
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
/* Default guard size specified by the standard. */
iattr->guardsize = __getpagesize ();
/* Enqueue the attributes to the list of all known variables. */
if (DEBUGGING_P)
{
lll_lock (__attr_list_lock);
iattr->next = __attr_list;
__attr_list = iattr;
lll_unlock (__attr_list_lock);
}
return 0;
}
versioned_symbol (libpthread, __pthread_attr_init_2_1, pthread_attr_init,
GLIBC_2_1);
#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
int
__pthread_attr_init_2_0 (attr)
pthread_attr_t *attr;
{
/* This code is specific to the old LinuxThread code which has a too
small pthread_attr_t definition. The struct looked like
this: */
struct old_attr
{
int detachstate;
int schedpolicy;
struct sched_param schedparam;
int inheritsched;
int scope;
} *iattr;
/* Many elements are initialized to zero so let us do it all at
once. This also takes care of clearing the bytes which are not
internally used. */
memset (attr, '\0', sizeof (struct old_attr));
iattr = (struct old_attr *) attr;
/* We cannot enqueue the attribute because that member is not in the
old attribute structure. */
return 0;
}
compat_symbol (libpthread, __pthread_attr_init_2_0, pthread_attr_init,
GLIBC_2_0);
#endif

View File

@ -0,0 +1,47 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include <errno.h>
#include "pthreadP.h"
int
pthread_attr_setdetachstate (attr, detachstate)
pthread_attr_t *attr;
int detachstate;
{
struct pthread_attr *iattr;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
/* Catch invalid values. */
if (detachstate != PTHREAD_CREATE_DETACHED
&& __builtin_expect (detachstate != PTHREAD_CREATE_JOINABLE, 0))
return EINVAL;
/* Set the flag. It is nonzero if threads are created detached. */
if (detachstate == PTHREAD_CREATE_DETACHED)
iattr->flags |= ATTR_FLAG_DETACHSTATE;
else
iattr->flags &= ~ATTR_FLAG_DETACHSTATE;
return 0;
}

View File

@ -0,0 +1,40 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include "pthreadP.h"
int
pthread_attr_setguardsize (attr, guardsize)
pthread_attr_t *attr;
size_t guardsize;
{
struct pthread_attr *iattr;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
/* Note that we don't round the value here. The standard requires
that subsequent pthread_attr_getguardsize calls return the value
set by the user. */
iattr->guardsize = guardsize;
return 0;
}

View File

@ -0,0 +1,46 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include <errno.h>
#include "pthreadP.h"
int
pthread_attr_setinheritsched (attr, inherit)
pthread_attr_t *attr;
int inherit;
{
struct pthread_attr *iattr;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
/* Catch invalid values. */
if (inherit != PTHREAD_INHERIT_SCHED && inherit != PTHREAD_EXPLICIT_SCHED)
return EINVAL;
/* Store the new values. */
if (inherit != PTHREAD_INHERIT_SCHED)
iattr->flags |= ATTR_FLAG_NOTINHERITSCHED;
else
iattr->flags &= ~ATTR_FLAG_NOTINHERITSCHED;
return 0;
}

View File

@ -0,0 +1,49 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include <errno.h>
#include <string.h>
#include "pthreadP.h"
int
pthread_attr_setschedparam (attr, param)
pthread_attr_t *attr;
const struct sched_param *param;
{
struct pthread_attr *iattr;
int max_prio;
int min_prio;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
max_prio = __sched_get_priority_max (iattr->schedpolicy);
min_prio = __sched_get_priority_min (iattr->schedpolicy);
/* Catch invalid values. */
if (param->sched_priority < min_prio || param->sched_priority > max_prio)
return EINVAL;
/* Copy the new values. */
memcpy (&iattr->schedparam, param, sizeof (struct sched_param));
return 0;
}

View File

@ -0,0 +1,43 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include <errno.h>
#include "pthreadP.h"
int
pthread_attr_setschedpolicy (attr, policy)
pthread_attr_t *attr;
int policy;
{
struct pthread_attr *iattr;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
/* Catch invalid values. */
if (policy != SCHED_OTHER && policy != SCHED_FIFO && policy != SCHED_RR)
return EINVAL;
/* Store the new values. */
iattr->schedpolicy = policy;
return 0;
}

View File

@ -0,0 +1,50 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include <errno.h>
#include "pthreadP.h"
int
pthread_attr_setscope (attr, scope)
pthread_attr_t *attr;
int scope;
{
struct pthread_attr *iattr;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
/* Catch invalid values. */
switch (scope)
{
case PTHREAD_SCOPE_SYSTEM:
iattr->flags &= ~ATTR_FLAG_SCOPEPROCESS;
break;
case PTHREAD_SCOPE_PROCESS:
return ENOTSUP;
default:
return EINVAL;
}
return 0;
}

View File

@ -0,0 +1,47 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include "pthreadP.h"
int
__pthread_attr_setstack (attr, stackaddr, stacksize)
pthread_attr_t *attr;
void *stackaddr;
size_t stacksize;
{
struct pthread_attr *iattr;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
/* Catch invalid sizes. */
if (stacksize < PTHREAD_STACK_MIN)
return EINVAL;
iattr->stacksize = stacksize;
iattr->stackaddr = (char *) stackaddr + stacksize;
iattr->flags |= ATTR_FLAG_STACKADDR;
return 0;
}
strong_alias (__pthread_attr_setstack, pthread_attr_setstack)

View File

@ -0,0 +1,43 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include <errno.h>
#include "pthreadP.h"
int
__pthread_attr_setstackaddr (attr, stackaddr)
pthread_attr_t *attr;
void *stackaddr;
{
struct pthread_attr *iattr;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
iattr->stackaddr = stackaddr;
iattr->flags |= ATTR_FLAG_STACKADDR;
return 0;
}
strong_alias (__pthread_attr_setstackaddr, pthread_attr_setstackaddr)
link_warning (pthread_attr_setstackaddr,
"the use of `pthread_attr_setstackaddr' is deprecated, use `pthread_attr_setstack'")

View File

@ -0,0 +1,44 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include "pthreadP.h"
int
__pthread_attr_setstacksize (attr, stacksize)
pthread_attr_t *attr;
size_t stacksize;
{
struct pthread_attr *iattr;
assert (sizeof (*attr) >= sizeof (struct pthread_attr));
iattr = (struct pthread_attr *) attr;
/* Catch invalid sizes. */
if (stacksize < PTHREAD_STACK_MIN)
return EINVAL;
iattr->stacksize = stacksize;
return 0;
}
strong_alias (__pthread_attr_setstacksize, pthread_attr_setstacksize)

View File

@ -0,0 +1,44 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include "pthreadP.h"
#include <lowlevellock.h>
int
pthread_barrier_destroy (barrier)
pthread_barrier_t *barrier;
{
struct pthread_barrier *ibarrier;
int result = EBUSY;
ibarrier = (struct pthread_barrier *) barrier;
lll_lock (ibarrier->lock);
if (__builtin_expect (ibarrier->left == ibarrier->init_count, 1))
/* The barrier is not used anymore. */
result = 0;
else
/* Still used, return with an error. */
lll_unlock (ibarrier->lock);
return result;
}

View File

@ -0,0 +1,57 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <errno.h>
#include "pthreadP.h"
#include <lowlevellock.h>
int
pthread_barrier_init (barrier, attr, count)
pthread_barrier_t *barrier;
const pthread_barrierattr_t *attr;
unsigned int count;
{
struct pthread_barrier *ibarrier;
if (__builtin_expect (count == 0, 0))
return EINVAL;
if (attr != NULL)
{
struct pthread_barrierattr *iattr;
iattr = (struct pthread_barrierattr *) attr;
if (iattr->pshared != PTHREAD_PROCESS_PRIVATE
&& __builtin_expect (iattr->pshared != PTHREAD_PROCESS_SHARED, 0))
/* Invalid attribute. */
return EINVAL;
}
ibarrier = (struct pthread_barrier *) barrier;
/* Initialize the individual fields. */
ibarrier->lock = LLL_LOCK_INITIALIZER;
ibarrier->left = count;
ibarrier->init_count = count;
ibarrier->curr_event = 0;
return 0;
}

View File

@ -0,0 +1,30 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include "pthreadP.h"
int
pthread_barrierattr_destroy (attr)
pthread_barrierattr_t *attr;
{
/* Nothing to do. */
return 0;
}

Some files were not shown because too many files have changed in this diff Show More