summaryrefslogtreecommitdiff
path: root/lib/libpthread/thread/thr_private.h
Commit message (Collapse)AuthorAgeFilesLines
* Code clean up, remove unused MACROS and function prototypes.David Xu2003-12-191-18/+0
| | | | Notes: svn path=/head/; revision=123666
* Remove an unused struct definition.Daniel Eischen2003-12-091-12/+0
| | | | Notes: svn path=/head/; revision=123356
* Add cancellation points for accept() and connect().Daniel Eischen2003-12-091-0/+2
| | | | Notes: svn path=/head/; revision=123355
* Rename _thr_enter_cancellation_point to _thr_cancel_enter, renameDavid Xu2003-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 Notes: svn path=/head/; revision=123312
* 1.Macro optimizing KSE_LOCK_ACQUIRE and THR_LOCK_ACQUIRE to use static fallDavid Xu2003-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) Notes: svn path=/head/; revision=123048
* Add an implementation for pthread_atfork().Daniel Eischen2003-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 Notes: svn path=/head/; revision=122075
* Complete cancellation support for M:N threads, check cancelling flag whenDavid Xu2003-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 Notes: svn path=/head/; revision=120896
* Save and restore timeout field for signal frame just like what we didDavid Xu2003-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. Notes: svn path=/head/; revision=120338
* 1. Allocating and freeing lock related resource in _thr_alloc and _thr_freeDavid Xu2003-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 Notes: svn path=/head/; revision=120074
* Original pthread_once code has memory leak if pthread_once_t is used inDavid Xu2003-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 Notes: svn path=/head/; revision=119928
* Add code to support pthread spin lock.David Xu2003-09-091-0/+6
| | | | | | | Reviewed by: deischen Notes: svn path=/head/; revision=119909
* Add code to support barrier synchronous object and implementDavid Xu2003-09-041-0/+12
| | | | | | | | | pthread_mutex_timedlock(). Reviewed by: deischen Notes: svn path=/head/; revision=119736
* Allow the concurrency level to be reduced.Daniel Eischen2003-08-301-0/+1
| | | | | | | Reviewed by: davidxu Notes: svn path=/head/; revision=119577
* Treat initial thread as scope system thread when KSE mode is not activatedDavid Xu2003-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 Notes: svn path=/head/; revision=119063
* Rethink the MD interfaces for libpthread to account forDaniel Eischen2003-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 Notes: svn path=/head/; revision=118510
* Simplify sigwait code a bit by using a waitset and removing oldsigmask.David Xu2003-07-271-2/+5
| | | | | | | Reviewed by: deischen Notes: svn path=/head/; revision=118075
* Move idle kse wakeup to outside of regions where locks are held.Daniel Eischen2003-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 Notes: svn path=/head/; revision=117907
* Cleanup thread accounting. Don't reset a threads timesliceDaniel Eischen2003-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 Notes: svn path=/head/; revision=117715
* o Eliminate upcall for PTHREAD_SYSTEM_SCOPE thread, now itDavid Xu2003-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 Notes: svn path=/head/; revision=117706
* o Use a daemon thread to monitor signal events in kernel, if pendingDavid Xu2003-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(). Notes: svn path=/head/; revision=116977
* Untangle the inter-dependency of kse types and ksd types/functionsMarcel Moolenaar2003-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. Notes: svn path=/head/; revision=116771
* Attempt to eliminate PLT relocations from rwlock aquire/releaseAlexander Kabaev2003-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) Notes: svn path=/head/; revision=115399
* Don't really spin on a spinlock; silently convert it to the sameDaniel Eischen2003-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) Notes: svn path=/head/; revision=115381
* Add a method of yielding the current thread with the schedulerDaniel Eischen2003-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) Notes: svn path=/head/; revision=115080
* Fix suspend and resume.Daniel Eischen2003-05-041-0/+5
| | | | | | | Submitted (in part) by: Kazuaki Oda <kaakun@highway.ne.jp> Notes: svn path=/head/; revision=114664
* Move the mailbox to the beginning of the thread and align theDaniel Eischen2003-04-301-4/+6
| | | | | | | thread so that the context (SSE FPU state) is also aligned. Notes: svn path=/head/; revision=114295
* o Don't add a scope system thread's KSE to the list of availableDaniel Eischen2003-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. Notes: svn path=/head/; revision=114187
* Protect thread errno from being changed while operatingDaniel Eischen2003-04-231-0/+2
| | | | | | | | | | | on behalf of the KSE. Add a kse_reinit function to reinitialize a reused KSE. Submitted by: davidxu Notes: svn path=/head/; revision=113942
* Add a couple asserts to pthread_cond_foo to ensure the (low-level)Daniel Eischen2003-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). Notes: svn path=/head/; revision=113870
* Add an i386-specifc hack to always set %gs. There still seemsDaniel Eischen2003-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. Notes: svn path=/head/; revision=113786
* Sorry folks; I accidentally committed a patch from what I was workingDaniel Eischen2003-04-181-10/+35
| | | | | | | | | on a couple of days ago. This should be the most recent changes. Noticed by: davidxu Notes: svn path=/head/; revision=113661
* Revamp libpthread so that it has a chance of working in an SMPDaniel Eischen2003-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 Notes: svn path=/head/; revision=113658
* Deliver signals posted via an upcall to the appropriate thread.Jonathan Mini2003-02-171-0/+30
| | | | Notes: svn path=/head/; revision=111035
* Schedule an idle context to block until timeouts expire without blockingJonathan Mini2002-11-121-0/+12
| | | | | | | further upcalls. Notes: svn path=/head/; revision=106786
* Use KSE to schedule threads.Jonathan Mini2002-10-301-23/+10
| | | | Notes: svn path=/head/; revision=106191
* Make libpthread KSE aware.Jonathan Mini2002-09-161-327/+7
| | | | | | | | Reviewed by: deischen, julian Approved by: -arch Notes: svn path=/head/; revision=103419
* Make the changes needed for libpthread to compile in its new home.Jonathan 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 Notes: svn path=/head/; revision=103388
* Remove much of the dereferencing of the fd table entries to lookDaniel Eischen2002-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 Notes: svn path=/head/; revision=102590
* Missed in earlier commit -- I did cvs commit src/lib/libc. Oops.Robert Watson2002-06-141-6/+0
| | | | Notes: svn path=/head/; revision=98205
* Revamp suspend and resume. While I'm here add pthread_suspend_all_np()Daniel Eischen2002-05-241-27/+4
| | | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=97204
* Undo namespace pollution by prefixing the globals pthread_guard_default andAlfred Perlstein2002-05-151-2/+2
| | | | | | | | | | | pthread_page_size. Fix a bunch line wrapping. Pointed out by: deischen Notes: svn path=/head/; revision=96636
* Don't use PAGE_SIZE in userland, instead use getpagesize(), this is toAlfred Perlstein2002-05-131-5/+5
| | | | | | | | | | allow running on other arches when the instructions are supported but the page size granularity is not. Glanced at by: peter Notes: svn path=/head/; revision=96501
* Add the ability to recognize old references to keys, and return NULLDaniel Eischen2002-03-191-10/+8
| | | | | | | | when old keys are referenced (after pthread_key_delete()) via pthread_getspecific(). Notes: svn path=/head/; revision=92730
* Don't rely on <sys/signal.h> to include <sys/ucontext.h>Daniel Eischen2002-02-171-0/+1
| | | | Notes: svn path=/head/; revision=90774
* This has been sitting in my local tree long enough. Remove the useDaniel Eischen2002-02-091-46/+9
| | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=90431
* Use the real function address (instead of function address + 8) for theDaniel Eischen2001-12-221-2/+2
| | | | | | | | | | | | return address when modifying a jmp_buf to create a new thread context. Also set t12 with the return address. This should fix libc_r on alpha. With much detective work by: Bernd Walter <ticso@cicely.de> Notes: svn path=/head/; revision=88401
* Fix pthread_join so that it works if the target thread exits whileDaniel Eischen2001-11-171-2/+11
| | | | | | | | | | the joining thread is in a signal handler. Reported by: Loren James Rittle <rittle@labs.mot.com> MFC after: 1 week Notes: svn path=/head/; revision=86499
* Make libc_r check the kern.usrstack sysctl instead of using internalPeter Wemm2001-10-261-0/+7
| | | | | | | | | | 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. Notes: svn path=/head/; revision=85567
* Style: sort __sys_foo() prototypes, tabs -> spaces, etc.Ruslan Ermilov2001-10-261-78/+78
| | | | Notes: svn path=/head/; revision=85559
* Removed:Ruslan Ermilov2001-10-261-14/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | - uthread_signal.c; libc_r does not wrap signal() since 1998/04/29. - uthread_attr_setprio.c; it was never connected to the build, and pthread_attr_setprio() does not exist in POSIX. - uthread_sigblock.c and uthread_sigsetmask.c; these were no-ops bloating libc_r's space. pthread_private.h: - Removed prototypes of non-syscalls: send(). - Removed prototypes of unused syscalls: sigpending(), sigsuspend(), and select(). - Fixed prototype of fork(). - MFS: Fixed prototypes of <sys/socket.h> syscalls. Reviewed by: deischen Approved by: deischen, jasone Notes: svn path=/head/; revision=85557