summaryrefslogtreecommitdiff
path: root/locks/unix/thread_mutex.c
Commit message (Collapse)AuthorAgeFilesLines
* Merge r1891204 from trunk:Joe Orton2021-07-051-0/+9
| | | | | | | | | | | | * locks/unix/thread_mutex.c, include/arch/unix/apr_arch_thread_mutex.h: Completely drop the code required imitate the mutex via a condition variable if HAVE_PTHREAD_MUTEX_TIMEDLOCK is defined. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1891269 13f79535-47bb-0310-9956-ffa450edef68
* Merge r1794266 from trunk:Yann Ylavic2019-03-211-26/+18
| | | | | | | | locks: thread: timedlock: better handling of spurious wakeups that may be inherent to some native/OS condvar implementation. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1855959 13f79535-47bb-0310-9956-ffa450edef68
* Make timedlocks a configuration option.Nick Kew2017-04-191-0/+2
| | | | | | | | | After first Mac then Solaris biting us, timedlocks look high-risk, so a config option and a corresponding rlease note offer a workaround to any users who get bitten. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1791932 13f79535-47bb-0310-9956-ffa450edef68
* Merge r1790632 from trunk:Yann Ylavic2017-04-071-17/+3
| | | | | | | | | | apr_{thread,proc,global}_timedlock() with negative timeout is now equivalent to apr_{thread,proc,global}_trylock(), i.e. immediate attempt to acquire the lock (but returning APR_TIMEUP if busy). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1790633 13f79535-47bb-0310-9956-ffa450edef68
* Merge r1790521, r1790523 from trunk:Yann Ylavic2017-04-071-1/+1
| | | | | | | | | | | | | | locks: follow up to r1790488. Make it clear in the type that it's a relative/interval time. locks: follow up to r1790488 and r1790521: likewise for the apr_proc_mutex_unix_lock_methods_t's timedacquired method. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1790527 13f79535-47bb-0310-9956-ffa450edef68
* Merge r1790488 from trunk:Yann Ylavic2017-04-071-24/+35
| | | | | | | | | | | | | | | locks: follow up to r1667900. Axe the 'absolute' argument of apr_{thread,proc,global}_mutex_timedlock() which was confusing, hence 'timeout' is always relative now. It still makes sense (to me) to handle a negative timeout as INFINITE, a nul one as IMMEDIATE, and a positive one as an upper bound timeout (like most if not all of the underlying system calls...). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1790490 13f79535-47bb-0310-9956-ffa450edef68
* Merge r1790296, r1790302, r1790303, r1790304, r1790330, r1790331, r1790436, ↵Yann Ylavic2017-04-061-4/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | r1790439, r1790444, r1790446 from trunk: Follow up to r1667900: semtimedop() should be passed a relative timeout rather then absolute. semtimedop() takes a delta time, so accept what is given as the "time remaining" rr1790301 Use our "portable" versions Make clear this is a delta timeout locks: when pthread_mutex_timedlock() isn't available, fall back to an implementation based on pthread_cond_timedwait() when possible. Avoid a compiler warning by using system's errno. locks: follow up to r1790330. When no native timedlock is available, fall back to a common/generic spin sleep proc_mutex_spinsleep_timedacquire() based on the configured APR_USE_*_SERIALIZE trylock. Otherwise, choose the best timedlock mechanism in the following order: 1. PTHREAD if HAVE_PTHREAD_MUTEX_ROBUST && (HAVE_PTHREAD_MUTEX_TIMEDLOCK || HAVE_PTHREAD_CONDATTR_SETPSHARED) 2. SYSV if HAVE_SEMTIMEDOP 3. POSIX if HAVE_SEM_TIMEDWAIT 4. The one of APR_USE_*_SERIALIZE, hence possibly non-robust and/or spinning with the same robustness as the underlying apr_proc_mutex_trylock() call. apr_proc_mutex_timedlock() won't return ENOTIMPL anymore. locks: follow up to r1790330 and r1790436. unix/misc.c is not needed anymore since we use apr_proc_mutex_trylock() directly. locks: follow up to r1790330. No functional change, more helpers/macros to help identify struct proc_pthread_mutex_t members. locks: follow up to r1790330. Don't try to access proc_pthread_mutex_t's condvar if the mutex was _put[_ex]() and not _create()d, this is a real pthread_mutex_t. Submitted by: ylavic, jim, jim, jim, ylavic, ylavic, ylavic, ylavic, ylavic, ylavic git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1790474 13f79535-47bb-0310-9956-ffa450edef68
* Add in our own pthread_mutex_timedlock impl for those OSs, likeJim Jagielski2017-04-041-63/+4
| | | | | | osx/macos that don't have it. Be a bit more generous in the test git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1790105 13f79535-47bb-0310-9956-ffa450edef68
* Merge r930508, r1667900, r1667901, r1667903, r1667962, r1669077, r1671292, ↵Yann Ylavic2016-03-051-2/+207
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | r1732582 from trunk: OS/2: Add an implementation of condition variables, derived from the Win32 implementation. locks: introduce apr_{thread,proc,global}_mutex_timedlock(). For proc mutexes, the new mechanism APR_LOCK_DEFAULT_TIMED usable at creation time allows for the best mechanism to be elected (unixes: 1 to 3, or specific: 4 to 7): 1. PROC_PTHREAD if pthread_mutex_timedlock() and pthread_mutex_set_robust_np() are both available, 2. SYSV if semtimedop() is availale, 3. POSIXSEM if sem_timedwait() is available, 4. BeOS' acquire_sem_etc() if available, 5. NetWare falls back to apr_thread_mutex_timedlock() as for others functions, 6. OS2's DosRequestMutexSem(), 7. Windows' WaitForSingleObject(). Otherwise (like when fcntl and flock only are availble, if that's ever possible), APR_ENOTIMPL is returned. For thread mutexes, the new flag APR_THREAD_MUTEX_TIMED, usable at create() time still, allows to switch to an implementation using a condition variable and apr_thread_cond_timedwait() when if no native mechanism is available (eg. NetWare, pthreads but without pthread_mutex_timedlock() available). On windows, this initializes a WaitForSingleObject()able handle (Mutex) instead of the fastest (but not timeout-able) CRITICAL_SECTION used by default. All apr_{thread,proc,global}_mutex_timedlock() functions can take a relative or absolute time, thanks to the last (boolean) argument. Test suite updated accordingly. Follow up to r1667900: revert spurious change on test/abts_tests.h. Follow up to r1667900: fix comments. Follow up to r1667900: handle negative (infinite) timeout in mutex/cond timedlock/timedwait. locks: follow up to r1667900. In apr_global_mutex_timedlock(), we can avoid converting from relative to absolute time if thread locking is not needed. make internal function static to avoid a warning Follow up to r1667900: Avoid a circular reference (PR 59068). Submitted by: bjh, ylavic, ylavic, ylavic, ylavic, ylavic, trawick, ylavic Reviewed/backported by: ylavic git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1733684 13f79535-47bb-0310-9956-ffa450edef68
* Simplify handling of z/OS pthread API nuances. Beyond theJeff Trawick2007-11-191-5/+5
| | | | | | | | | | | | | simplification, it fixes a compile error in the call to pthread_yield() on z/OS. Submitted by: David Jones I modified it slightly to use AC_DEFINE() as suggested by jorton. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@596402 13f79535-47bb-0310-9956-ffa450edef68
* Fix the typo.Joe Orton2006-08-031-1/+1
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@428317 13f79535-47bb-0310-9956-ffa450edef68
* Update license header.Joe Orton2006-08-031-6/+6
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@428313 13f79535-47bb-0310-9956-ffa450edef68
* Update copyright year to 2005 and standardize on current copyright owner line.Justin Erenkrantz2005-02-041-1/+2
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@151412 13f79535-47bb-0310-9956-ffa450edef68
* Drop racy/broken Unix nested mutex implementation; use SUSv3-styleJoe Orton2004-06-041-109/+36
| | | | | | | | | | | | | | | | | | | recursive mutex support if available: * build/apr_threads.m4 (APR_CHECK_PTHREAD_RECURSIVE_MUTEX): New macro. * configure.in: Use it. * include/arch/unix/apr_arch_thread_mutex.h (struct apr_thread_mutex_t): Drop nested mutex tracking fields. * locks/unix/thread_mutex.c (apr_thread_mutex_create): Return ENOTIMPL if lacking recursive mutex support, else create a recursive mutex. (apr_thread_mutex_lock, apr_thread_mutex_unlock, apr_thread_mutex_trylock): Remove nested mutex tracking. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@65157 13f79535-47bb-0310-9956-ffa450edef68
* Relicense APR under Apache License, Version 2.0Justin Erenkrantz2004-02-131-49/+10
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@64904 13f79535-47bb-0310-9956-ffa450edef68
* thread id is not always a scalarJeff Trawick2003-11-161-1/+3
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@64749 13f79535-47bb-0310-9956-ffa450edef68
* axing deprecated apr_atomic_foo functionsJeff Trawick2003-11-161-5/+5
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@64747 13f79535-47bb-0310-9956-ffa450edef68
* Thanks to Jeff for pointing out I didn't point to the atomics.William A. Rowe Jr2003-08-081-3/+3
| | | | | | | Fixes build breakage. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@64581 13f79535-47bb-0310-9956-ffa450edef68
* Revamp apr_thread_mutex to be as thread safe, and occasionallyWilliam A. Rowe Jr2003-08-071-23/+57
| | | | | | | | | | | | | as reentrant as possible. Switched to atomics to preserve the incr/decr integrity. Although we previously reset the thread_id to zero, it's been pointed out on list that this is less than desireable. However, negative one isn't necessarily a good choice because several platforms have unsigned thread_t's. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@64579 13f79535-47bb-0310-9956-ffa450edef68
* Error handling fix (unrelated to previous changes): don't callJoe Orton2003-06-081-1/+0
| | | | | | | pthread_mutex_destroy(NULL) if pthread_mutex_init() fails. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@64534 13f79535-47bb-0310-9956-ffa450edef68
* Code style cleanups: remove unnecessary casts to and from void *;Joe Orton2003-06-081-8/+3
| | | | | | | don't check for allocation failure. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@64533 13f79535-47bb-0310-9956-ffa450edef68
* POSIX says that passing a mutexattr object with default attributes toJoe Orton2003-06-081-18/+1
| | | | | | | | | | | pthread_mutex_init() is equivalent to passing NULL: simplify apr_thread_mutex_create() to do the latter. Fixes build on BSD/OS 4.0, which prototypes but does not implement pthread_mutexattr_{init,destroy}, fooling the autoconf checks. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@64532 13f79535-47bb-0310-9956-ffa450edef68
* Namespace protection for include/arch/ header filesThom May2003-01-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | aix/dso.h -> -> aix/apr_arch_dso.h beos/dso.h -> beos/apr_arch_dso.h beos/proc_mutex.h -> beos/apr_arch_proc_mutex.h beos/thread_cond.h -> beos/apr_arch_thread_cond.h beos/thread_mutex.h -> beos/apr_arch_thread_mutex.h beos/threadproc.h -> beos/apr_arch_threadproc.h beos/thread_rwlock.h -> beos/apr_arch_thread_rwlock.h netware/dso.h -> -> netware/apr_arch_dso.h netware/fileio.h -> -> netware/apr_arch_fileio.h netware/global_mutex.h -> netware/apr_arch_global_mutex.h netware/internal_time.h -> netware/apr_arch_internal_time.h netware/networkio.h -> netware/apr_arch_networkio.h netware/pre_nw.h -> netware/apr_arch_pre_nw.h netware/proc_mutex.h -> netware/apr_arch_proc_mutex.h netware/thread_cond.h -> netware/apr_arch_thread_cond.h netware/thread_mutex.h -> netware/apr_arch_thread_mutex.h netware/threadproc.h -> netware/apr_arch_threadproc.h netware/thread_rwlock.h -> netware/apr_arch_thread_rwlock.h os2/dso.h -> os2/apr_arch_dso.h os2/fileio.h -> os2/apr_arch_fileio.h os2/networkio.h -> os2/apr_arch_networkio.h os2/os2calls.h -> os2/apr_arch_os2calls.h os2/proc_mutex.h -> os2/apr_arch_proc_mutex.h os2/thread_cond.h -> os2/apr_arch_thread_cond.h os2/thread_mutex.h -> os2/apr_arch_thread_mutex.h os2/threadproc.h -> os2/apr_arch_threadproc.h os2/thread_rwlock.h -> os2/apr_arch_thread_rwlock.h os390/dso.h -> os390/apr_arch_dso.h unix/dso.h -> unix/apr_arch_dso.h unix/fileio.h -> unix/apr_arch_fileio.h unix/global_mutex.h -> unix/apr_arch_global_mutex.h unix/inherit.h -> unix/apr_arch_inherit.h unix/internal_time.h -> unix/apr_arch_internal_time.h unix/misc.h -> unix/apr_arch_misc.h unix/networkio.h -> unix/apr_arch_networkio.h unix/proc_mutex.h -> unix/apr_arch_proc_mutex.h unix/shm.h -> unix/apr_arch_shm.h unix/thread_cond.h -> unix/apr_arch_thread_cond.h unix/thread_mutex.h -> unix/apr_arch_thread_mutex.h unix/threadproc.h -> unix/apr_arch_threadproc.h unix/thread_rwlock.h -> unix/apr_arch_thread_rwlock.h win32/atime.h -> win32/apr_arch_atime.h win32/dso.h -> win32/apr_arch_dso.h win32/fileio.h -> win32/apr_arch_fileio.h win32/inherit.h -> win32/apr_arch_inherit.h win32/misc.h -> win32/apr_arch_misc.h win32/networkio.h -> win32/apr_arch_networkio.h win32/proc_mutex.h -> win32/apr_arch_proc_mutex.h win32/thread_cond.h -> win32/apr_arch_thread_cond.h win32/thread_mutex.h -> win32/apr_arch_thread_mutex.h win32/threadproc.h -> win32/apr_arch_threadproc.h win32/thread_rwlock.h -> win32/apr_arch_thread_rwlock.h win32/utf8.h -> win32/apr_arch_utf8.h git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@64271 13f79535-47bb-0310-9956-ffa450edef68
* Update copyright notices to 2003.Thom May2003-01-011-1/+1
| | | | | | | No functional changes git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@64251 13f79535-47bb-0310-9956-ffa450edef68
* Collapse this down to the infinately more readable apr_pool_cleanup_run().Aaron Bannert2002-07-301-6/+1
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@63743 13f79535-47bb-0310-9956-ffa450edef68
* When we are destroying a mutex we don't know if it is locked or not,Aaron Bannert2002-07-301-1/+0
| | | | | | | | | | so we shouldn't try to unlock the mutex. Submitted by: Philip Martin <philip@codematters.co.uk> Reviewed by: Aaron Bannert git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@63742 13f79535-47bb-0310-9956-ffa450edef68
* Split APR_THREAD_MUTEX_DEFAULT with a new APR_THREAD_MUTEX_UNNESTEDWilliam A. Rowe Jr2002-05-291-0/+4
| | | | | | | | | | | | | | | | which guarentees unnested lock behavior, keep APR_THREAD_MUTEX_DEFAULT on Win32, Netware and OS2 as nested locks, leave Unix and BeOS with unnested locks by default. Needs an implementation on Netware and OS2 for UNNESTED locks, for now return APR_ENOTIMPL. Required for absolute locks in series for Win32 on the same thread, since CriticalSection objects are blindingly fast without contention, but they will always nest on the same thread. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@63440 13f79535-47bb-0310-9956-ffa450edef68
* Optimization: rearranged the mutex lock/unlock code toBrian Pane2002-04-281-10/+8
| | | | | | | | eliminate a conditional branch on platforms where PTHREAD_SETS_ERRNO is not defined (at present, this means everything except OS/390) git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@63307 13f79535-47bb-0310-9956-ffa450edef68
* Update our copyright for this year.Roy T. Fielding2002-03-131-1/+1
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@63117 13f79535-47bb-0310-9956-ffa450edef68
* These are redundant redundancies. We already wrap the whole fileJim Jagielski2002-03-061-12/+0
| | | | | | | | | | | | with APR_HAS_THREADS. PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@63089 13f79535-47bb-0310-9956-ffa450edef68
* Add Brian Pane's 10% performance improvement logic to trylock() also.Aaron Bannert2002-01-111-13/+21
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@62756 13f79535-47bb-0310-9956-ffa450edef68
* Improve performance about 10% by optimizing the code pathWilliam A. Rowe Jr2002-01-111-24/+38
| | | | | | | Submitted by: Brian Pane <brian.pane@cnet.com> git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@62746 13f79535-47bb-0310-9956-ffa450edef68
* Stop using the name of a standard system function for a variable.Roy T. Fielding2001-10-221-52/+40
| | | | | | | Remove minor optimizations that were causing compile warnings. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@62452 13f79535-47bb-0310-9956-ffa450edef68
* Added a new parameter to apr_thread_mutex_init(). Mutexes are now byAaron Bannert2001-10-171-18/+32
| | | | | | | | | | | | | | | | default not nested, but an init flag can enable them. I added a new test to testlockperf to show how much faster non-nested mutexes are. I also updated calls to apr_thread_mutex_init() wherever I could find them. This patch only implements this for Unix (nested locks already existed on Unix, so this patch just optionally enables/disables them). I did my best to change the function declaration on other platforms, but someone will have to double check me. Those other platforms will also have to either enable nested locks (sometimes available in their thread library) or just do what Unix does. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@62435 13f79535-47bb-0310-9956-ffa450edef68
* Add pool accessors to the apr_thread_mutex_t datatype.Ryan Bloom2001-09-261-0/+2
| | | | | | | Submitted by: Aaron Bannert <aaron@clove.org> git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@62377 13f79535-47bb-0310-9956-ffa450edef68
* Cleanup some of the thread lock work. Remove some unnecessaryRyan Bloom2001-09-051-0/+2
| | | | | | | | header files, and add tell apr_want.h that we want mem functions. Submitted by: Aaron Bannert <aaron@clove.org> git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@62291 13f79535-47bb-0310-9956-ffa450edef68
* Add the new thread_lock API to APR. This is the first step to breakingRyan Bloom2001-09-041-0/+224
the locking API into separate APIs. Submitted by: Aaron Bannert <aaron@clove.org> git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@62286 13f79535-47bb-0310-9956-ffa450edef68