summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread/thr_init.c
Commit message (Collapse)AuthorAgeFilesLines
* Repo copy libpthreads to libkse.obrien2007-10-091-530/+0
| | | | | | This introduces the WITHOUT_LIBKSE nob, and changes WITHOUT_LIBPTHREADS to mean with neither threading libs. Approved by: re(kensmith)
* Remove 3rd clause, renumber, ok per emailimp2007-01-121-4/+1
|
* Add compatibility symbol maps. libpthread (.so.1 and .so.2)deischen2006-03-131-0/+5
| | | | | | | | | | | 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
* Only catch SIGINFO (for dumping thread states) when LIBPTHREAD_DEBUGdeischen2006-03-061-0/+2
| | | | | | is defined in the environment. Requested by: jmg & a few others
* Add some more pthread stubs so that librt can use them.deischen2006-03-051-4/+35
| | | | | | | The thread jump table has been resorted, so you need to keep libc, libpthread, and libthr in sync. Submitted by: xu
* Modify the code path of the ifdef NOTYET part of _kse_single_thread():brian2005-09-241-1/+1
| | | | | | | | | | | | | | | | | | | | 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]
* Somewhere along the line, tick accumulation for SA threads wasdeischen2005-02-181-1/+1
| | | | | | | 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>
* Set the default guardsize and stacksize in the default threaddeischen2005-02-151-0/+2
| | | | attribute when the library is initialized.
* Increase the default stacksizes:deischen2005-02-131-3/+11
| | | | | | 32-bit 64-bit main thread 2MB 4MB other threads 1MB 2MB
* Use a generic way to back threads out of wait queues when handlingdeischen2004-12-181-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | signals instead of having more intricate knowledge of thread state within signal handling. Simplify signal code because of above (by David Xu). Use macros for libpthread usage of pthread_cleanup_push() and pthread_cleanup_pop(). This removes some instances of malloc() and free() from the semaphore and pthread_once() implementations. When single threaded and forking(), make sure that the current thread's signal mask is inherited by the forked thread. Use private mutexes for libc and libpthread. Signals are deferred while threads hold private mutexes. This fix also breaks www/linuxpluginwrapper; a patch that fixes it is at http://people.freebsd.org/~deischen/kse/linuxpluginwrapper.diff Fix race condition in condition variables where handling a signal (pthread_kill() or kill()) may not see a wakeup (pthread_cond_signal() or pthread_cond_broadcast()). In collaboration with: davidxu
* Pull debug symbols in for statically linked binary.davidxu2004-08-211-0/+4
| | | | Reviewed by: desichen
* As long as we have a knob to force system scope threads, why not havedeischen2004-08-121-1/+3
| | | | | | | | | | | | | a knob to force process scope threads. If the environment variable LIBPTHREAD_PROCESS_SCOPE is set, force all threads to be process scope threads regardless of how the application creates them. If LIBPTHREAD_SYSTEM_SCOPE is set (forcing system scope threads), it overrides LIBPTHREAD_PROCESS_SCOPE. $ # To force system scope threads $ LIBPTHREAD_SYSTEM_SCOPE=anything threaded_app $ # To force process scope threads $ LIBPTHREAD_PROCESS_SCOPE=anything threaded_app
* Add a way to force 1:1 mode for libpthread. To do this, definedeischen2004-08-071-5/+9
| | | | | | | | | | | LIBPTHREAD_SYSTEM_SCOPE in the environment. You can still force libpthread to be built in strictly 1:1 by adding -DSYSTEM_SCOPE_ONLY to CFLAGS. This is kept for archs that don't yet support M:N mode. Requested by: rwatson Reviewed by: davidxu
* If _libkse_debug is not zero, activate thread mode.davidxu2004-07-131-0/+6
|
* Remove surplus mmap() call for stack guard page in init_private, it is donedavidxu2003-11-291-25/+0
| | | | | | | | in init_main_thread. Also don't initialize lock and lockuser again for initial thread, it is already done by _thr_alloc(). Reviewed by: deischen Approved by: re (scottl)
* Add an implementation for pthread_atfork().deischen2003-11-041-0/+2
| | | | | | | | Aside from the POSIX requirements for pthread_atfork(), when fork()ing, take the malloc lock to keep malloc state consistent in the child. Reviewed by: davidxu
* Treat initial thread as scope system thread when KSE mode is not activateddavidxu2003-08-181-4/+3
| | | | | | | | | yet, so we can protect some locking code from being interrupted by signal handling. When KSE mode is turned on, reset the thread flag to scope process except we are running in 1:1 mode which we needn't turn it off. Also remove some unused member variables in structure kse. Tested by: deischen
* Initialize rtld lock just before turning on thread mode anddavidxu2003-08-101-2/+0
| | | | uninitialize rtld lock after thread mode shutdown.
* Rethink the MD interfaces for libpthread to account fordeischen2003-08-051-14/+7
| | | | | | | | | archs that can (or are required to) have per-thread registers. Tested on i386, amd64; marcel is testing on ia64 and will have some follow-up commits. Reviewed by: davidxu
* o Eliminate upcall for PTHREAD_SYSTEM_SCOPE thread, now itdavidxu2003-07-171-5/+11
| | | | | | | | | | | | | is system bound thread and when it is blocked, no upcall is generated. o Add ability to libkse to allow it run in pure 1:1 threading mode, defining SYSTEM_SCOPE_ONLY in Makefile can turn on this option. o Eliminate code for installing dummy signal handler for sigwait call. o Add hash table to find thread. Reviewed by: deischen
* o Use a daemon thread to monitor signal events in kernel, if pendingdavidxu2003-06-281-39/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | signals were changed in kernel, it will retrieve the pending set and try to find a thread to dispatch the signal. The dispatching process can be rolled back if the signal is no longer in kernel. o Create two functions _thr_signal_init() and _thr_signal_deinit(), all signal action settings are retrieved from kernel when threading mode is turned on, after a fork(), child process will reset them to user settings by calling _thr_signal_deinit(). when threading mode is not turned on, all signal operations are direct past to kernel. o When a thread generated a synchoronous signals and its context returned from completed list, UTS will retrieve the signal from its mailbox and try to deliver the signal to thread. o Context signal mask is now only used when delivering signals, thread's current signal mask is always the one in pthread structure. o Remove have_signals field in pthread structure, replace it with psf_valid in pthread_signal_frame. when psf_valid is true, in context switch time, thread will backout itself from some mutex/condition internal queues, then begin to process signals. when a thread is not at blocked state and running, check_pending indicates there are signals for the thread, after preempted and then resumed time, UTS will try to deliver signals to the thread. o At signal delivering time, not only pending signals in thread will be scanned, process's pending signals will be scanned too. o Change sigwait code a bit, remove field sigwait in pthread_wait_data, replace it with oldsigmask in pthread structure, when a thread calls sigwait(), its current signal mask is backuped to oldsigmask, and waitset is copied to its signal mask and when the thread gets a signal in the waitset range, its current signal mask is restored from oldsigmask, these are done in atomic fashion. o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait(). o Signal code locking is better than previous, there is fewer race conditions. o Temporary disable most of code in _kse_single_thread as it is not safe after fork().
* Only init _thread_sigact once, needn't init it again after a fork().davidxu2003-06-041-31/+31
| | | | Obtained from: deischen
* Attempt to eliminate PLT relocations from rwlock aquire/releasekan2003-05-301-0/+2
| | | | | | | | | | | path, making them suitable for direct use by the dynamic loader. Register libpthread-specific locking API with rtld on startup. This still has some rough edges with signals which should be addresses later. Approved by: re (scottl)
* Don't really spin on a spinlock; silently convert it to the samedeischen2003-05-291-0/+1
| | | | | | | | | | | | low-level lock used by the libpthread implementation. In the future, we'll eliminate spinlocks from libc but that will wait until after 5.1-release. Don't call an application signal handler if the handler is the same as the library-installed handler. This seems to be possible after a fork and is the cause of konsole hangs. Approved by: re@ (jhb)
* Add a method of yielding the current thread with the schedulerdeischen2003-05-161-0/+2
| | | | | | | | | | | | | | | | | | | | | | | lock held (_thr_sched_switch_unlocked()) and use this to avoid dropping the scheduler lock and having the scheduler retake the same lock again. Add a better way of detecting if a low-level lock is in use. When switching out a thread due to blocking in the UTS, don't switch to the KSE's scheduler stack only to switch back to another thread. If possible switch to the new thread directly from the old thread and avoid the overhead of the extra context switch. Check for pending signals on a thread when entering the scheduler and add them to the threads signal frame. This includes some other minor signal fixes. Most of this was a joint effor between davidxu and myself. Reviewed by: davidxu Approved by: re@ (blanket for libpthread)
* Move the mailbox to the beginning of the thread and align thedeischen2003-04-301-0/+3
| | | | thread so that the context (SSE FPU state) is also aligned.
* Create the thread signal lock as a KSE lock (as opposed todeischen2003-04-291-1/+1
| | | | | | | | | | | | a thread lock). Better protect access to thread state while searching for threads to handle a signal. Better protect access to process pending signals while processing a thread in sigwait(). Submitted by: davidxu
* Add a couple asserts to pthread_cond_foo to ensure the (low-level)deischen2003-04-221-0/+3
| | | | | | | | | | | | | | | lock level is 0. Thus far, the threads implementation doesn't use mutexes or condition variables so the lock level should be 0. Save the return value when trying to schedule a new thread and use this to return an error from pthread_create(). Change the max sleep time for an idle KSE to 1 minute from 2 minutes. Maintain a count of the number of KSEs within a KSEG. With these changes scope system threads seem to work, but heavy use of them crash the kernel (supposedly VM bugs).
* Sorry folks; I accidentally committed a patch from what I was workingdeischen2003-04-181-3/+3
| | | | | | on a couple of days ago. This should be the most recent changes. Noticed by: davidxu
* Revamp libpthread so that it has a chance of working in an SMPdeischen2003-04-181-201/+314
| | | | | | | | | | | | | | | | | | | environment. This includes support for multiple KSEs and KSEGs. The ability to create more than 1 KSE via pthread_setconcurrency() is in the works as well as support for PTHREAD_SCOPE_SYSTEM threads. Those should come shortly. There are still some known issues which davidxu and I are working on, but it'll make it easier for us by committing what we have. This library now passes all of the ACE tests that libc_r passes with the exception of one. It also seems to work OK with KDE including konqueror, kwrite, etc. I haven't been able to get mozilla to run due to lack of java plugin, so I'd be interested to see how it works with that. Reviewed by: davidxu
* Deliver signals posted via an upcall to the appropriate thread.mini2003-02-171-0/+31
|
* Schedule an idle context to block until timeouts expire without blockingmini2002-11-121-0/+12
| | | | further upcalls.
* Use KSE to schedule threads.mini2002-10-301-11/+16
|
* Make libpthread KSE aware.mini2002-09-161-158/+16
| | | | | Reviewed by: deischen, julian Approved by: -arch
* Make the changes needed for libpthread to compile in its new home.mini2002-09-161-1/+1
| | | | | | | | The new libpthread will provide POSIX threading support using KSE. These files were previously repo-copied from src/lib/libc_r. Reviewed by: deischen Approved by: -arch
* Revamp suspend and resume. While I'm here add pthread_suspend_all_np()deischen2002-05-241-7/+21
| | | | | | | | | | | | | and pthread_resume_all_np(). These suspend and resume all threads except the current thread, respectively. The existing functions pthread_single_np() and pthread_multi_np(), which formerly had no effect, now exhibit the same behaviour and pthread_suspend_all_np() and pthread_resume_all_np(). These functions have been added mostly for the native java port. Don't allow the uthread kernel pipe to use the same descriptors as stdio. Mostily submitted by Oswald Buddenhagen <ossi@kde.org>. Correct some minor style nits.
* Undo namespace pollution by prefixing the globals pthread_guard_default andalfred2002-05-151-7/+7
| | | | | | | | pthread_page_size. Fix a bunch line wrapping. Pointed out by: deischen
* Don't use PAGE_SIZE in userland, instead use getpagesize(), this is toalfred2002-05-131-3/+14
| | | | | | | allow running on other arches when the instructions are supported but the page size granularity is not. Glanced at by: peter
* Add the ability to recognize old references to keys, and return NULLdeischen2002-03-191-1/+1
| | | | | when old keys are referenced (after pthread_key_delete()) via pthread_getspecific().
* This has been sitting in my local tree long enough. Remove the usedeischen2002-02-091-12/+0
| | | | | | | | | | | | | | of an alternate signal stack for handling signals. Let the kernel send signals on the stack of the current thread and teach the threads signal handler how to deliver signals to the current thread if it needs to. Also, always store a threads context as a jmp_buf. Eventually this will change to be a ucontext_t or mcontext_t. Other small nits. Use struct pthread * instead of pthread_t in internal library routines. The threads code wants struct pthread *, and pthread_t doesn't necessarily have to be the same. Reviewed by: jasone
* Fix the retrieval of USRSTACK via sysctl so that it works for 64-bitdeischen2001-12-181-2/+2
| | | | | | archs. This should fix libc_r on alpha. Submitted by: Bernd Walter <ticso@cicely9.cicely.de>
* Make libc_r check the kern.usrstack sysctl instead of using internalpeter2001-10-261-3/+8
| | | | | | | kernel #defines to figure out where the stack is located. This stops libc_r from exploding when the kernel is compiled with a different KVM size. IMHO this is all kinda bogus, it would be better to just check %esp and work from that.
* Compensate for "Compensate for header dethreading" by backing it out.bde2001-10-101-2/+0
|
* Implement pthread_attr_[gs]etguardsize(). Non-default-size stacks used tojasone2001-07-201-4/+1
| | | | | | | | be malloc()ed, but they are now allocated using mmap(), just as the default-size stacks are. A separate cache of stacks is kept for non-default-size stacks. Collaboration with: deischen
* Instead of using a join queue for each thread, use a single pointer tojasone2001-05-201-2/+2
| | | | | | | | | | | keep track of a joiner. POSIX only supports a single joiner, so this simplification is acceptable. At the same time, make sure to mark a joined thread as detached so that its resources can be freed. Reviewed by: deischen PR: 24345
* Compenate for header dethreading.markm2001-05-011-0/+2
|
* Limit threads clock resolution to no less than 1000usec (1000Hz).deischen2001-02-261-1/+2
| | | | | PR: 25300 Submitted by: Tom Pavel <pavel@alum.mit.edu> (in part)
* Add weak definitions for wrapped system calls. In general:deischen2001-01-241-91/+119
| | | | | | | | | | | | | | | | | | | | | | | | | | | _foo - wrapped system call foo - weak definition to _foo and for cancellation points: _foo - wrapped system call __foo - enter cancellation point, call _foo(), leave cancellation point foo - weak definition to __foo Change use of global _thread_run to call a function to get the currently running thread. Make all pthread_foo functions weak definitions to _pthread_foo, where _pthread_foo is the implementation. This allows an application to provide its own pthread functions. Provide slightly different versions of pthread_mutex_lock and pthread_mutex_init so that we can tell the difference between a libc mutex and an application mutex. Threads holding mutexes internal to libc should never be allowed to exit, call signal handlers, or cancel. Approved by: -arch
* Force strong references to several pthread_* functions which are weaklyobrien2001-01-061-0/+32
| | | | | | | | | | | | | | | | referenced to by libgcc.a. This is needed when linking statically as SVR4 (ie, ELF) behavior is to only link in a module if it satisfies an undefined strong reference from somewhere. (this surprises a lot of people) Things are different when using shared libs, the entire library and its modules and their symbols are available at run-time (when the weak reference is seen to still be unsatisfied and is satisfied on the spot), this is not the case with static libs. Thus one can have a static binary with unresolved week references, and at run-time dereference a NULL pointer. Submitted by: eischen
* When entering the scheduler from the signal handler, telldeischen2000-11-141-6/+9
| | | | | | | | | | | the kernel to (re)use the alternate signal stack. In this case, we don't return normally from the signal handler, so the kernel still thinks we are using the signal stack. The fixes a nasty bug where the signal handler can start fiddling with the stack of a thread while the handler is actually running on the same stack. MFC candidate
OpenPOWER on IntegriCloud