summaryrefslogtreecommitdiffstats
path: root/lib/libthr/thread/thr_mutex.c
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* Remove unused _get_curthread() call.davidxu2005-12-121-2/+0
|
* - Prefix MUTEX_TYPE_MAX with PTHREAD_ to avoid namespace pollution.stefanf2005-08-191-1/+1
| | | | | | - Remove the macros MUTEX_TYPE_FAST and MUTEX_TYPE_COUNTING_FAST. OK'ed by: deischen
* Import my recent 1:1 threading working. some features improved includes:davidxu2005-04-021-589/+1385
| | | | | | | | | | | | | | | | 1. fast simple type mutex. 2. __thread tls works. 3. asynchronous cancellation works ( using signal ). 4. thread synchronization is fully based on umtx, mainly, condition variable and other synchronization objects were rewritten by using umtx directly. those objects can be shared between processes via shared memory, it has to change ABI which does not happen yet. 5. default stack size is increased to 1M on 32 bits platform, 2M for 64 bits platform. As the result, some mysql super-smack benchmarks show performance is improved massivly. Okayed by: jeff, mtm, rwatson, scottl
* Remove vestiges of libthr's signal mangling past. This fixes that lastmtm2004-09-221-14/+1
| | | | known problem with mysql on libthr: not being able to kill mysqld.
* The SUSv3 function say that the affected functions MAY FAIL, if themtm2004-09-221-27/+6
| | | | | | | | | | | | specified mutex is invalid. In spec parlance 'MAY FAIL' means it's up to the implementor. So, remove the check for NULL pointers for two reasons: 1. A mutex may be invalid without necessarily being NULL. 2. If the pointer to the mutex is NULL core-dumping in the vicinity of the problem is much much much better than failing in some other part of the code (especially when the application doesn't check the return value of the function that you oh so helpfully set to EINVAL).
* o Assertions to catch that stuff that shouldn't happen is not happening.mtm2004-07-301-0/+2
| | | | | | | | | | o In the rwlock code: move a duplicated check inside an if..else to after the if...else clause. o When initializing a static rwlock move the initialization check inside the lock. o In thr_setschedparam.c: When breaking out of the trylock...retry if busy loop make sure to reset the mtx pointer to null if the mutex is nolonger in a queue.
* Change the thread ID (thr_id_t) used for 1:1 threading from being amarcel2004-07-021-4/+4
| | | | | | | | | | | | | | | | | | | | pointer to the corresponding struct thread to the thread ID (lwpid_t) assigned to that thread. The primary reason for this change is that libthr now internally uses the same ID as the debugger and the kernel when referencing to a kernel thread. This allows us to implement the support for debugging without additional translations and/or mappings. To preserve the ABI, the 1:1 threading syscalls, including the umtx locking API have not been changed to work on a lwpid_t. Instead the 1:1 threading syscalls operate on long and the umtx locking API has not been changed except for the contested bit. Previously this was the least significant bit. Now it's the most significant bit. Since the contested bit should not be tested by userland, this change is not expected to be visible. Just to be sure, UMTX_CONTESTED has been removed from <sys/umtx.h>. Reviewed by: mtm@ ABI preservation tested on: i386, ia64
* Make libthr async-signal-safe without costly signal masking. The guidlines Imtm2004-05-201-42/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | followed are: Only 3 functions (pthread_cancel, pthread_setcancelstate, pthread_setcanceltype) are required to be async-signal-safe by POSIX. None of the rest of the pthread api is required to be async-signal-safe. This means that only the three mentioned functions are safe to use from inside signal handlers. However, there are certain system/libc calls that are cancellation points that a caller may call from within a signal handler, and since they are cancellation points calls have to be made into libthr to test for cancellation and exit the thread if necessary. So, the cancellation test and thread exit code paths must be async-signal-safe as well. A summary of the changes follows: o Almost all of the code paths that masked signals, as well as locking the pthread structure now lock only the pthread structure. o Signals are masked (and left that way) as soon as a thread enters pthread_exit(). o The active and dead threads locks now explicitly require that signals are masked. o Access to the isdead field of the pthread structure is protected by both the active and dead list locks for writing. Either one is sufficient for reading. o The thread state and type fields have been combined into one three-state switch to make it easier to read without requiring a lock. It doesn't need a lock for writing (and therefore for reading either) because only the current thread can write to it and it is an integer value. o The thread state field of the pthread structure has been eliminated. It was an unnecessary field that mostly duplicated the flags field, but required additional locking that would make a lot more code paths require signal masking. Any truly unique values (such as PS_DEAD) have been reborn as separate members of the pthread structure. o Since the mutex and condvar pthread functions are not async-signal-safe there is no need to muck about with the wait queues when handling a signal ... o ... which also removes the need for wrapping signal handlers and sigaction(2). o The condvar and mutex async-cancellation code had to be revised as a result of some of these changes, which resulted in semi-unrelated changes which would have been difficult to work on as a separate commit, so they are included as well. The only part of the changes I am worried about is related to locking for the pthread joining fields. But, I will take a closer look at them once this mega-patch is committed.
* q§mtm2004-05-201-7/+5
|
* The thread suspend function now returns ETIMEDOUT, not EAGAIN.mtm2004-03-291-1/+1
|
* Stop using signals for synchronizing threads. The performance penaltymtm2004-03-271-1/+1
| | | | was too much.
* o The mutex locking functions aren't normally cancellation points. But,mtm2004-03-261-3/+12
| | | | | | | we still have to DTRT when an asynchronously cancellable thread is cancelled while waiting for a mutex. o While dequeueing a waiting mutex don't skip a thread if it has a cancel pending. Only skip it if it is also async cancellable.
* o Refactor and, among other things, get rid of insane nesting levels.mtm2004-02-181-810/+300
| | | | | | | o Fix mutex priority protocols. Keep separate counts of priority inheritance and protection mutexes to make things easier. This will not have much affect since this is only the userland side, and the rest involves kernel scheduling.
* Refactor _pthread_mutex_initmtm2004-01-191-125/+64
| | | | | | | | | | | | o Simplify the logic by removing a lot of unnecesary nesting o Reduce the amount of local variables o Zero-out the allocated structure and get rid of all the unnecessary setting to 0 and NULL; Refactor _pthread_mutex_destroy o Simplify the logic by removing a lot of unnecesary nesting o No need to check pointer that the mutex attributes points to. Checking passed in pointer is enough.
* o Implement pthread_mutex_timedlock(), which does not block indefinitely onmtm2003-12-301-0/+32
| | | | | a mutex locked by another thread. o document it: pthread_mutex_timedlock(3)
OpenPOWER on IntegriCloud