summaryrefslogtreecommitdiffstats
path: root/lib/libthr/thread
Commit message (Collapse)AuthorAgeFilesLines
* Revert revision 214007, I realized that MySQL wants to resolvedavidxu2010-10-203-48/+2
| | | | | | | a silly rwlock deadlock problem, the deadlock is caused by writer waiters, if a thread has already locked a reader lock, and wants to acquire another reader lock, it will be blocked by writer waiters, but we had already fixed it years ago.
* Set default type to PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, thisdavidxu2010-10-181-0/+1
| | | | is the type we are using.
* s/||/&&davidxu2010-10-181-2/+2
|
* Add pthread_rwlockattr_setkind_np and pthread_rwlockattr_getkind_np, thedavidxu2010-10-183-2/+46
| | | | | | | | | functions set or get pthread_rwlock type, current supported types are: PTHREAD_RWLOCK_PREFER_READER_NP, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, PTHREAD_RWLOCK_PREFER_WRITER_NP, default is PTHREAD_RWLOCK_PREFER_WRITER_NONCECURSIVE_NP, this maintains binary compatible with old code.
* change code to use unwind.h.davidxu2010-09-302-5/+6
|
* Check invalid mutex in _mutex_cv_unlock.davidxu2010-09-291-0/+6
|
* In current code, statically initialized and destroyed object havedavidxu2010-09-285-195/+160
| | | | | | | | same null value, the code can not distinguish between them, to fix the problem, now a destroyed object is assigned to a non-null value, and it will be rejected by some pthread functions. PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP is changed to number 1, so that adaptive mutex can be statically initialized correctly.
* Report death event to debugger before moving to gc list, otherwisedavidxu2010-09-261-3/+2
| | | | debugger may can not find it on thread list.
* Only access unwind_disabled when _PTHREAD_FORCED_UNWIND is defined.davidxu2010-09-251-1/+2
|
* Add missing field.davidxu2010-09-251-0/+1
|
* Because old _pthread_cleanup_push/pop do not have frame address,davidxu2010-09-252-13/+17
| | | | | | it is incompatible with stack unwinding code, if they are invoked, disable stack unwinding for current thread, and when thread is exiting, print a warning message.
* Simplify code, and in while loop, fix operator to match the unwindingdavidxu2010-09-251-7/+4
| | | | direction.
* To support stack unwinding for cancellation points, add -fexceptions flagdavidxu2010-09-253-2/+17
| | | | | | | for them, two functions _pthread_cancel_enter and _pthread_cancel_leave are added to let thread enter and leave a cancellation point, it also makes it possible that other functions can be cancellation points in libraries without having to be rewritten in libthr.
* inline testcancel() into thr_cancel_leave(), because cancel_pending isdavidxu2010-09-241-2/+3
| | | | almost false, this makes a slight better branch predicting.
* In most cases, cancel_point and cancel_async needn't be checked again,davidxu2010-09-243-5/+3
| | | | because cancellation is almostly checked at cancellation points.
* If we are at cancellation point, always work as deferred mode despitedavidxu2010-09-211-34/+32
| | | | | | whether asynchronous mode is turned on or not, this always gives us a chance to decide whether thread should be canceled or not in cancellation points.
* Because atfork lock is held while forking, a thread cancellation triggereddavidxu2010-09-194-12/+13
| | | | by atfork handler is unsafe, use intenal flag no_cancel to disable it.
* Fix typo.davidxu2010-09-191-1/+1
|
* - _Unwind_Resume function is not used, remove it.davidxu2010-09-191-14/+8
| | | | | | - Use a store barrier to make sure uwl_forcedunwind is lastest thing other threads can see. - Add some comments.
* Fix a race condition when finding stack unwinding functions.davidxu2010-09-191-7/+20
|
* add code to support stack unwinding when thread exits. note that onlydavidxu2010-09-155-1/+176
| | | | | | defer-mode cancellation works, asynchrnous mode does not work because it lacks of libuwind's support. stack unwinding is not enabled unless LIBTHR_UNWIND_STACK is defined in Makefile.
* Move back IN_GCLIST flag into field tlflags, since thread list and gc listdavidxu2010-09-151-6/+6
| | | | still share same lock.
* Don't compare thread pointers again.davidxu2010-09-131-3/+3
|
* Fix copy&paste problem.davidxu2010-09-131-2/+2
|
* PS_DEAD state needs not be checked because _thr_find_thread() has alreadydavidxu2010-09-131-4/+0
| | | | checked it.
* Convert thread list lock from mutex to rwlock.davidxu2010-09-1315-129/+153
|
* Because POSIX does not allow EINTR to be returned from sigwait(),davidxu2010-09-101-6/+8
| | | | | | | | add a wrapper for it in libc and rework the code in libthr, the system call still can return EINTR, we keep this feature. Discussed on: thread Reviewed by: jilles
* To avoid possible race condition, SIGCANCEL is always sent except thedavidxu2010-09-081-1/+1
| | | | thread is dead.
* Fix off-by-one error in function _thr_sigact_unload, also disable thedavidxu2010-09-061-3/+5
| | | | | function, it seems some gnome application tends to crash if we unregister sigaction automatically.
* Remove incorrect comments, also make sure signal isdavidxu2010-09-011-5/+4
| | | | disabled when unregistering sigaction.
* In function __pthread_cxa_finalize(), also make code for removingdavidxu2010-09-011-1/+8
| | | | atfork handler be async-signal safe.
* pthread_atfork should acquire writer lock and protect the codedavidxu2010-09-011-1/+3
| | | | with critical region.
* Change atfork lock from mutex to rwlock, also make mutexes used by malloc()davidxu2010-09-016-28/+60
| | | | | | | | module private type, when private type mutex is locked/unlocked, thread critical region is entered or leaved. These changes makes fork() async-signal safe which required by POSIX. Note that user's atfork handler still needs to be async-signal safe, but it is not problem of libthr, it is user's responsiblity.
* Add signal handler wrapper, the reason to add it becauses there aredavidxu2010-09-0114-273/+591
| | | | | | | | | | | | | | | | | | | | | | | some cases we want to improve: 1) if a thread signal got a signal while in cancellation point, it is possible the TDP_WAKEUP may be eaten by signal handler if the handler called some interruptibly system calls. 2) In signal handler, we want to disable cancellation. 3) When thread holding some low level locks, it is better to disable signal, those code need not to worry reentrancy, sigprocmask system call is avoided because it is a bit expensive. The signal handler wrapper works in this way: 1) libthr installs its signal handler if user code invokes sigaction to install its handler, the user handler is recorded in internal array. 2) when a signal is delivered, libthr's signal handler is invoke, libthr checks if thread holds some low level lock or is in critical region, if it is true, the signal is buffered, and all signals are masked, once the thread leaves critical region, correct signal mask is restored and buffered signal is processed. 3) before user signal handler is invoked, cancellation is temporarily disabled, after user signal handler is returned, cancellation state is restored, and pending cancellation is rescheduled.
* Unregister thread specific data destructor when a corresponding dsodavidxu2010-08-273-0/+23
| | | | is unloaded.
* clear lock to zero state if it is destroyed.davidxu2010-08-271-0/+3
|
* eliminate unused code.davidxu2010-08-262-17/+0
|
* Decrease rdlock count only when thread unlocked a reader lock.davidxu2010-08-261-1/+1
| | | | MFC after: 3 days
* Remove unused source.kib2010-08-241-57/+0
| | | | MFC after: 2 weeks
* The __hidden definition is provided by sys/cdefs.h.kib2010-08-241-4/+0
| | | | MFC after: 2 weeks
* Add wrapper for setcontext() and swapcontext(), the wrappersdavidxu2010-08-242-14/+51
| | | | unblock SIGCANCEL which is needed by thread cancellation.
* On shared object unload, in __cxa_finalize, call and clear all installedkib2010-08-232-0/+25
| | | | | | | | | | | | | | | | | | | | | | atexit and __cxa_atexit handlers that are either installed by unloaded dso, or points to the functions provided by the dso. Use _rtld_addr_phdr to locate segment information from the address of private variable belonging to the dso, supplied by crtstuff.c. Provide utility function __elf_phdr_match_addr to do the match of address against dso executable segment. Call back into libthr from __cxa_finalize using weak __pthread_cxa_finalize symbol to remove any atfork handler which function points into unloaded object. The rtld needs private __pthread_cxa_finalize symbol to not require resolution of the weak undefined symbol at initialization time. This cannot work, since rtld is relocated before sym_zero is set up. Idea by: kan Reviewed by: kan (previous version) MFC after: 3 weeks
* Reduce redundant code.davidxu2010-08-201-76/+21
| | | | Submitted by: kib
* In current implementation, thread cancellation is done in signal handler,davidxu2010-08-206-99/+284
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | which does not know what is the state of interrupted system call, for example, open() system call opened a file and the thread is still cancelled, result is descriptor leak, there are other problems which can cause resource leak or undeterminable side effect when a thread is cancelled. However, this is no longer true in new implementation. In defering mode, a thread is canceled if cancellation request is pending and later the thread enters a cancellation point, otherwise, a later pthread_cancel() just causes SIGCANCEL to be sent to the target thread, and causes target thread to abort system call, userland code in libthr then checks cancellation state, and cancels the thread if needed. For example, the cancellation point open(), the thread may be canceled at start, but later, if it opened a file descriptor, it is not canceled, this avoids file handle leak. Another example is read(), a thread may be canceled at start of the function, but later, if it read some bytes from a socket, the thread is not canceled, the caller then can decide if it should still enable cancelling or disable it and continue reading data until it thinks it has read all bytes of a packet, and keeps a protocol stream in health state, if user ignores partly reading of a packet without disabling cancellation, then second iteration of read loop cause the thread to be cancelled. An exception is that the close() cancellation point always closes a file handle despite whether the thread is cancelled or not. The old mechanism is still kept, for a functions which is not so easily to fix a cancellation problem, the rough mechanism is used. Reviewed by: kib@
* According to specification, function fcntl() is a cancellation point onlydavidxu2010-08-201-4/+11
| | | | when cmd argument is F_SETLKW.
* Tweak code a bit to be POSIX compatible, when a cancellation requestdavidxu2010-08-171-0/+2
| | | | | | | | | | | | is acted upon, or when a thread calls pthread_exit(), the thread first disables cancellation by setting its cancelability state to PTHREAD_CANCEL_DISABLE and its cancelability type to PTHREAD_CANCEL_DEFERRED. The cancelability state remains set to PTHREAD_CANCEL_DISABLE until the thread has terminated. It has no effect if a cancellation cleanup handler or thread-specific data destructor routine changes the cancelability state to PTHREAD_CANCEL_ENABLE.
* Use _SIG_VALID instead of expanded form of the macro.kib2010-07-121-1/+1
| | | | | Submitted by: Garrett Cooper <yanegomi gmail com> MFC after: 1 week
* Coalesce one more broken line.deischen2010-05-241-2/+1
|
* Coalesce a couple of broken lines since they can fit within 80deischen2010-05-241-4/+2
| | | | characters. Little nit found while looking at a bug report.
* remove file thr_sem_new.c.davidxu2010-01-051-1/+0
|
OpenPOWER on IntegriCloud