Commit Graph

502 Commits

Author SHA1 Message Date
davidxu
b118d117f4 Add more cpu affinity function's symbols. 2008-03-05 06:56:35 +00:00
davidxu
adf8d28a8f Check actual size of cpuset kernel is using and define underscore version
of API.
2008-03-05 06:55:48 +00:00
davidxu
8ead1ed2f9 If a new thread is created, it inherits current thread's signal masks,
however if current thread is executing cancellation handler, signal
SIGCANCEL may have already been blocked, this is unexpected, unblock the
signal in new thread if this happens.

MFC after: 1 week
2008-03-04 04:28:59 +00:00
davidxu
e0d98325b4 Include cpuset.h, unbreak compiling. 2008-03-04 03:45:11 +00:00
davidxu
7046a9b037 implement pthread_attr_getaffinity_np and pthread_attr_setaffinity_np. 2008-03-04 03:03:24 +00:00
davidxu
f88b971008 Implement functions pthread_getaffinity_np and pthread_setaffinity_np to
get and set thread's cpu affinity mask.
2008-03-03 09:16:29 +00:00
des
c5334cac08 _pthread_mutex_isowned_np(): use a more reliable method; the current code
will work in simple cases, but may fail in more complicated ones.

Reviewed by:	davidxu
2008-02-14 12:37:58 +00:00
obrien
d3499a87ee style.Makefile(5) 2008-02-13 05:25:43 +00:00
obrien
d8f894d961 style(9) 2008-02-13 05:12:05 +00:00
des
ddda03a2e0 Yet another pointy hat: when I zapped FBSDprivate_1.1, I forgot to move
its contents to FBSDprivate_1.0.
2008-02-06 20:45:46 +00:00
des
f006d1f25a Remove unnecessary prototype. 2008-02-06 20:43:19 +00:00
des
3086491df6 Convert pthread.map to the format expected by version_gen.awk, and modify
the Makefile accordingly; libthr now explicitly uses libc's Versions.def.

MFC after:	2 weeks
2008-02-06 20:25:00 +00:00
des
85a226c62d Remove incorrectly added FBSDprivate_1.1 namespace, and move symbols which
are new in FreeBSD 8 to the appropriate namespace.
2008-02-06 20:20:29 +00:00
des
053e111aba Per discussion on -threads, rename _islocked_np() to _isowned_np(). 2008-02-06 19:34:31 +00:00
des
c089534891 After careful consideration (and a brief discussion with attilio@), change
the semantics of pthread_mutex_islocked_np() to return true if and only if
the mutex is held by the current thread.

Obviously, change the regression test to match.

MFC after:	2 weeks
2008-02-04 12:35:23 +00:00
des
72d185548f Add pthread_mutex_islocked_np(), a cheap way to verify that a mutex is
locked.  This is intended primarily to support the userland equivalent
of the various *_ASSERT_LOCKED() macros we have in the kernel.

MFC after:	2 weeks
2008-02-03 22:38:10 +00:00
davidxu
9acb5351ab SYSTEM_SCOPE_ONLY flag is no longer needed, it is the only mode libthr
supports.
2008-01-18 04:29:36 +00:00
davidxu
70ef09a695 sem_post() requires to return -1 on error. 2008-01-07 02:26:29 +00:00
davidxu
cbdadd6e3e call underscore version of pthread_cleanup_pop instead. 2007-12-20 04:40:12 +00:00
davidxu
cd0acadf51 Remove vfork() overloading, it is no longer needed. 2007-12-20 04:32:28 +00:00
davidxu
42e5c27a87 Add function prototypes. 2007-12-17 02:53:11 +00:00
davidxu
5340a5f502 1. Add function pthread_mutex_setspinloops_np to turn a mutex's spin
loop count.
2. Add function pthread_mutex_setyieldloops_np to turn a mutex's yield
   loop count.
3. Make environment variables PTHREAD_SPINLOOPS and PTHREAD_YIELDLOOPS
   to be only used for turnning PTHREAD_MUTEX_ADAPTIVE_NP mutex.
2007-12-14 06:25:57 +00:00
davidxu
50439b0991 Enclose all code for macro ENQUEUE_MUTEX in do while statement, and
add missing brackets.

