summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread/thr_private.h
Commit message (Collapse)AuthorAgeFilesLines
* Use a generic way to back threads out of wait queues when handlingdeischen2004-12-181-5/+19
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* Save cancelflags in signal frame, this fixes a problem thatdavidxu2004-11-011-0/+1
| | | | | | | a thread in pthread_cond_wait handled a signal can no longer be canceled. Reviewed by: deischen
* 1. Move thread list flags into new separate member, and atomicallydavidxu2004-10-231-11/+15
| | | | | | | | | | | put DEAD thread on GC list, this closes a race between pthread_join and thr_cleanup. 2. Introduce a mutex to protect tcb initialization, tls allocation and deallocation code in rtld seems no lock protection or it is broken, under stress testing, memory is corrupted. Reviewed by: deischen patch partly provided by: deischen
* Add a way to force 1:1 mode for libpthread. To do this, definedeischen2004-08-071-0/+1
| | | | | | | | | | | 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
* s/TMDF_DONOTRUNUSER/TMDF_SUSPEND/gdavidxu2004-08-031-1/+1
| | | | Dicussed with: deischen
* Don't include lock.h and pthread_md.h when we're being included bymarcel2004-07-181-0/+2
| | | | libthread_db. Both headers are included seperately.
* Add code to support thread debugging.davidxu2004-07-131-12/+24
| | | | | | | | | | | | | | | 1. Add global varible _libkse_debug, debugger uses the varible to identify libpthread. when the varible is written to non-zero by debugger, libpthread will take some special action at context switch time, it will check TMDF_DOTRUNUSER flags, if a thread has the flags set by debugger, it won't be scheduled, when a thread leaves KSE critical region, thread checks the flag, if it was set, the thread relinquish CPU. 2. Add pq_first_debug to select a thread allowd to run by debugger. 3. Some names prefixed with _thr are renamed to _thread prefix. which is allowed to run by debugger.
* Check pending signals, if there is signal will be unblocked bydavidxu2004-06-121-0/+1
| | | | | | | | | | | | | | | | | | sigsuspend, thread shouldn't wait, in old code, it may be ignored. When a signal handler is invoked in sigsuspend, thread gets two different signal masks, one is in thread structure, sigprocmask() can retrieve it, another is in ucontext which is a third parameter of signal handler, the former is the result of sigsuspend mask ORed with sigaction's sa_mask and current signal, the later is the mask in thread structure before sigsuspend is called. After signal handler is called, the mask in ucontext should be copied into thread structure, and becomes CURRENT signal mask, then sigsuspend returns to user code. Reviewed by: deischen Tested by: Sean McNeil <sean@mcneil.com>
* Provide a userland version of non-pshared semaphores and add cancellationdeischen2004-02-031-12/+0
| | | | points to sem_wait() and sem_timedwait(). Also make sem_post signal-safe.
* Add a simple work-around for deadlocking on recursive read locksdeischen2004-01-081-1/+4
| | | | | | | | | | on a rwlock while there are writers waiting. We normally favor writers but when a reader already has at least one other read lock, we favor the reader. We don't track all the rwlocks owned by a thread, nor all the threads that own a rwlock -- we just keep a count of all the read locks owned by a thread. PR: 24641
* Forgot to commit this file for last commit. :(davidxu2003-12-291-0/+4
|
* Code clean up, remove unused MACROS and function prototypes.davidxu2003-12-191-18/+0
|
* Remove an unused struct definition.deischen2003-12-091-12/+0
|
* Add cancellation points for accept() and connect().deischen2003-12-091-0/+2
|
* Rename _thr_enter_cancellation_point to _thr_cancel_enter, renamedavidxu2003-12-091-14/+25
| | | | | | | | | | | | | | | | | | | | | _thr_leave_cancellation_point to _thr_cancel_leave, add a parameter to _thr_cancel_leave to indicate whether cancellation point should be checked, this gives us an option to not check cancallation point if a syscall successfully returns to avoid any leaks, current I have creat(), open() and fcntl(F_DUPFD) to not check cancellation point after they sucessfully returned. Replace some members in structure kse with bit flags to same some memory. Conditionally compile THR_ASSERT to nothing if _PTHREAD_INVARIANTS is not defined. Inline some small functions in thr_cancel.c. Use __predict_false in thr_kern.c for some executed only once code. Reviewd by: deischen
* 1.Macro optimizing KSE_LOCK_ACQUIRE and THR_LOCK_ACQUIRE to use static falldavidxu2003-11-291-8/+7
| | | | | | | | | | | | | | through branch predict as suggested in INTEL IA32 optimization guide. 2.Allocate siginfo arrary separately to avoid pthread to be allocated at 2K boundary, which hits L1 address alias problem and causes context switch to be slow down. 3.Simplify context switch code by removing redundant code, code size is reduced, so it is expected to run faster. Reviewed by: deischen Approved by: re (scottl)
* Add an implementation for pthread_atfork().deischen2003-11-041-0/+13
| | | | | | | | 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
* Complete cancellation support for M:N threads, check cancelling flag whendavidxu2003-10-081-0/+1
| | | | | | | thread state is changed from RUNNING to WAIT state and do some cancellation operations for every cancellable state. Reviewed by: deischen
* Save and restore timeout field for signal frame just like what we diddavidxu2003-09-221-0/+1
| | | | | | for interrupted field. Also in _thr_sig_handler, retrieve current signal mask from kernel not from ucp, the later is pre-unioned mask, not current signal mask.
* 1. Allocating and freeing lock related resource in _thr_alloc and _thr_freedavidxu2003-09-141-0/+2
| | | | | | | | | | | to avoid potential memory leak, also fix a bug in pthread_create, contention scope should be inherited when PTHREAD_INHERIT_SCHED is set, and also check right field for PTHREAD_INHERIT_SCHED, scheduling inherit flag is in sched_inherit. 2. Execute hooks registered by atexit() on thread stack but not on scheduler stack. 3. Simplify some code in _kse_single_thread by calling xxx_destroy functions. Reviewed by: deischen
* Original pthread_once code has memory leak if pthread_once_t is used indavidxu2003-09-091-0/+2
| | | | | | | | | | | | | | | a shared library or any other dyanmic allocated data block, once pthread_once_t is initialized, a mutex is allocated, if we unload the shared library or free those data block, then there is no way to deallocate the mutex, result is memory leak. To fix this problem, we don't use mutex field in pthread_once_t, instead, we use its state field and an internal mutex and conditional variable in libkse to do any synchronization, we introduce a third state IN_PROGRESS to wait if another thread is already in invoking init_routine(). Also while I am here, make pthread_once() conformed to pthread cancellation point specification. Reviewed by: deischen
* Add code to support pthread spin lock.davidxu2003-09-091-0/+6
| | | | Reviewed by: deischen
* Add code to support barrier synchronous object and implementdavidxu2003-09-041-0/+12
| | | | | | pthread_mutex_timedlock(). Reviewed by: deischen
* Allow the concurrency level to be reduced.deischen2003-08-301-0/+1
| | | | Reviewed by: davidxu
* Treat initial thread as scope system thread when KSE mode is not activateddavidxu2003-08-181-12/+0
| | | | | | | | | 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
* Rethink the MD interfaces for libpthread to account fordeischen2003-08-051-11/+4
| | | | | | | | | 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
* Simplify sigwait code a bit by using a waitset and removing oldsigmask.davidxu2003-07-271-2/+5
| | | | Reviewed by: deischen
* Move idle kse wakeup to outside of regions where locks are held.deischen2003-07-231-2/+2
| | | | | | | | This eliminates ping-ponging of locks, where the idle KSE wakes up only to find the lock it needs is being held. This gives little or no gain to M:N mode but greatly speeds up 1:1 mode. Reviewed & Tested by: davidxu
* Cleanup thread accounting. Don't reset a threads timeslicedeischen2003-07-181-2/+5
| | | | | | | | when it blocks; it only gets reset when it yields. Properly set a thread's default stack guardsize. Reviewed by: davidxu
* o Eliminate upcall for PTHREAD_SYSTEM_SCOPE thread, now itdavidxu2003-07-171-9/+13
| | | | | | | | | | | | | 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-14/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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().
* Untangle the inter-dependency of kse types and ksd types/functionsmarcel2003-06-231-1/+0
| | | | | | | | | | | | | | | | | | | by moving the definition of struct ksd to pthread_md.h and removing the inclusion of ksd.h from thr_private.h (which has the definition of struct kse and kse_critical_t). This allows ksd.h to have inline functions that use struct kse and kse_critical_t and generally yields a cleaner implementation at the cost of not having all ksd related types/definitions in one header. Implement the ksd functionality on ia64 by using inline functions and permanently remove ksd.c from the ia64 specific makefile. This change does not clean up the i386 specific version of ksd.h. NOTE: The ksd code on ia64 abuses the tp register in the same way as it is abused in libthr in that it is incompatible with the runtime specification. This will be address when support for TLS hits the tree.
* Attempt to eliminate PLT relocations from rwlock aquire/releasekan2003-05-301-0/+20
| | | | | | | | | | | 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-1/+2
| | | | | | | | | | | | 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-23/+22
| | | | | | | | | | | | | | | | | | | | | | | 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)
* Fix suspend and resume.deischen2003-05-041-0/+5
| | | | Submitted (in part) by: Kazuaki Oda <kaakun@highway.ne.jp>
* Move the mailbox to the beginning of the thread and align thedeischen2003-04-301-4/+6
| | | | thread so that the context (SSE FPU state) is also aligned.
* o Don't add a scope system thread's KSE to the list of availabledeischen2003-04-281-9/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | KSEs when it's thread exits; allow the GC handler to do that. o Make spinlock/spinlock critical regions. The following were submitted by davidxu o Alow thr_switch() to take a null mailbox argument. o Better protect cancellation checks. o Don't set KSE specific data when creating new KSEs; rely on the first upcall of the KSE to set it. o Add the ability to set the maximum concurrency level and do this automatically. We should have a way to enable/disable this with some sort of tunable because some applications may not want this to be the default. o Hold the scheduling lock across thread switch calls. o If scheduling of a thread fails, make sure to remove it from the list of active threads. o Better protect accesses to a joining threads when the target thread is exited and detached. o Remove some macro definitions that are now provided by <sys/kse.h>. o Don't leave the library in threaded mode if creation of the initial KSE fails. o Wakeup idle KSEs when there are threads ready to run. o Maintain the number of threads active in the priority queue.
* Protect thread errno from being changed while operatingdeischen2003-04-231-0/+2
| | | | | | | | on behalf of the KSE. Add a kse_reinit function to reinitialize a reused KSE. Submitted by: davidxu
* Add a couple asserts to pthread_cond_foo to ensure the (low-level)deischen2003-04-221-1/+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).
* Add an i386-specifc hack to always set %gs. There still seemsdeischen2003-04-211-7/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | to be instances where the kernel doesn't properly save and/or restore it. Use noupcall and nocompleted flags in the KSE mailbox. These require kernel changes to work which will be committed sometime later. Things still work without the changes. Remove the general kse entry function and use two different functions -- one for scope system threads and one for scope process threads. The scope system function is not yet enabled and we use the same function for all threads at the moment. Keep a copy of the KSE stack for the case that a KSE runs a scope system thread and uses the same stack as the thread (no upcalls are generated, so a separate stack isn't needed). This isn't enabled yet. Use a separate field for the KSE waiting flag. It isn't correct to use the mailbox flags field. The following fixes were provided by David Xu: o Initialize condition variable locks with thread versions of the low-level locking functions instead of the kse versions. o Enable threading before creating the first thread instead of after. o Don't enter critical regions when trying to malloc/free or call functions that malloc/free. o Take the scheduling lock when inheriting thread attributes. o Check the attribute's stack pointer instead of the attributes stack size for null when allocating a thread's stack. o Add a kseg reinit function so we don't have to destroy and then recreate the same lock. o Check the return value of kse_create() and return an appropriate error if it fails. o Don't forget to destroy a thread's locks when freeing it. o Examine the correct flags word for checking to see if a thread is in a synchronization queue. Things should now work on an SMP kernel.
* Sorry folks; I accidentally committed a patch from what I was workingdeischen2003-04-181-10/+35
| | | | | | 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-509/+614
| | | | | | | | | | | | | | | | | | | 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/+30
|
* 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-23/+10
|
* Make libpthread KSE aware.mini2002-09-161-327/+7
| | | | | Reviewed by: deischen, julian Approved by: -arch
* Make the changes needed for libpthread to compile in its new home.mini2002-09-161-3/+3
| | | | | | | | 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
* Remove much of the dereferencing of the fd table entries to lookdeischen2002-08-291-3/+5
| | | | | | | | | | | at file flags and replace it with functions that will avoid null pointer checks. MFC to be done by archie ;-) PR: 42100 Reviewed by: archie, robert MFC after: 3 days
* Missed in earlier commit -- I did cvs commit src/lib/libc. Oops.rwatson2002-06-141-6/+0
|
OpenPOWER on IntegriCloud