Commit Graph

484 Commits

Author SHA1 Message Date
Doug Rabson
cd7d66a21f Call the fcntl compatiblity wrapper from the thread library fcntl wrappers
so that they get the benefit of the (limited) forward ABI compatibility.

MFC after: 1 week
2008-05-30 14:47:42 +00:00
Christian Brueffer
662cac9f23 Fix some "in in" typos in comments.
PR:		121490
Submitted by:	Anatoly Borodin <anatoly.borodin@gmail.com>
Approved by:	rwatson (mentor), jkoshy
MFC after:	3 days
2008-03-26 07:32:08 +00:00
Dag-Erling Smørgrav
04539c7099 Add missing #include
Spotted by:	tinderbox
Submitted by:	Pietro Cerutti <gahr@gahr.ch>
Pointy hat to:	des
2008-02-06 23:25:29 +00:00
Dag-Erling Smørgrav
0957bb7d29 Add pthread_mutex_isowned_np() here as well; libthr and libkse are supposed
to have identical functionality.

MFC after:	2 weeks
2008-02-06 20:44:29 +00:00
Daniel Eischen
3d6d3ed091 Remove hacks to allow libkse to export its symbols in the LIBTHREAD_1_0
version namespace which was needed before the library version was
bumped.
2007-12-16 23:29:57 +00:00
Daniel Eischen
396a73603d Set the tcb (thread control block) in the child process after a fork.
This protects against a race with an upcall in the parent during the
fork which can clobber the parent's tcb before the vm space is copied
in the child.  The child then gets a corrupted tcb that is either null
or that points to another thread that doesn't exist in the child (after
a fork, only the fork()ing thread exists in the child).

Reported by:	Arno J. Klaassen (arno at heho / snv / jussieu / fr)
2007-12-06 06:04:01 +00:00
Daniel Eischen
eb63e604ea WARNS=3'ify. 2007-11-30 17:20:29 +00:00
Daniel Eischen
0442ae6dc7 Initialize the current thread and signal locks so that sigaction()
will work after a fork().

WARNS=3'ify.
2007-11-30 17:16:14 +00:00
Jason Evans
b6b7fd3e2a Fix pointer dereferencing problems in _pthread_mutex_init_calloc_cb() that
were obscured by pseudo-opaque pthreads API pointer casting.
2007-11-28 00:16:24 +00:00
Jason Evans
e1636e1f97 Add _pthread_mutex_init_calloc_cb() to libthr and libkse, so that malloc(3)
(part of libc) can use pthreads mutexes without causing infinite recursion
during initialization.
2007-11-27 03:16:44 +00:00
David Xu
eb326f14a2 Move the added code in revision 1.26 into function pthread_key_create,
it should be there.
2007-11-26 02:35:17 +00:00
David Xu
4940ef4ad0 MFlibthr:
In _pthread_key_create() ensure that libkse is initialized.
2007-11-19 02:09:07 +00:00
Kris Kennaway
2017a7cdfe Add a new "non-portable" mutex type, PTHREAD_MUTEX_ADAPTIVE_NP. This
is also implemented in glibc and is used by a number of existing
applications (mysql, firefox, etc).

This mutex type is a default mutex with the additional property that
it spins briefly when attempting to acquire a contested lock, doing
trylock operations in userland before entering the kernel to block if
eventually unsuccessful.

The expectation is that applications requesting this mutex type know
that the mutex is likely to be only held for very brief periods, so it
is faster to spin in userland and probably succeed in acquiring the
mutex, than to enter the kernel and sleep, only to be woken up almost
immediately.  This can help significantly in certain cases when
pthread mutexes are heavily contended and held for brief durations
(such as mysql).

Spin up to 200 times before entering the kernel, which represents only
a few us on modern CPUs.  No performance degradation was observed with
this value and it is sufficient to avoid a large performance drop in
mysql performance in the heavily contended pthread mutex case.

The libkse implementation is a NOP.

Reviewed by:      jeff
MFC after:        3 days
2007-10-29 21:01:47 +00:00
Daniel Eischen
00fb440c1a Enable symbol versioning by default. Use WITHOUT_SYMVER to disable it.
Warning, after symbol versioning is enabled, going back is not easy
(use WITHOUT_SYMVER at your own risk).

Change the default thread library to libthr.