MFC: after 1 day
2007-12-11 08:00:58 +00:00
jasone
600513aa8d 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
jasone
21bb948195 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
davidxu
e24c6a3904 Simplify code, fix a thread cancellation bug in sem_wait and sem_timedwait. 2007-11-23 05:42:52 +00:00
davidxu
df28d4b72f Reuse nwaiter member field to record number of waiters, in sem_post(),
this should reduce the chance having to do a syscall when there is no
waiter in the semaphore.
2007-11-21 06:01:02 +00:00
davidxu
6a4c1655fd Remove warning level and aliasing restrictions. 2007-11-21 05:29:57 +00:00
davidxu
a0922e4b91 Convert ceiling type to unsigned integer before comparing, fix compiler
warnings.
2007-11-21 05:25:27 +00:00
davidxu
e90ed63757 Add some function prototypes. 2007-11-21 05:23:54 +00:00
davidxu
c63688968a Remove umtx_t definition, use type long directly, add wrapper function
_thr_umtx_wait_uint() for umtx operation UMTX_OP_WAIT_UINT, use the
function in semaphore operations, this fixed compiler warnings.
2007-11-21 05:21:58 +00:00
jb
5582e69034 These are the things that the tinderbox has problems with because it
doesn't use the default CFLAGS which contain -fno-strict-aliasing.

Until the code is cleaned up, just add -fno-strict-aliasing to the
CFLAGS of these for the tinderboxes' sake, allowing the rest of the
tree to have -Werror enabled again.
2007-11-20 02:07:30 +00:00
marius
af79ab51ec In _pthread_key_create() ensure that libthr is initialized. This
fixes a NULL-dereference of curthread when libstdc+ initializes
the exception handling globals on archs we can't use GNU TLS due
to lack of support in binutils 2.15 (i.e. arm and sparc64), yet,
thus making threaded C++ programs compiled with GCC 4.2.1 work
again on these archs.

Reviewed by:	davidxu
MFC after:	3 days
2007-11-06 21:50:43 +00:00
davidxu
c01b764192 Avoid doing adaptive spinning for priority protected mutex, current
implementation always does lock in kernel.
2007-10-31 01:50:48 +00:00
davidxu
674cdbbcee Don't do adaptive spinning if it is running on UP kernel. 2007-10-31 01:44:50 +00:00
davidxu
e199852bb6 Restore revision 1.55, the kris's adaptive mutex type. 2007-10-31 01:37:13 +00:00
kris
9e91eb96b8 Adaptive mutexes should have the same deadlock detection properties that
default (errorcheck) mutexes do.

Noticed by:          davidxu
2007-10-30 09:24:23 +00:00
davidxu
97a20b1db7 Add my recent work of adaptive spin mutex code. Use two environments variable
to tune pthread mutex performance:
1. LIBPTHREAD_SPINLOOPS
	If a pthread mutex is being locked by another thread, this environment
	variable sets total number of spin loops before the current thread
	sleeps in kernel, this saves a syscall overhead if the mutex will be
	unlocked very soon (well written application code).
2. LIBPTHREAD_YIELDLOOPS
	If a pthread mutex is being locked by other threads, this environment
	variable sets total number of sched_yield() loops before the currrent
	thread sleeps in kernel. if a pthread mutex is locked, the current thread
	gives up cpu, but will not sleep in kernel, this means, current thread
	does not set contention bit in mutex, but let lock owner to run again
	if the owner is on kernel's run queue, and when lock owner unlocks the
	mutex, it does not need to enter kernel and do lots of work to resume
	mutex waiters, in some cases, this saves lots of syscall overheads for
	mutex owner.

In my practice, sometimes LIBPTHREAD_YIELDLOOPS can massively improve performance
than LIBPTHREAD_SPINLOOPS, this depends on application. These two environments
are global to all pthread mutex, there is no interface to set them for each
pthread mutex, the default values are zero, this means spinning is turned off
by default.
2007-10-30 05:57:37 +00:00
kris
bbfd76f872 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
ru
8ea97e9ef7 - Stop calling libthr alternative as it's now the default
threading library.

- Now that libpthread is a symlink, it's no longer possible
  to link applications with libpthread and have libmap.conf(5)
  select the desired threading library; applications will be
  linked to the default threading library, libkse or libthr.
  Remove an obsolete paragraph.

- Mention that improvements can be seen compared to libkse.

