summaryrefslogtreecommitdiffstats
path: root/lib/libthr/thread/thr_private.h
Commit message (Collapse)AuthorAgeFilesLines
* MFC r303393:kib2016-08-031-1/+0
| | | | Remove empty initializer for the once facility.
* MFC r297535:kib2016-04-111-1/+0
| | | | Remove unused variable.
* MFC r295407:kib2016-03-121-0/+2
| | | | Make libc __pthread_map_stacks_exec() interposed.
* MFC r278751:kib2015-02-171-0/+4
| | | | Properly interpose libc spinlocks, was missed in r276630.
* Fix known issues which blow up the process after dlopen("libthr.so")kib2015-01-181-2/+18
| | | | | | | | | | | | | | | | | | | | | (or loading a dso linked to libthr.so into process which was not linked against threading library). MFC r276630: Remove interposing, fix malloc, reinstall signal handlers wrappers on libthr load. MFC r276681: Avoid calling internal libc function through PLT or accessing data though GOT. MFC r277032: Reduce the size of the interposing table and amount of cancellation-handling code in the libthr. MFC note: r276646 ("do not erronously export 'openat' symbol from rtld") is not applicable to stable/10 yet, since PATHFDS support was not merged.
* MFC r258499:kib2013-11-301-0/+3
| | | | | | | Fix for the spurious signal handler call with zero signo in the threaded process. Approved by: re (hrs)
* libthr: Remove _thr_rtld_fini(), unused since r245630.jilles2013-04-121-1/+0
|
* In suspend_common(), don't wait for a thread which is in creation, becausedavidxu2012-08-271-0/+6
| | | | | | | pthread_suspend_all_np() may have already suspended its parent thread. Add locking code in pthread_suspend_all_np() to only allow one thread to suspend other threads, this eliminates a deadlock where two or more threads try to suspend each others.
* MFp4:davidxu2012-08-111-4/+4
| | | | | Further decreases unexpected context switches by defering mutex wakeup until internal sleep queue lock is released.
* MFp4:davidxu2012-05-031-0/+1
| | | | | | | Enqueue thread in LIFO, this can cause starvation, but it gives better performance. Use _thr_queuefifo to control the frequency of FIFO vs LIFO, you can use environment string LIBPTHREAD_QUEUE_FIFO to configure the variable.
* Set SIGCANCEL to SIGTHR as part of some cleanup of DTrace code.gnn2012-04-181-1/+1
| | | | | Reviewed by: davidxu@ MFC after: 1 week
* umtx operation UMTX_OP_MUTEX_WAKE has a side-effect that it accessesdavidxu2012-04-051-2/+0
| | | | | | | | | | | | | | | | | | | | | a mutex after a thread has unlocked it, it event writes data to the mutex memory to clear contention bit, there is a race that other threads can lock it and unlock it, then destroy it, so it should not write data to the mutex memory if there isn't any waiter. The new operation UMTX_OP_MUTEX_WAKE2 try to fix the problem. It requires thread library to clear the lock word entirely, then call the WAKE2 operation to check if there is any waiter in kernel, and try to wake up a thread, if necessary, the contention bit is set again by the operation. This also mitgates the chance that other threads find the contention bit and try to enter kernel to compete with each other to wake up sleeping thread, this is unnecessary. With this change, the mutex owner is no longer holding the mutex until it reaches a point where kernel umtx queue is locked, it releases the mutex as soon as possible. Performance is improved when the mutex is contensted heavily. On Intel i3-2310M, the runtime of a benchmark program is reduced from 26.87 seconds to 2.39 seconds, it even is better than UMTX_OP_MUTEX_WAKE which is deprecated now. http://people.freebsd.org/~davidxu/bench/mutex_perf.c
* When destroying a barrier, waiting all threads exit the barrier,davidxu2012-03-161-3/+5
| | | | | this makes it possible a thread received PTHREAD_BARRIER_SERIAL_THREAD immediately free memory area of the barrier.
* Plug a memory leak. When a cached thread is reused, don't clear sleepdavidxu2012-02-071-6/+9
| | | | | | | queue pointers, just reuse it. PR: 164828 MFC after: 1 week
* Implement the __pthread_map_stacks_exec() for libthr.kib2011-01-091-0/+1
| | | | | | | | | | | | Stack creation code is changed to call _rtld_get_stack_prot() to get the stack protection right. There is a race where thread is created during dlopen() of dso that requires executable stacks. Then, _rtld_get_stack_prot() may return PROT_READ | PROT_WRITE, but thread is still not linked into the thread list. In this case, the callback misses the thread stack, and rechecks the required protection afterward. Reviewed by: davidxu
* MFp4:davidxu2010-12-221-9/+106
| | | | | | | | | | | | | | | - Add flags CVWAIT_ABSTIME and CVWAIT_CLOCKID for umtx kernel based condition variable, this should eliminate an extra system call to get current time. - Add sub-function UMTX_OP_NWAKE_PRIVATE to wake up N channels in single system call. Create userland sleep queue for condition variable, in most cases, thread will wait in the queue, the pthread_cond_signal will defer thread wakeup until the mutex is unlocked, it tries to avoid an extra system call and a extra context switch in time window of pthread_cond_signal and pthread_mutex_unlock. The changes are part of process-shared mutex project.
* Get cpuset in pthread_attr_get_np() and free it in pthread_attr_destroy().davidxu2010-10-251-0/+2
| | | | MFC after: 7 days
* Revert revision 214007, I realized that MySQL wants to resolvedavidxu2010-10-201-3/+0
| | | | | | | 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.
* Add pthread_rwlockattr_setkind_np and pthread_rwlockattr_getkind_np, thedavidxu2010-10-181-0/+3
| | | | | | | | | 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-301-1/+2
|
* In current code, statically initialized and destroyed object havedavidxu2010-09-281-0/+10
| | | | | | | | 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.
* Add missing field.davidxu2010-09-251-0/+1
|
* To support stack unwinding for cancellation points, add -fexceptions flagdavidxu2010-09-251-1/+2
| | | | | | | 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.
* In most cases, cancel_point and cancel_async needn't be checked again,davidxu2010-09-241-1/+0
| | | | because cancellation is almostly checked at cancellation points.
* Because atfork lock is held while forking, a thread cancellation triggereddavidxu2010-09-191-4/+4
| | | | by atfork handler is unsafe, use intenal flag no_cancel to disable it.
* add code to support stack unwinding when thread exits. note that onlydavidxu2010-09-151-0/+9
| | | | | | 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.
* Fix copy&paste problem.davidxu2010-09-131-2/+2
|
* Convert thread list lock from mutex to rwlock.davidxu2010-09-131-10/+34
|
* Change atfork lock from mutex to rwlock, also make mutexes used by malloc()davidxu2010-09-011-1/+2
| | | | | | | | 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-011-10/+23
| | | | | | | | | | | | | | | | | | | | | | | 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-271-0/+1
| | | | is unloaded.
* eliminate unused code.davidxu2010-08-261-5/+0
|
* 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-241-0/+6
| | | | unblock SIGCANCEL which is needed by thread cancellation.
* On shared object unload, in __cxa_finalize, call and clear all installedkib2010-08-231-0/+3
| | | | | | | | | | | | | | | | | | | | | | 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
* In current implementation, thread cancellation is done in signal handler,davidxu2010-08-201-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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@
* Use umtx to implement process sharable semaphore, to make this work,davidxu2010-01-051-0/+17
| | | | | | | | | | | | | | | | | | | | | | now type sema_t is a structure which can be put in a shared memory area, and multiple processes can operate it concurrently. User can either use mmap(MAP_SHARED) + sem_init(pshared=1) or use sem_open() to initialize a shared semaphore. Named semaphore uses file system and is located in /tmp directory, and its file name is prefixed with 'SEMD', so now it is chroot or jail friendly. In simplist cases, both for named and un-named semaphore, userland code does not have to enter kernel to reduce/increase semaphore's count. The semaphore is designed to be crash-safe, it means even if an application is crashed in the middle of operating semaphore, the semaphore state is still safely recovered by later use, there is no waiter counter maintained by userland code. The main semaphore code is in libc and libthr only has some necessary stubs, this makes it possible that a non-threaded application can use semaphore without linking to thread library. Old semaphore implementation is kept libc to maintain binary compatibility. The kernel ksem API is no longer used in the new implemenation. Discussed on: threads@
* Make openat(2) a cancellation point.jilles2009-10-111-0/+1
| | | | | | | This is required by POSIX and matches open(2). Reviewed by: kib, jhb MFC after: 1 month
* Make pthread_cleanup_push() and pthread_cleanup_pop() as a pair of macros,davidxu2008-06-091-6/+9
| | | | | | | use stack space to keep cleanup information, this eliminates overhead of calling malloc() and free() in thread library. Discussed on: thread@
* - Reduce function call overhead for uncontended case.davidxu2008-05-291-10/+0
| | | | | - Remove unused flags MUTEX_FLAGS_* and their code. - Check validity of the timeout parameter in mutex_self_lock().
* Use UMTX_OP_WAIT_UINT_PRIVATE and UMTX_OP_WAKE_PRIVATE to savedavidxu2008-04-291-1/+1
| | | | time in kernel(avoid VM lookup).
* put THR_CRITICAL_LEAVE into do .. while statement.davidxu2008-04-031-2/+4
|
* add __hidden suffix to _umtx_op_err, this eliminates PLT.davidxu2008-04-031-1/+1
|
* Add pthread_setaffinity_np and pthread_getaffinity_np to libc namespace.davidxu2008-04-021-2/+0
|
* Remove unused functions.davidxu2008-04-021-2/+0
|
* Replace function _umtx_op with _umtx_op_err, the later function directlydavidxu2008-04-021-0/+2
| | | | | | returns errno, because errno can be mucked by user's signal handler and most of pthread api heavily depends on errno to be correct, this change should improve stability of the thread library.
* Replace userland rwlock with a pure kernel based rwlock, the newdavidxu2008-04-021-6/+1
| | | | | | implementation does not switch pointers when it resumes waiters. Asked by: jeff
* Rewrite rwlock to user atomic operations to change rwlock state, thisdavidxu2008-03-311-1/+5
| | | | | | | eliminates internal mutex lock contention when most rwlock operations are read. Orignal patch provided by: jeff
* Use cpuset defined in pthread_attr for newly created thread, for now,davidxu2008-03-051-0/+5
| | | | | | | we set scheduling parameters and cpu binding fully in userland, and because default scheduling policy is SCHED_RR (time-sharing), we set default sched_inherit to PTHREAD_SCHED_INHERIT, this saves a system call.
OpenPOWER on IntegriCloud