summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread
Commit message (Collapse)AuthorAgeFilesLines
* accept() returns a file descriptor when it succeeds which is verydeischen2003-12-092-2/+2
| | | | | | | | | likely to be non-zero. When leaving the cancellation point, check the return value against -1 to see if cancellation should be checked. While I'm here, make the same change to connect() just to be consisitent. Pointed out by: davidxu
* Remove an unused struct definition.deischen2003-12-091-12/+0
|
* Add cancellation points for accept() and connect().deischen2003-12-094-0/+102
|
* Use mutex instead of low level thread lock to implement spinlock, thisdavidxu2003-12-091-30/+18
| | | | avoids signal to be blocked when otherwise it can be handled.
* Rename _thr_enter_cancellation_point to _thr_cancel_enter, renamedavidxu2003-12-0930-136/+148
| | | | | | | | | | | | | | | | | | | | | _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
* More reliably check timeout for pthread_mutex_timedlock.davidxu2003-12-091-1/+1
|
* Go back to using rev 1.18 where thread locks are used instead of KSEdeischen2003-12-081-17/+16
| | | | | | | locks for [libc] spinlock implementation. This was previously backed out because it exposed a bug in ia64 implementation. OK'd by: marcel
* 1.Macro optimizing KSE_LOCK_ACQUIRE and THR_LOCK_ACQUIRE to use static falldavidxu2003-11-292-99/+31
| | | | | | | | | | | | | | 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)
* 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)
* Back out last change and go back to using KSE locks instead of threaddeischen2003-11-161-16/+17
| | | | | | locks until we know why this breaks ia64. Reported by: marcel
* 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.
* Use THR lock instead of KSE lock to avoid scheduler be blocked in spinlock.davidxu2003-11-081-17/+16
| | | | Reviewed by: deischen
* style(9)deischen2003-11-051-40/+53
| | | | Reviewed by: bde
* Don't declare the malloc lock; use the declaration provided in libc.deischen2003-11-051-1/+6
| | | | Noticed by: bde
* Add pthread_atfork() source code. Dan forgot to commit this file.davidxu2003-11-051-0/+56
|
* Add an implementation for pthread_atfork().deischen2003-11-045-6/+71
| | | | | | | | 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
* Add the ability to reinitialize a spinlock (libc/libpthreaddeischen2003-11-041-12/+17
| | | | | | internal lock, not a pthread spinlock). Reviewed by: davidxu
* s/foo()/foo(void)/deischen2003-11-041-2/+3
| | | | Add a blank line after a variable declaration.
* Libpthread uses the convention that all of its (non-weak) symbolsdeischen2003-11-041-5/+11
| | | | | begin with underscores and provide weak definitions without underscores. Make the pthread spinlock conform to this convention.
* Add the ability to reinitialize a mutex (internally, not a userlanddeischen2003-11-041-7/+20
| | | | | | API). Reviewed by: davidxu
* Fix some comments for last commit.davidxu2003-10-081-5/+4
|
* Complete cancellation support for M:N threads, check cancelling flag whendavidxu2003-10-082-69/+157
| | | | | | | thread state is changed from RUNNING to WAIT state and do some cancellation operations for every cancellable state. Reviewed by: deischen
* Use thread lock instead of scheduler lock to eliminate lock contentiondavidxu2003-10-081-18/+21
| | | | | | for all wrapped syscalls under SMP. 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
|
* pthread API should return error code in return value not in errno.davidxu2003-09-251-2/+2
| | | | Reviewed by: deischen
* If syscall failed, restore old sigaction and return error to thread.davidxu2003-09-251-11/+19
|
* As comments in _mutex_lock_backout state, only current threaddavidxu2003-09-241-6/+4
| | | | | | | | | | | | | | can clear the pointer to mutex, not the thread doing mutex handoff. Because _mutex_lock_backout does not hold scheduler lock while testing THR_FLAGS_IN_SYNCQ and then reading mutex pointer, it is possible mutex owner begin to unlock and handoff the mutex to the current thread, and mutex pointer will be cleared to NULL before current thread reading it, so current thread will end up with deferencing a NULL pointer, Fix the race by making mutex waiters to clear their mutex pointers. While I am here, also save inherited priority in mutex for PTHREAD_PRIO_INERIT mutex in mutex_trylock_common just like what we did in mutex_lock_common.
* Free thread name memory if there is.davidxu2003-09-231-0/+4
|
* Save and restore timeout field for signal frame just like what we diddavidxu2003-09-222-1/+4
| | | | | | 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.
* Print waitset correctly.davidxu2003-09-221-1/+1
|
* 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.
* pthread api should return error code in return value, not in errno.davidxu2003-09-181-2/+1
|
* Fix a typo. Also turn on PTHREAD_SCOPE_SYSTEM after fork().davidxu2003-09-161-1/+2
|
* Fix bogus comment and assign sigmask in critical region, usedavidxu2003-09-151-2/+4
| | | | SIG_CANTMASK to remove unmaskable signal masks.
* Fix a bogus comment, sigmask must be maintained correctly,davidxu2003-09-151-1/+1
| | | | it will be inherited in pthread_create.
* 1. Allocating and freeing lock related resource in _thr_alloc and _thr_freedavidxu2003-09-144-94/+87
| | | | | | | | | | | 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
* When invoking an old style signal handler, use true traditional BSD style todavidxu2003-09-141-6/+13
| | | | | | invoke signal handler. Reviewed by: deischen
* Respect POSIX specification, a value return from pthread_attr_getguardsizedavidxu2003-09-142-16/+18
| | | | | | | | | should be a value past to pthread_attr_setguardsize, not a rounded up value. Also fix a stack size matching bug in thr_stack.c, now stack matching code uses number of pages but not bytes length to match stack size, so for example, size 512 bytes and size 513 bytes should both match 1 page stack size. Reviewed by: deischen
* Avoid garbage bits in c_flags by direct assigning value.davidxu2003-09-141-1/+1
| | | | Reviewed by: deischen
* If user is seting scope process flag, clear PTHREAD_SCOPE_SYSTEM bitdavidxu2003-09-141-2/+4
| | | | | | accordingly. Reviewed by: deischen
* Check invalid parameter and return EINVAL.davidxu2003-09-141-0/+3
| | | | Reviewed by: deischen
* Original pthread_once code has memory leak if pthread_once_t is used indavidxu2003-09-092-9/+52
| | | | | | | | | | | | | | | 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-093-0/+161
| | | | Reviewed by: deischen
* Add small piece of code to support pthread_rwlock_timedrdlock anddavidxu2003-09-061-8/+43
| | | | pthread_rwlock_timedrwlock.
* Add code to support barrier synchronous object and implementdavidxu2003-09-046-6/+346
| | | | | | pthread_mutex_timedlock(). Reviewed by: deischen
* Remove repeated macro THR_IN_CONDQ.davidxu2003-09-041-1/+0
|
* 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.
* Don't assume sizeof(long) = sizeof(int) on x86; use intdeischen2003-09-038-0/+17
| | | | | | | | | | | | instead of long types for low-level locks. Add prototypes for some internal libc functions that are wrapped by the library as cancellation points. Add memory barriers to alpha atomic swap functions (submitted by davidxu). Requested by: bde
* Move kse_wakeup_multi call to just before KSE_SCHED_UNLOCK.davidxu2003-09-031-4/+2
| | | | Tested on: SMP
OpenPOWER on IntegriCloud