Reviewed by:	deischen, davidxu
2007-10-22 10:13:38 +00:00
davidxu
5523a9bb34 Use macro THR_CLEANUP_PUSH/POP, they are cheaper than pthread_cleanup_push/pop. 2007-10-16 07:46:15 +00:00
davidxu
38b01da7d2 Reverse the logic of UP and SMP.
Submitted by: jasone
2007-10-16 07:36:02 +00:00
obrien
a1598920aa Tweak the handling of "WITHOUT_LIBPTHREAD". Also remove the accidental
treatment of 'LIBKSE' as an "old style" knob.

Submitted by:	ru
Approved by:	re(kensmith)
2007-10-09 23:31:11 +00:00
ru
08a6766d3a Always install libpthread.* symlinks if at least one of
the threading libraries is built.  This simplifies the
logic in makefiles that need to check if the pthreads
support is present.  It also fixes a bug where we would
build a threading library that we shouldn't have built:
for example, building with WITHOUT_LIBTHR and the default
value of DEFAULT_THREADING_LIB (libthr) would mistakenly
build the libthr library, but not install it.

Approved by:	re (kensmith)
2007-10-01 18:29:55 +00:00
davidxu
52bd1282cd Output error message to STDERR_FILENO.
Approved by: re (bmah)
2007-08-07 04:50:14 +00:00
davidxu
abf8c6f8db Set warning level to 2. 2007-06-08 02:21:13 +00:00
deischen
ff36458e08 Bump library versions in preparation for 7.0.
Ok'd by:	kan
2007-05-21 02:49:08 +00:00
ru
3be5d73f3d Fix a logic bug I re-introduced in my patch I sent to Daniel
that would cause the selected shared threading library to be
overwritten with its 32-bit version on amd64.

PR:		amd64/112509
2007-05-18 12:25:48 +00:00
deischen
7d5de3a8a3 Allow DEFAULT_THREAD_LIB to be set from /etc/src.conf.
Submitted by:	ru
2007-05-17 04:54:35 +00:00
deischen
bf3a79274d 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
davidxu
d97c4f1e52 backout experimental adaptive spinning mutex for product use. 2007-05-09 08:39:33 +00:00
deischen
2a7306fdc5 Use C comments since we now preprocess these files with CPP. 2007-04-29 14:05:22 +00:00
davidxu
2dd85eafce If a thread who's name is being set is not the current thread, use macros
THR_THREAD_LOCK and THR_THREAD_UNLOCK instead, this should fix wrong
lock level problem.

