summaryrefslogtreecommitdiffstats
path: root/lib/libthr/thread/thr_mutex.c
Commit message (Collapse)AuthorAgeFilesLines
* Propagate errors from _thr_umutex_unlock2 through mutex_unlock_common.kib2015-02-251-3/+4
| | | | | | | | | | | | Errors from _thr_umutex_unlock2 should "never happen" in normal circumstances. If they do, however, return them to the application so it can fail early and loudly. Hiding the errors will only delay the inevitable failure, making it harder to find and diagnose. Submitted by: Eric van Gyzen <eric_van_gyzen@dell.com> Obtained from: Dell Inc. PR: 198914 MFC after: 1 week
* MFp4:davidxu2012-08-111-8/+8
| | | | | Further decreases unexpected context switches by defering mutex wakeup until internal sleep queue lock is released.
* Return EBUSY for PTHREAD_MUTEX_ADAPTIVE_NP too when the mutex could notdavidxu2012-05-271-0/+1
| | | | | | | be acquired. PR: 168317 MFC after: 3 days
* Return 0 instead of garbage value.davidxu2011-01-061-2/+1
| | | | Found by: clang static analyzer
* Always clear flag PMUTEX_FLAG_DEFERED when unlocking, as it is onlydavidxu2010-12-241-2/+2
| | | | significant for lock owner.
* MFp4:davidxu2010-12-221-82/+120
| | | | | | | | | | | | | | | - 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.
* Remove locking and unlock in pthread_mutex_destroy, becausedavidxu2010-10-271-25/+2
| | | | | it can not fix race condition in application code, as a result, the problem described in PR threads/151767 is avoided.
* Check invalid mutex in _mutex_cv_unlock.davidxu2010-09-291-0/+6
|
* In current code, statically initialized and destroyed object havedavidxu2010-09-281-119/+98
| | | | | | | | 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.
* Change atfork lock from mutex to rwlock, also make mutexes used by malloc()davidxu2010-09-011-5/+23
| | | | | | | | 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 two commands to _umtx_op system call to allow a simple mutex to bedavidxu2008-06-241-35/+33
| | | | | | | | | | | | | | locked and unlocked completely in userland. by locking and unlocking mutex in userland, it reduces the total time a mutex is locked by a thread, in some application code, a mutex only protects a small piece of code, the code's execution time is less than a simple system call, if a lock contention happens, however in current implemenation, the lock holder has to extend its locking time and enter kernel to unlock it, the change avoids this disadvantage, it first sets mutex to free state and then enters kernel and wake one waiter up. This improves performance dramatically in some sysbench mutex tests. Tested by: kris Sounds great: jeff
* - Reduce function call overhead for uncontended case.davidxu2008-05-291-205/+103
| | | | | - Remove unused flags MUTEX_FLAGS_* and their code. - Check validity of the timeout parameter in mutex_self_lock().
* Increase the default MUTEX_ADAPTIVE_SPINS to 2000, after furtherkris2008-04-261-1/+1
| | | | | | | | testing it turns out 200 was too short to give good adaptive performance. Reviewed by: jeff MFC after: 1 week
* Fixed mis-implementation of pthread_mutex_get{spin,yield}loops_np().ru2008-03-251-4/+7
| | | | Reviewed by: davidxu
* _pthread_mutex_isowned_np(): use a more reliable method; the current codedes2008-02-141-1/+1
| | | | | | will work in simple cases, but may fail in more complicated ones. Reviewed by: davidxu
* Remove unnecessary prototype.des2008-02-061-1/+0
|
* Per discussion on -threads, rename _islocked_np() to _isowned_np().des2008-02-061-3/+3
|
* After careful consideration (and a brief discussion with attilio@), changedes2008-02-041-1/+1
| | | | | | | | | the semantics of pthread_mutex_islocked_np() to return true if and only if the mutex is held by the current thread. Obviously, change the regression test to match. MFC after: 2 weeks
* Add pthread_mutex_islocked_np(), a cheap way to verify that a mutex isdes2008-02-031-0/+16
| | | | | | | locked. This is intended primarily to support the userland equivalent of the various *_ASSERT_LOCKED() macros we have in the kernel. MFC after: 2 weeks
* Add function prototypes.davidxu2007-12-171-1/+7
|
* 1. Add function pthread_mutex_setspinloops_np to turn a mutex's spindavidxu2007-12-141-29/+104
| | | | | | | | loop count. 2. Add function pthread_mutex_setyieldloops_np to turn a mutex's yield loop count. 3. Make environment variables PTHREAD_SPINLOOPS and PTHREAD_YIELDLOOPS to be only used for turnning PTHREAD_MUTEX_ADAPTIVE_NP mutex.
* Enclose all code for macro ENQUEUE_MUTEX in do while statement, anddavidxu2007-12-111-5/+7
| | | | | | add missing brackets. MFC: after 1 day
* Fix pointer dereferencing problems in _pthread_mutex_init_calloc_cb() thatjasone2007-11-281-7/+3
| | | | were obscured by pseudo-opaque pthreads API pointer casting.
* Add _pthread_mutex_init_calloc_cb() to libthr and libkse, so that malloc(3)jasone2007-11-271-6/+27
| | | | | (part of libc) can use pthreads mutexes without causing infinite recursion during initialization.
* Convert ceiling type to unsigned integer before comparing, fix compilerdavidxu2007-11-211-3/+3
| | | | warnings.
* Avoid doing adaptive spinning for priority protected mutex, currentdavidxu2007-10-311-2/+5
| | | | implementation always does lock in kernel.
* Don't do adaptive spinning if it is running on UP kernel.davidxu2007-10-311-3/+5
|
* Restore revision 1.55, the kris's adaptive mutex type.davidxu2007-10-311-14/+36
|
* Adaptive mutexes should have the same deadlock detection properties thatkris2007-10-301-0/+1
| | | | | | default (errorcheck) mutexes do. Noticed by: davidxu
* Add my recent work of adaptive spin mutex code. Use two environments variabledavidxu2007-10-301-45/+37
| | | | | | | | | | | | | | | | | | | | | | | | | to tune pthread mutex performance: 1. LIBPTHREAD_SPINLOOPS If a pthread mutex is being locked by another thread, this environment variable sets total number of spin loops before the current thread sleeps in kernel, this saves a syscall overhead if the mutex will be unlocked very soon (well written application code). 2. LIBPTHREAD_YIELDLOOPS If a pthread mutex is being locked by other threads, this environment variable sets total number of sched_yield() loops before the currrent thread sleeps in kernel. if a pthread mutex is locked, the current thread gives up cpu, but will not sleep in kernel, this means, current thread does not set contention bit in mutex, but let lock owner to run again if the owner is on kernel's run queue, and when lock owner unlocks the mutex, it does not need to enter kernel and do lots of work to resume mutex waiters, in some cases, this saves lots of syscall overheads for mutex owner. In my practice, sometimes LIBPTHREAD_YIELDLOOPS can massively improve performance than LIBPTHREAD_SPINLOOPS, this depends on application. These two environments are global to all pthread mutex, there is no interface to set them for each pthread mutex, the default values are zero, this means spinning is turned off by default.
* Add a new "non-portable" mutex type, PTHREAD_MUTEX_ADAPTIVE_NP. Thiskris2007-10-291-0/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | is also implemented in glibc and is used by a number of existing applications (mysql, firefox, etc). This mutex type is a default mutex with the additional property that it spins briefly when attempting to acquire a contested lock, doing trylock operations in userland before entering the kernel to block if eventually unsuccessful. The expectation is that applications requesting this mutex type know that the mutex is likely to be only held for very brief periods, so it is faster to spin in userland and probably succeed in acquiring the mutex, than to enter the kernel and sleep, only to be woken up almost immediately. This can help significantly in certain cases when pthread mutexes are heavily contended and held for brief durations (such as mysql). Spin up to 200 times before entering the kernel, which represents only a few us on modern CPUs. No performance degradation was observed with this value and it is sufficient to avoid a large performance drop in mysql performance in the heavily contended pthread mutex case. The libkse implementation is a NOP. Reviewed by: jeff MFC after: 3 days
* backout experimental adaptive spinning mutex for product use.davidxu2007-05-091-1/+0
|
* Insert mutex at tail if it has highest ceiling.davidxu2007-01-051-1/+1
|
* Oops, don't corrupt the list.davidxu2007-01-051-1/+1
|
* Check if the PP mutex is recursive, if we have already locked it, place thedavidxu2007-01-051-9/+28
| | | | mutex in right order sorted by priority ceiling.
* Check environment variable PTHREAD_ADAPTIVE_SPIN, if it is set, usedavidxu2006-12-201-0/+1
| | | | it as a default spin cycle count.
* Create inline function _thr_umutex_trylock2 to only try one atomicdavidxu2006-12-141-3/+3
| | | | | operation, if it is failed, we call syscall directly, this saves one atomic operation per lock contention.
* Move code calculating new inherited priority into single function.davidxu2006-11-111-30/+21
|
* Use return value of _thr_umutex_lock instead of using zero.davidxu2006-09-081-2/+1
|
* Use umutex APIs to implement pthread_mutex, member pp_mutexq is addeddavidxu2006-08-281-55/+100
| | | | | | into pthread structure to keep track of locked PTHREAD_PRIO_PROTECT mutex, no real mutex code is changed, the mutex locking and unlocking code should has same performance as before.
* Axe unused member field.davidxu2006-08-081-2/+0
|
* Unexpand two TAILQ_FOREACH_SAFE cases.delphij2006-07-171-2/+1
| | | | Ok'ed by: davidxu
* Remove unused member field m_queue.davidxu2006-06-021-5/+1
|
* Do not check validity of timeout if a mutex can be acquired immediately.davidxu2006-04-081-67/+89
| | | | | Completly drop recursive mutex in pthread_cond_wait and restore recursive after resumption. Reorganize code to make gcc to generate better code.
* WARNS level 4 cleanup.davidxu2006-04-041-11/+22
|
* Remove priority mutex code because it does not work correctly,davidxu2006-03-271-1118/+122
| | | | | | | | | to make it work, turnstile like mechanism to support priority propagating and other realtime scheduling options in kernel should be available to userland mutex, for the moment, I just want to make libthr be simple and efficient thread library. Discussed with: deischen, julian
* Reimplement mutex_init to get rid of compile warning.davidxu2006-02-281-88/+39
|
* Eliminate unused code.davidxu2006-01-161-7/+1
|
* Enable mutex inheritance code in mutex_fork, I forgot to turn on it.davidxu2006-01-141-1/+11
| | | | while here, add some comments about process shared mutex.
* Let _mutex_cv_lock call internal functiona mutex_lock_common.davidxu2005-12-211-1/+2
|
OpenPOWER on IntegriCloud