summaryrefslogtreecommitdiffstats
path: root/lib/libthr/thread/thr_umtx.c
Commit message (Collapse)AuthorAgeFilesLines
* Use clockid parameter instead of hard-coded CLOCK_REALTIME.davidxu2012-03-191-1/+1
| | | | Reported by: pjd
* Some software think a mutex can be destroyed after it owned it, fordavidxu2012-03-181-7/+0
| | | | | | | | | | | example, it uses a serialization point like following: pthread_mutex_lock(&mutex); pthread_mutex_unlock(&mutex); pthread_mutex_destroy(&muetx); They think a previous lock holder should have already left the mutex and is no longer referencing it, so they destroy it. To be maximum compatible with such code, we use IA64 version to unlock the mutex in kernel, remove the two steps unlocking code.
* Follow changes made in revision 232144, pass absolute timeout to kernel,davidxu2012-02-271-4/+31
| | | | this eliminates a clock_gettime() syscall.
* In revision 231989, we pass a 16-bit clock ID into kernel, howeverdavidxu2012-02-251-17/+32
| | | | | | | | | | | | according to POSIX document, the clock ID may be dynamically allocated, it unlikely will be in 64K forever. To make it future compatible, we pack all timeout information into a new structure called _umtx_time, and use fourth argument as a size indication, a zero means it is old code using timespec as timeout value, but the new structure also includes flags and a clock ID, so the size argument is different than before, and it is non-zero. With this change, it is possible that a thread can sleep on any supported clock, though current kernel code does not have such a POSIX clock driver system.
* Use unused fourth argument of umtx_op to pass flags to kernel for operationdavidxu2012-02-221-13/+3
| | | | | | UMTX_OP_WAIT. Upper 16bits is enough to hold a clock id, and lower 16bits is used to pass flags. The change saves a clock_gettime() syscall from libthr.
* Check both seconds and nanoseconds are zero, only checking nanosecondsdavidxu2012-02-191-1/+1
| | | | is zero may trigger timeout too early. It seems a copy&paste bug.
* Pass CVWAIT flags to kernel, this should handledavidxu2011-11-171-3/+2
| | | | | | | | | timeout correctly for pthread_cond_timedwait when it uses kernel-based condition variable. PR: 162403 Submitted by: jilles MFC after: 3 days
* MFp4:davidxu2010-12-221-0/+53
| | | | | | | | | | | | | | | - 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.
* Change atfork lock from mutex to rwlock, also make mutexes used by malloc()davidxu2010-09-011-0/+7
| | | | | | | | 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-0/+39
| | | | | | | | | | | | | | | | | | | | | | | 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.
* Work-around a race condition on ia64 while unlocking a contested lock.marcel2009-12-141-0/+3
| | | | | | | | The race condition is believed to be in UMTX_OP_MUTEX_WAKE. On ia64, we simply go to the kernel to unlock. The big question is why this is only a race condition on ia64... MFC after: 3 days
* Add two commands to _umtx_op system call to allow a simple mutex to bedavidxu2008-06-241-10/+60
| | | | | | | | | | | | | | 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
* Use UMTX_OP_WAIT_UINT_PRIVATE and UMTX_OP_WAKE_PRIVATE to savedavidxu2008-04-291-5/+6
| | | | time in kernel(avoid VM lookup).
* Replace function _umtx_op with _umtx_op_err, the later function directlydavidxu2008-04-021-48/+28
| | | | | | 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-0/+24
| | | | | | implementation does not switch pointers when it resumes waiters. Asked by: jeff
* Remove umtx_t definition, use type long directly, add wrapper functiondavidxu2007-11-211-2/+14
| | | | | _thr_umtx_wait_uint() for umtx operation UMTX_OP_WAIT_UINT, use the function in semaphore operations, this fixed compiler warnings.
* backout experimental adaptive spinning mutex for product use.davidxu2007-05-091-1/+0
|
* Check environment variable PTHREAD_ADAPTIVE_SPIN, if it is set, usedavidxu2006-12-201-0/+1
| | | | it as a default spin cycle count.
* Correctly check failed syscall.davidxu2006-12-121-10/+10
|
* Move checking for c_has_waiters into low level _thr_ucond_signal anddavidxu2006-12-121-0/+4
| | | | | | | _thr_ucond_broadcast, clear condition variable pointer in cancellation info after returing from _thr_ucond_wait, since kernel has already dropped the internal lock, so we don't need to unlock it in cancellation handler again.
* Add _thr_ucond_init().davidxu2006-12-051-0/+6
|
* Fix typo, I was using a wrong header file, and the typo is not detecteddavidxu2006-12-041-1/+1
| | | | by compiler.
* Use kernel provided userspace condition variable to implement pthreaddavidxu2006-12-041-0/+33
| | | | condition variable.
* o Make _thr_umutex_init a function.davidxu2006-10-131-6/+14
| | | | | | o Eliminate unused parameter for some functions. o Convert type of first parameter to void * for _thr_umtx_wait and _thr_umtx_wake.
* Replace internal usage of struct umtx with umutex which can supportsdavidxu2006-09-061-31/+0
| | | | real-time if we want, no functionality is changed.
* Add umutex APIs.davidxu2006-08-281-0/+46
|
* WARNS level 4 cleanup.davidxu2006-04-041-7/+10
|
* Import my recent 1:1 threading working. some features improved includes:davidxu2005-04-021-0/+80
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
OpenPOWER on IntegriCloud