Bug reported by: ed dot maste at gmail dot com
2007-04-05 07:20:31 +00:00
imp
9109b1ceb8 Remove 3rd clause, renumber, ok per email 2007-01-12 07:26:21 +00:00
davidxu
9770c4c640 Insert mutex at tail if it has highest ceiling. 2007-01-05 03:57:11 +00:00
davidxu
dec2b546dd Oops, don't corrupt the list. 2007-01-05 03:33:47 +00:00
davidxu
190109deab Check if the PP mutex is recursive, if we have already locked it, place the
mutex in right order sorted by priority ceiling.
2007-01-05 03:29:15 +00:00
davidxu
d305995d66 get LIBPTHREAD_ADAPTIVE_SPIN early, so it can be used for some global
mutexes.
2006-12-20 05:05:44 +00:00
davidxu
e034ab54f2 Check environment variable PTHREAD_ADAPTIVE_SPIN, if it is set, use
it as a default spin cycle count.
2006-12-20 04:43:34 +00:00
davidxu
ca27871833 - Remove variable _thr_scope_system, all threads are system scope.
- Rename _thr_smp_cpus to boolean variable _thr_is_smp.
- Define CPU_SPINWAIT macro for each arch, only X86 supports it.
2006-12-15 11:52:01 +00:00
davidxu
26cbb63b3f Create inline function _thr_umutex_trylock2 to only try one atomic
operation, if it is failed, we call syscall directly, this saves
one atomic operation per lock contention.
2006-12-14 13:22:02 +00:00
davidxu
229aca4634 Correctly check failed syscall. 2006-12-12 05:26:39 +00:00
davidxu
fcda4340a4 Move checking for c_has_waiters into low level _thr_ucond_signal and
_thr_ucond_broadcast, clear condition variable pointer in cancellation
info after returing from _thr_ucond_wait, since kernel has already
dropped the internal lock, so we don't need to unlock it in cancellation
handler again.
2006-12-12 03:08:49 +00:00
davidxu
33168bd24f test cancel_pending to save a thr_wake call in some specical cases. 2006-12-06 00:15:35 +00:00
davidxu
b01e86cf0a _thr_ucond_wait drops lock, we should pick it up again. 2006-12-05 23:46:11 +00:00
davidxu
3f73376426 the c_has_waiters is lazily updated, temporarily disable the false
alarm code.
2006-12-05 07:23:58 +00:00
davidxu
f26900460b Use ucond to implement barrier. 2006-12-05 06:54:25 +00:00
davidxu
f1f5293365 Add _thr_ucond_init(). 2006-12-05 06:53:44 +00:00
davidxu
19c999e75f Tweak _thr_cancel_leave_defer a bit to fix a possible race. 2006-12-05 05:01:57 +00:00
davidxu
5ad129a10a Fix typo, I was using a wrong header file, and the typo is not detected
by compiler.
2006-12-04 14:27:42 +00:00
davidxu
cbb0fd8174 Use kernel provided userspace condition variable to implement pthread
condition variable.
2006-12-04 14:20:41 +00:00
davidxu
61e0842016 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
ru
815d860c2f - When building world WITHOUT_LIBPTHREAD, link libthr to libpthread.
- Don't build ngctl(8) and cached(8) if threading libs aren't built.
- Fix various issues in a cached(8) makefile.
2006-11-26 14:36:34 +00:00
davidxu
add205129c Eliminate atomic operations in thread cancellation functions, it should
reduce overheads of cancellation points.
2006-11-24 09:57:38 +00:00
davidxu
cc0840138e Move code calculating new inherited priority into single function. 2006-11-11 13:33:47 +00:00
davidxu
e8a2970aaf Don't inherit THR_FLAGS_NEED_SUSPEND for child process, child process
only has one thread, setting the flag can cause the thread to be
suspended and no another thread will resume it.
2006-10-14 13:40:08 +00:00
davidxu
653013bedc o Make _thr_umutex_init a function.
o Eliminate unused parameter for some functions.
o Convert type of first parameter to void * for _thr_umtx_wait
  and _thr_umtx_wake.
2006-10-13 22:31:00 +00:00
davidxu
4fdad8dba6 Use type pthread_state for thread state. 2006-10-13 12:45:21 +00:00
davidxu
d2c57b7fad use rtprio_thread system call to get or set thread priority. 2006-09-21 04:21:30 +00:00
davidxu
e83ab88356 Use return value of _thr_umutex_lock instead of using zero. 2006-09-08 09:29:14 +00:00
davidxu
21e4536026 Replace internal usage of struct umtx with umutex which can supports
real-time if we want, no functionality is changed.
2006-09-06 04:04:10 +00:00
davidxu
567ba06917 Same as pthread_setschedparam, use sizeof(struct sched_param) instead. 2006-09-05 14:39:06 +00:00
davidxu
5b28602728 Pass correct parameter size. 2006-09-05 14:37:22 +00:00
marcel
d21513035e Stylize: avoid using a global register variable. 2006-09-01 21:01:11 +00:00
marcel
2d71eb396a Rename TLS_TP_OFFSET back to TP_OFFSET. The former clashes with rtld. 2006-09-01 06:36:00 +00:00
marcel
1125db3243 Stylize. 2006-09-01 06:15:00 +00:00
marcel
6a1762d589 Stylize. 2006-08-31 23:31:18 +00:00
marcel
5ffd88a18e TLS fixes:
o  The TLS pointer (r2) points 0x7000 after the *end* of the TCB.
o  _rtld_allocate_tls() gets a pointer to the current TCB, not the
   current TLS pointer.