There most likely still needs to be a version bump for at least the
thread libraries.  If necessary, this will happen later.
2007-05-13 14:12:40 +00:00
Daniel Eischen
23daef56b3 Catch up with the renaming of the private version namespace. 2007-04-29 15:27:23 +00:00
Daniel Eischen
96c57267f5 Add a reference and lock the target thread when setting its name.
Submitted by:	davidxu (via libthr)
2007-04-23 03:36:14 +00:00
Brian Somers
d5d9eb5095 Oops, fix a typo in the last commit :-/ 2007-03-05 19:00:49 +00:00
Brian Somers
ee12856f1d In the NOTYET code path when a process forks, the remaining
child thread goes back to system scope rather than process
scope.  This allows an ensuing exec() to actually work.

This change was made a year ago here, but I "forgot" to
commit it :(

Approved by:	deischen
MFC after:	3 weeks
2007-03-05 17:47:27 +00:00
Warner Losh
fed32d7544 Remove 3rd clause, renumber, ok per email 2007-01-12 07:26:21 +00:00
Peter Edwards
977e36e94a Clean bound and non-bound pthread structures consistently before
they become candidates for reuse.  Without this fix, some of the
state from a thread structure's previous incarnation could interfere
with its new one. Specifically, a non-bound thread started as
"suspended" (see pthread_attr_setcreatesuspend_np()) might not get
scheduled at all when resumed, as the "active" flag would be set
spuriously.

Reviewed by: deischen@, davidxu@
MFC after: 1 week
2006-12-18 17:08:07 +00:00
David Xu
6f54e82927 If a thread was detached, return EINVAL instead, the error code
is also returned by pthread_detach() if a thread was already
detached, the error code was already documented:

>    [EINVAL]	The implementation has detected that the value speci-
>		fied by thread does not refer to a joinable thread.
2006-11-28 11:05:31 +00:00
Maxim Konovalov
0295184c7e o Remove a cruft prevented libpthread sigaction(2) wrapper to
do its work for SIGINFO.  Always install libpthread signal handler
wrapper for SIGINFO even if user SIG_IGN's or SIG_DFL's it.

SIGINFO has a special meaning for libpthread: when LIBPTHREAD_DEBUG
enviroment variable defined it is used for dumping an information
about threads to /tmp/.

Reported by:	mi
Reviewed by:	deischen
MFC after:	2 weeks
2006-06-09 14:23:40 +00:00
David Xu
0eb14dbdd6 Export offsets of thread signal pending set and signal mask for debugger. 2006-05-17 04:59:59 +00:00
Xin LI
34562de4d5 Unexpand TAILQ_FIRST(foo) == NULL to TAILQ_EMPTY.
Ok'ed by:	davidxu
2006-04-13 03:09:34 +00:00
Dag-Erling Smørgrav
1e5e6f25c5 Bring libpthread up to WARNS level 2.
Reviewed by:	deischen
2006-03-29 05:38:19 +00:00
Dag-Erling Smørgrav
adb19548bd Fix prototype mismatch and use of un-namespaced pthread functions. 2006-03-28 21:50:12 +00:00
Daniel Eischen
2445cd7c11 Use the correct type for and argument. Recent changes to namespace.h
exposed this bug.

Reported by:	kris
2006-03-28 21:07:59 +00:00
Daniel Eischen
e62165c8b0 Add compatibility symbol maps. libpthread (.so.1 and .so.2)
used LIBTHREAD_1_0 as its version definition, but now needs
to define its symbols in the same namespace used by libc.
The compatibility hooks allows you to use libraries and
binaries built and linked to libpthread before libc was
built with symbol versioning.  The shims can be removed if
libpthread is given a version bump.

Reviewed by:	davidxu
2006-03-13 00:59:51 +00:00
Daniel Eischen
4f0d668324 Only catch SIGINFO (for dumping thread states) when LIBPTHREAD_DEBUG
is defined in the environment.

Requested by:	jmg & a few others
2006-03-06 05:02:28 +00:00
Daniel Eischen
f4cd2a5b5c Add some more pthread stubs so that librt can use them.
The thread jump table has been resorted, so you need to
keep libc, libpthread, and libthr in sync.

Submitted by:	xu
2006-03-05 18:10:28 +00:00
Daniel Eischen
aa8eff60a3 Eliminate a race condition in timed waits (cv, mutex, and sleeps).
MFC Candidate.

PR:	93592
2006-02-23 21:34:08 +00:00
Daniel Eischen
9fcaf8a4ab Don't forget to initialize a tailq before using it.
MFC candidate
Noticed by:	luoqi
2006-02-16 01:33:36 +00:00
Jason Evans
90dc795234 Increase the number of spinlocks, since libc's malloc implementation is
about to significantly increase the number of spinlocks used.

Approved by:	markm (mentor)
2006-01-13 06:14:04 +00:00
Jason Evans
52828c0e9c In preparation for a new malloc implementation:
* Add posix_memalign().

  * Move calloc() from calloc.c to malloc.c.  Add a calloc() implementation in
    rtld-elf in order to make the loader happy (even though calloc() isn't
    used in rtld-elf).

  * Add _malloc_prefork() and _malloc_postfork(), and use them instead of
    directly manipulating __malloc_lock.

Approved by:	phk, markm (mentor)
2006-01-12 07:28:21 +00:00
Brian Somers
6632abc8dc For the ``#ifdef NOTYET'' code that allows calling non-async-safe
functions in the child after a fork() from a threaded process,
use __sys_setprocmask() rather than setprocmask() to keep our
signal handling sane.  Without this fix, signals are essentially
ignored in said child and things such as protection violations
result in an endless busy loop.

Reviewed by:	deischen
2006-01-03 15:34:27 +00:00
David Xu
710eb02de0 Include files thr_condattr_pshared.c and thr_mattr_pshare.c. 2005-10-24 05:48:32 +00:00
David Xu
3c86291f25 Add functions pthread_mutexattr_setpshared and pthread_mutexattr_getpshared. 2005-10-24 05:35:40 +00:00
David Xu
b21a55e2d6 Add function pthread_condattr_setpshared and pthread_condattr_getpshared. 2005-10-24 05:35:14 +00:00
Brian Somers
225721f00b Modify the code path of the ifdef NOTYET part of _kse_single_thread():
o  Don't reinitialise the atfork() handler list in the child.  We
   are meant to call the child handler, and on subsequent fork()s
   should call all three functions as normal.
o  Don't reinitialise the thread specific keyed data in the
   child after a fork.  Applications may require this for context.
o  Reinitialise curthread->tlflags after removing ourselves from
   (and reinitialising) the various internal thread lists.
o  Reinitialise __malloc_lock in the child after fork() (to balance
   our explicitly taking the lock prior to the fork()).

With these changes, it is possible to enable the NOTYET code in
thr_kern.c to allow the use of non-async-safe functions after
fork()ing from a threaded program.

Reviewed by:	Daniel Eischen <deischen@freebsd.org>
[_malloc_lock reinitialisation has since been moved to avoid polluting the
!NOTYET code]
2005-09-24 01:19:53 +00:00
Stefan Farfeleder
7e4cbc3a50 Include needed headers that were obtained through <pthread.h>. Sort headers
while here.
2005-09-01 15:21:23 +00:00
Daniel Eischen
f98418eb29 Allocate a thread's tcb last so it is easier to handle failures to
malloc() siginfo.

PR:	85468
2005-08-30 12:42:00 +00:00
Daniel Eischen
f12a8f9703 Handle failure to malloc() part of the thread structure.
PR:	83457
2005-08-29 13:49:18 +00:00
Daniel Eischen
c7c5df6fdb Don't attempt to initialize the rtld lock if it can't be malloc()'d.
PR:	83452
2005-08-29 13:47:42 +00:00
Stefan Farfeleder
ad7c49168f - Prefix MUTEX_TYPE_MAX with PTHREAD_ to avoid namespace pollution.
- Remove the macros MUTEX_TYPE_FAST and MUTEX_TYPE_COUNTING_FAST.

OK'ed by:	deischen
2005-08-19 21:31:42 +00:00
Daniel Eischen
7f2461f315 Add a cancellation point for usleep(). 2005-08-03 00:48:13 +00:00
David Xu
86a07ac068 Fix off-by-one nanosecond in macro TIMESPEC_ADD.
Reviewed by: deischen
Approved by: re (dwhite)
MFC after  : 4 days
2005-06-22 22:35:49 +00:00
Daniel Eischen
0e963ec574 Somewhere along the line, tick accumulation for SA threads was
changed to use the statclock.  Make sure we calculate the value
of a tick correctly in userland.

Noticed by:	Kazuaki Oda <kaakun at highway dot ne dot jp>
2005-02-18 16:07:05 +00:00
Daniel Eischen
888ab0185e Set the default guardsize and stacksize in the default thread
attribute when the library is initialized.
2005-02-15 15:02:11 +00:00
Daniel Eischen
36a1ac2c2e Increase the default stacksizes:
32-bit		64-bit
main thread	  2MB		  4MB
other threads	  1MB		  2MB
2005-02-13 18:38:06 +00:00
Daniel Eischen
de2faa4a12 Don't panic when sigsuspend is interrupted by a cancellation.
PR:	75273
2004-12-19 23:23:43 +00:00