summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread/thr_kern.c
Commit message (Collapse)AuthorAgeFilesLines
* Repo copy libpthreads to libkse.obrien2007-10-091-2549/+0
| | | | | | This introduces the WITHOUT_LIBKSE nob, and changes WITHOUT_LIBPTHREADS to mean with neither threading libs. Approved by: re(kensmith)
* Oops, fix a typo in the last commit :-/brian2007-03-051-1/+1
|
* In the NOTYET code path when a process forks, the remainingbrian2007-03-051-7/+4
| | | | | | | | | | | 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
* Clean bound and non-bound pthread structures consistently beforepeadar2006-12-181-4/+5
| | | | | | | | | | | | 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
* Don't forget to initialize a tailq before using it.deischen2006-02-161-0/+1
| | | | | MFC candidate Noticed by: luoqi
* For the ``#ifdef NOTYET'' code that allows calling non-async-safebrian2006-01-031-1/+1
| | | | | | | | | | 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
* Modify the code path of the ifdef NOTYET part of _kse_single_thread():brian2005-09-241-7/+10
| | | | | | | | | | | | | | | | | | | | 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]
* Allocate a thread's tcb last so it is easier to handle failures todeischen2005-08-301-20/+21
| | | | | | malloc() siginfo. PR: 85468
* Handle failure to malloc() part of the thread structure.deischen2005-08-291-3/+4
| | | | PR: 83457
* Use a generic way to back threads out of wait queues when handlingdeischen2004-12-181-39/+16
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* 1. Move thread list flags into new separate member, and atomicallydavidxu2004-10-231-10/+27
| | | | | | | | | | | 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
* if system scope thread didn't set timeout, don't call clock_gettime syscalldavidxu2004-10-081-8/+9
| | | | | | before and after sleeping. Reviewed by: deischen
* Make sure we don't call _thr_start_sig_daemon() when SYSTEM_SCOPE_ONLY is ↵ssouhlal2004-09-241-2/+3
| | | | | | defined. This makes libpthread usable on powerpc. Approved by: grehan (mentor), deischen
* Add TLS support for i386 and amd64.dfr2004-08-151-1/+1
|
* As long as we have a knob to force system scope threads, why not havedeischen2004-08-121-4/+4
| | | | | | | | | | | | | 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
* Check debugger suspending flag for system scope thread.davidxu2004-08-081-3/+7
| | | | Reviewed by: deischen
* Add a way to force 1:1 mode for libpthread. To do this, definedeischen2004-08-071-29/+27
| | | | | | | | | | | 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-2/+2
| | | | Dicussed with: deischen
* Add code to support thread debugging.davidxu2004-07-131-8/+54
| | | | | | | | | | | | | | | 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.
* After forking and initializing the library to single-threadeddeischen2004-04-081-2/+3
| | | | | | | | | | mode (where the forked thread is the one and only thread and is marked as system scope), set the system scope flag before initializing the signal mask. This prevents trying to use internal locks that haven't yet been initialized. Reported by: Dan Nelson <dnelson at allantgroup.com> Reviewed by: davidxu
* Replace a comment with more accurated one, memory heap is now protected bydavidxu2003-12-191-3/+2
| | | | new fork() wrapper.
* Rename _thr_enter_cancellation_point to _thr_cancel_enter, renamedavidxu2003-12-091-18/+11
| | | | | | | | | | | | | | | | | | | | | _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-91/+24
| | | | | | | | | | | | | | 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)
* If a thread in critical region got a synchronous signal, according currentdavidxu2003-11-091-0/+2
| | | | | | signal handling mode, there is no chance to handle the signal, something must be wrong in the library, just call kse_thr_interrupt to dump its core. I have the code for a long time, but forgot to commit it.
* Add an implementation for pthread_atfork().deischen2003-11-041-1/+15
| | | | | | | | 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-69/+156
| | | | | | | thread state is changed from RUNNING to WAIT state and do some cancellation operations for every cancellable state. Reviewed by: deischen
* When concurrency level is reduced and a kse is exiting, make sure no otherdavidxu2003-09-291-0/+13
| | | | | | threads are still referencing the kse by migrating them to initial kse. Reviewed by: deischen
* Remove unused variable.davidxu2003-09-281-2/+0
|
* Free thread name memory if there is.davidxu2003-09-231-0/+4
|
* Make KSE_STACKSIZE machine dependent by moving it from thr_kern.c tomarcel2003-09-191-2/+0
| | | | | | pthread_md.h. This commit only moves the definition; it does not change it for any of the platforms. This more easily allows 64-bit architectures (in particular) to pick a slightly larger stack size.
* Fix a typo. Also turn on PTHREAD_SCOPE_SYSTEM after fork().davidxu2003-09-161-1/+2
|
* 1. Allocating and freeing lock related resource in _thr_alloc and _thr_freedavidxu2003-09-141-73/+44
| | | | | | | | | | | 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
* Add code to support barrier synchronous object and implementdavidxu2003-09-041-2/+5
| | | | | | pthread_mutex_timedlock(). Reviewed by: deischen
* Allow hooks registered by atexit() to run with current thread pointer set,davidxu2003-09-041-1/+4
| | | | without this change, my atexit test dumps core.
* Move kse_wakeup_multi call to just before KSE_SCHED_UNLOCK.davidxu2003-09-031-4/+2
| | | | Tested on: SMP
* Allow the concurrency level to be reduced.deischen2003-08-301-7/+8
| | | | Reviewed by: davidxu
* Treat initial thread as scope system thread when KSE mode is not activateddavidxu2003-08-181-15/+9
| | | | | | | | | 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
* Keep initial kse and kse group just like we keep initial thread,davidxu2003-08-161-9/+11
| | | | | | Don't free them, so some code can still reference them. Reviewed by: deischen
* Always set tcb for bound thread, and switch tcb for M:N thread at correctdavidxu2003-08-131-7/+18
| | | | time.
* Correctly set current tcb. This fixes some IA64/KSE problems.davidxu2003-08-121-17/+11
| | | | Reviewed by: deischen, julian
* Initialize rtld lock just before turning on thread mode anddavidxu2003-08-101-19/+33
| | | | uninitialize rtld lock after thread mode shutdown.
* o Add code to GC freed KSEs and KSE groupsdavidxu2003-08-081-25/+116
| | | | | | | o Fix a bug in kse_free_unlocked(), kcb_dtor shouldn't be called because the KSE is cached and will be resued in _kse_alloc(). Reviewed by: deischen
* Don't call kse_set_curthread() when scheduling a new bounddeischen2003-08-061-2/+3
| | | | | | | thread. It should only be called by the current kse and never by a KSE on behalf of another. Submitted by: davidxu
* Rethink the MD interfaces for libpthread to account fordeischen2003-08-051-156/+160
| | | | | | | | | 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
* Move idle kse wakeup to outside of regions where locks are held.deischen2003-07-231-35/+57
| | | | | | | | 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-36/+21
| | | | | | | | 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-104/+217
| | | | | | | | | | | | | 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
* Restore signal mask correctly after fork().davidxu2003-07-091-1/+2
|
* Save and restore thread's error code around signal handling.davidxu2003-07-091-1/+2
| | | | Reviewed by: deischen
* Check if thread is in critical region, only testing check_pendingdavidxu2003-07-031-1/+2
| | | | is not enough.
OpenPOWER on IntegriCloud