o  _rtld_free_tls() gets the size of the TCB structure.
2006-08-31 19:16:47 +00:00
marcel
c088f26c25 Fix harmless bug: sizeof(tcb) equals sizeof(void*) not sizeof(struct tcb).
The argument is (currently) not used by _rtld_free_tls().
2006-08-31 19:06:30 +00:00
marcel
4736b1fdce o Set TP using inline assembly to avoid dead code elimination.
o  Eliminate _tcb.
2006-08-30 03:31:32 +00:00
davidxu
37473cc569 Remove unused file. 2006-08-29 13:01:23 +00:00
davidxu
faa99f1910 pthread_sigmask is in thr_sig.c, remove this file. 2006-08-28 12:29:54 +00:00
davidxu
b7dde83f82 Kill unused files. 2006-08-28 05:01:31 +00:00
davidxu
58fc7458af Use umutex APIs to implement pthread_mutex, member pp_mutexq is added
into pthread structure to keep track of locked PTHREAD_PRIO_PROTECT mutex,
no real mutex code is changed, the mutex locking and unlocking code should
has same performance as before.
2006-08-28 04:52:50 +00:00
davidxu
77e7cda2cf Add umutex APIs. 2006-08-28 04:47:27 +00:00
ru
4d582ffe09 Remove alpha left-overs. 2006-08-22 08:03:01 +00:00
davidxu
c8a98491d0 Axe unused member field. 2006-08-08 05:04:43 +00:00
davidxu
cfa46376c7 Get number of CPUs and ignore spin count on single processor machine. 2006-08-08 04:42:41 +00:00
davidxu
5193e44c40 1. Don't override underscore version of aio_suspend(), system(),
wait(), waitpid() and usleep(), they are internal versions and
   should not be cancellation points.
2. Make wait3() as a cancellation point.
3. Move raise() and pause() into file thr_sig.c.
4. Add functions _sigsuspend, _sigwait, _sigtimedwait and _sigwaitinfo,
   remove SIGCANCEL bit in wait-set for those functions, the signal is
   used internally to implement thread cancellation.
2006-07-25 12:50:05 +00:00
delphij
36c285d128 Unexpand two TAILQ_FOREACH_SAFE cases.
Ok'ed by:	davidxu
2006-07-17 09:23:44 +00:00
davidxu
2b1dbc0acb Caching scheduling policy and priority in userland, a critical but baddly
written application is frequently changing thread priority for SCHED_OTHER
policy.
2006-07-13 22:45:19 +00:00
davidxu
19b8418903 Use thr_setscheduler, thr_getscheduler and thr_setschedparam to implement
pthread functions.
2006-07-13 06:35:43 +00:00
davidxu
ecacf536b0 Use kernel facilities to support real-time scheduling. 2006-07-12 06:13:18 +00:00
davidxu
f53e1c9383 __error could be called too early before libthr is initialized, test
this case and return global varible errno instead.
2006-07-12 03:44:05 +00:00
davidxu
be54fdbbff Remove unused member. 2006-06-03 00:19:40 +00:00
davidxu
523fcb36a8 Remove unused member field m_queue. 2006-06-02 08:37:01 +00:00
delphij
6e4a34202a Explicitly request pre-zeroed memory instead of memset'ing our
own.

Ok'ed by:	davidxu
2006-05-31 00:31:38 +00:00
davidxu
975a6925fe Add symbol versions: FBSD_1.0 and FBSDprivate. 2006-05-11 07:02:52 +00:00
davidxu
6a9d879cfe s/long/int. 2006-04-27 08:25:13 +00:00
davidxu
66d0fee031 - Use same priority range returned by kernel's sched_get_priority_min()
and sched_get_priority_max() syscalls.
- Remove unused fields from structure pthread_attr.
2006-04-27 08:18:23 +00:00
davidxu
8001df6f90 Remove multiple _get_curthread() calls. 2006-04-23 11:23:37 +00:00
ru
450f399135 Install shared libpthread library into /lib; needed by some
/sbin programs.
2006-04-12 19:42:20 +00:00
davidxu
7d0c23506c Do not check validity of timeout if a mutex can be acquired immediately.
Completly drop recursive mutex in pthread_cond_wait and restore recursive
after resumption. Reorganize code to make gcc to generate better code.
2006-04-08 13:24:44 +00:00
davidxu
f921934131 Remove declaration of _thr_initial from MD header file, it is no longer
needed.
2006-04-04 03:35:26 +00:00
davidxu
8bff50a485 Simplify _get_curthread() and _tcb_ctor because libc and rtld now
already allocate thread pointer space in tls block for initial thread.
Only i386 and amd64 have been done, others still have to be tested.
2006-04-04 03:26:06 +00:00
davidxu
31f2b819c6 WARNS level 4 cleanup. 2006-04-04 02:57:49 +00:00
des
5438ed2ce6 Fix prototype mismatch. 2006-03-28 21:46:55 +00:00
davidxu
255936645e Remove priority mutex code because it does not work correctly,
to make it work, turnstile like mechanism to support priority
propagating and other realtime scheduling options in kernel
should be available to userland mutex, for the moment, I just
want to make libthr be simple and efficient thread library.

Discussed with: deischen, julian
2006-03-27 23:50:21 +00:00
davidxu
4b5909711d Comment out -g compiler option, found by 'FreeBSD Build Options Survey'. 2006-03-27 05:58:58 +00:00
davidxu
32673f0256 Check cancellation state carefully to see we really need to call
_pthread_testcancel(). Preserve errno in _thr_suspend_check().
2006-03-26 01:57:03 +00:00
davidxu
2926ddf5d1 Don't cancel thread if it is in critical region. 2006-03-25 07:03:13 +00:00
davidxu
679e2338c0 Only wake up writer if the lock is free. 2006-03-25 05:14:21 +00:00
davidxu
cba4d932c1 Compile thr_rtld.c 2006-03-25 05:00:54 +00:00
davidxu
6ee36bbb6d Add locking support for rtld. 2006-03-25 04:49:07 +00:00
davidxu
eb9bdb4259 set an upper limit for thread structures which can be allocated. 2006-03-24 04:34:06 +00:00
davidxu
020594940d Set default contention scope to system. 2006-03-20 03:14:14 +00:00
ru
5f8b6d3c5a Convert NO_PROFILE and NO_LIB32 to new style. 2006-03-18 21:37:05 +00:00
davidxu
d119bdaa7a Remove mqueue and timer, now they are in librt. 2006-03-08 23:47:04 +00:00
deischen
e586a0042e 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
davidxu
6fdf2b7d81 Reimplement mutex_init to get rid of compile warning. 2006-02-28 06:06:19 +00:00
davidxu
bb43155dbb Disable POSIX SIGEV_THREAD notification support, soon we will have a common
library which can be reused both for libthr and libpthread.
2006-02-22 02:52:22 +00:00
davidxu
91fda076fb Read cycle count before sending signal, this fixes a userland thread
suspension bug.

MFC after: 3 days
2006-02-20 09:02:40 +00:00
davidxu
70ea4e1323 Rework last change of pthread_once, create a function _thr_once_init to
reinitialize its internal locks.
2006-02-15 23:05:03 +00:00
davidxu
44a8ce5006 After fork(), reinitialize internal locks for pthread_once(). 2006-02-15 13:41:02 +00:00
davidxu
08b1c5c928 Now, thread name is stored in kernel, userland no longer has to keep it. 2006-02-05 03:04:54 +00:00
davidxu
118990614c use syscall thr_set_name to implement pthread_set_name_np. 2006-02-05 02:26:17 +00:00
davidxu
3172ccca0f Add missing symbol pthread_set_name_np. 2006-01-23 06:11:23 +00:00
davidxu
97a1cdabb8 Eliminate unused code. 2006-01-16 05:33:48 +00:00
davidxu
aedf24a684 Enable mutex inheritance code in mutex_fork, I forgot to turn on it.
while here, add some comments about process shared mutex.
2006-01-14 11:33:43 +00:00
jasone
e30d92806f 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
jasone
3668a2e494 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
davidxu
84187b477c The thr_new sysscall was already in libc, don't generate it. 2006-01-11 06:10:05 +00:00
davidxu
1218aa5627 Use macro STATIC_LIB_REQUIRE to declare a symbol should be linked into
static binary.
2006-01-10 04:53:03 +00:00
davidxu
36bb818343 Rescue pthread_set_name_np for compatible reason, remove unused code. 2006-01-09 08:07:22 +00:00
davidxu
8798f9bcec Tweak macro THR_LOCK_RELEASE a bit for non-PTHREAD_INVARIANTS case. 2006-01-09 07:32:22 +00:00
davidxu
db9594be6e Return real detached state. 2006-01-09 03:59:51 +00:00
davidxu
6f27a53b6f Fix a bug recently introduced, the _thread_active_count should be
decreased if thread can not be created.
2006-01-08 10:13:18 +00:00
davidxu
d1f7b6d605 Allow background threads to be suspended. 2006-01-08 01:49:31 +00:00
davidxu
4c4f339838 Try to reduce total time needed for suspending all threads,
first broadcast signals to all threads, then enter a wait loop.
2006-01-08 01:48:51 +00:00
davidxu
f04292bb19 Remove functions i386_get_gsbase and i386_set_gsbase, they were already
in libc.
2006-01-07 06:01:43 +00:00
davidxu
d6c88c0f27 Refine thread suspension code, now thread suspension is a blockable
operation, the caller is blocked util target threads are really
suspended, also avoid suspending a thread when it is holding a
critical lock.
Fix a bug in _thr_ref_delete which tests a never set flag.
2006-01-05 13:51:22 +00:00
davidxu
45180066f9 1. Add SIGEV_THREAD notification for mq_notify.
2. Reuse current timer code and abstract some common code to
   to support both timer and mqueue.
2006-01-04 11:48:02 +00:00
davidxu
46ad9344c2 Remove in-progress wait code to sync with libpthread's behavior. 2006-01-03 13:30:23 +00:00
davidxu
2d34e45c94 Let _mutex_cv_lock call internal functiona mutex_lock_common. 2005-12-21 05:14:07 +00:00
davidxu
5ac55e9c46 Hide umtx API symbols as well. 2005-12-21 03:53:29 +00:00
davidxu
8d9e23fb51 1. Retire macro SCLASS, instead simply use language keyword and
put variables in thr_init.c.
2. Hide all global symbols which won't be exported.
2005-12-21 03:14:06 +00:00
davidxu
3e60ee73cb Follow the mistake in libpthread, the first version name in libpthread
is LIBTHREAD_1_0, but really it should be LIBPTHREAD_1_0.
Fix it so libmap.conf works again (it was broken by recent versioning
code in rtld_elf).
2005-12-21 02:34:20 +00:00
davidxu
a8cc7e07c2 Clear return code to zero if joiner successfully waited joinee.
Bug reported by: jasone at connonware when using ports lang/onyx
MFC after: 3 days
2005-12-19 03:20:55 +00:00
davidxu
272f64aa70 Update copyright. 2005-12-17 09:42:45 +00:00
davidxu
7bdde27518 Remove unused _get_curthread() call. 2005-12-12 07:14:57 +00:00
davidxu
ae161ac239 Fix name compatible problem with POSIX standard. the sigval_ptr and
sigval_int really should be sival_ptr and sival_int.
Also sigev_notify_function accepts a union sigval value but not a
pointer.
2005-11-04 09:41:00 +00:00
davidxu
3e97a4d0bd Remove a redundant _get_curthread() call. 2005-11-02 14:06:29 +00:00
davidxu
e623529523 In raise(), use a shortcut to directly send signal to current thread. 2005-11-02 13:52:48 +00:00
davidxu
326dbaf282 Fix some comments, eliminate a memory leak. 2005-11-01 13:05:47 +00:00
davidxu
e3fd454017 Use TIMERS_UNLOCK. 2005-11-01 07:05:32 +00:00
davidxu
185b13c547 Add code to handle timer_delete(). The timer wrapper code is completely
rewritten, now timers created with same sigev_notify_attributes will
run in same thread, this allows user to organize which timers can
run in same thread to save some thread resource.
2005-11-01 06:53:22 +00:00
davidxu
363ab5c566 Add thread exit handler in timer_loop to handle broken buggy code which
could lead to memory leak.
2005-10-30 23:59:01 +00:00
davidxu
77f9fea7ac Add timer_create wrapper. 2005-10-30 03:16:30 +00:00
davidxu
2039945090 Remove unused variable.
Reviewed by: cognet
2005-10-29 13:40:31 +00:00
davidxu
3882c07f39 Kill unused variable declaration. 2005-10-29 03:08:43 +00:00
davidxu
912a374cd0 Link libthr to libpthread on Alpha and Sparc. 2005-10-27 10:21:23 +00:00
davidxu
3aca9ad9f9 Add experiment code to implement POSIX timer's SIGEV_THREAD notification. 2005-10-26 11:08:32 +00:00
davidxu
0929747005 Follow the change in kernel, joiner thread just waits at thread id
address, let kernel wake it up.
2005-10-26 07:11:43 +00:00
davidxu
108506206f Put pthread_condattr_init sorted order. 2005-10-25 00:09:58 +00:00
davidxu
841a0c67c5 Export following functions:
_pthread_mutexattr_getpshared
	_pthread_mutexattr_setpshared
	pthread_condattr_getpshared
	pthread_condattr_setpshared
	pthread_mutexattr_getpshared
	pthread_mutexattr_setpshared
2005-10-24 05:20:04 +00:00
davidxu
f8a456fe19 Add functions pthread_mutexattr_setpshared and pthread_mutexattr_getpshared. 2005-10-24 05:16:41 +00:00
davidxu
f24893fc40 The pthread_attr_set_createsuspend_np was broken, fix it by
replacing THR_FLAGS_SUSPENDED with THR_FLAGS_NEED_SUSPEND.
2005-10-10 12:15:07 +00:00
davidxu
424c2c3a12 Sort function names. 2005-10-04 08:28:46 +00:00
davidxu
6459dc5d9d Add function pthread_timedjoin_np, the function is similar with pthread_join
except the function will return ETIMEDOUT if target thread does not exit
before specified absolute time passes.
2005-10-04 06:15:25 +00:00
stefanf
be47cc4f82 Include needed headers that were obtained through <pthread.h>. Sort headers
while here.
2005-09-01 15:21:23 +00:00
stefanf
cb1c3eea78 - 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
deischen
a1a323c7ed Add usleep to the map files.
Noticed by:	davidxu
2005-08-03 01:54:52 +00:00
deischen
6f4c090af6 Add a cancellation point for usleep().
While here, fix sleep() so that it is also a cancellation point (a
missing weak reference prevented that).
2005-08-03 00:47:31 +00:00
davidxu
dc3be45bb9 Cast to uintptr_t to avoid compiler warning, it was broken by
the recent atomic_ptr() change.
2005-07-28 03:34:54 +00:00
kensmith
f97f77429f Bump the shared library version number of all libraries that have not
been bumped since RELENG_5.

Reviewed by:	ru
Approved by:	re (not needed for commit check but in principle...)
2005-07-22 17:19:05 +00:00
davidxu
4a65a73e58 Fix off-by-one nanosecond bug in macro TIMESPEC_ADD.
Reviewed by: deischen
Approved by: re (dwhite)
MFC after  : 4 days
2005-06-22 22:38:56 +00:00
ru
7cec114952 Markup fixes.
Approved by:	re
2005-06-16 19:01:07 +00:00
rwatson
cbb1ab3809 Remove incorrect BUGS entry: libthr does support process-scope thread
scheduling.

MFC after:	1 week
Submitted by:	davidxu
Approved by:	re (scottl)
2005-06-15 15:21:10 +00:00
rwatson
dffb6088ac Add a stub libthr(3) man page to document what it is and why, as well as
to point at libmap.conf(5).  This will help answer questions about what
and why it is, although not in great detail.

Approved by:	re (scottl)
MFC after:	1 week
MFC note:	When MFC'd, don't MFC mention of work not yet MFC'd.
2005-06-11 15:27:56 +00:00
davidxu
094168eea8 Remove COMPAT_32BIT, it is no longer needed. 2005-04-27 01:29:03 +00:00
davidxu
9f7f211673 Remove unused variable. 2005-04-23 03:34:43 +00:00
davidxu
8d38949442 Now libthr only uses GDT based tls on i386. using LDT can only increase
clock cycles and has 8191 threads limitation.
2005-04-23 03:31:59 +00:00
davidxu
a0a25ee25d Use thr_new syscall to create a new thread, obscure context operations
is no longer needed.
2005-04-23 02:48:59 +00:00
davidxu
d75a2adc3f Add i386_get_gsbase, i386_set_gsbase since old libc doesn't have the
functions, otherwise user ports have to be rebuilt.
2005-04-23 02:14:38 +00:00
peter
c1d476c931 Adapt the libpthread patch for using i386_set_gsbase() to libthr. 2005-04-14 00:44:07 +00:00
davidxu
3093d067e4 Conditionally report initial thread event. 2005-04-12 03:13:49 +00:00
davidxu
bc36c64c8d Add missing event reporting code. 2005-04-12 03:08:11 +00:00
davidxu
2cf5eeb001 Add debugger event reporting support, current only TD_CREATE and TD_DEATH
events are reported.
2005-04-12 03:00:28 +00:00
cognet
c7b04f713a Use the new atomic_cmpset_32(). 2005-04-07 22:06:05 +00:00
davidxu
22b6b1a4cf Adjust hash function for smaller pthread structure size. 2005-04-07 06:09:17 +00:00