summaryrefslogtreecommitdiff
path: root/lib/libthr/thread/thr_rwlock.c
Commit message (Collapse)AuthorAgeFilesLines
* Avoid conflicts with libc symbols in libthr jump table.Konstantin Belousov2019-07-311-15/+22
| | | | | | | | | | | | | | | | | | | In some corner cases of static linking and unexpected libraries order on the linker command line, libc symbol might preempt the same libthr symbol, in which case libthr jump table points back to libc causing either infinite recursion or loop. Handle all of such symbols by using private libthr names for them, ensuring that the right pointers are installed into the table. In collaboration with: arichardson PR: 239475 Tested by: pho MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D21088 Notes: svn path=/head/; revision=350481
* POSIX compliance improvements in the pthread(3) functions.Pedro F. Giffuni2018-08-181-4/+4
| | | | | | | | | | | | | | | | This basically adds makes use of the C99 restrict keyword, and also adds some 'const's to four threading functions: pthread_mutexattr_gettype(), pthread_mutexattr_getprioceiling(), pthread_mutexattr_getprotocol(), and pthread_mutex_getprioceiling. The changes are in accordance to POSIX/SUSv4-2018. Hinted by: DragonFlyBSD Relnotes: yes MFC after: 1 month Differential Revision: D16722 Notes: svn path=/head/; revision=337992
* lib: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-261-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using mis-identified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326219
* libthr: change CHECK_AND_INIT_RWLOCK to an inline functionEric van Gyzen2017-05-201-24/+47
| | | | | | | | | | | | | This was prompted by a compiler warning about 'ret' shadowing a local variable in the callers of the macro. Reviewed by: kib MFC after: 3 days Sponsored by: Dell EMC Differential Revision: https://reviews.freebsd.org/D10832 Notes: svn path=/head/; revision=318581
* Use __FBSDID() for .c files from lib/libthr/thread.Konstantin Belousov2016-04-081-2/+3
| | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297706
* Assert that the lock objects put into the off-page, fit into the page.Konstantin Belousov2016-04-081-0/+3
| | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297701
* Implement process-shared locks support for libthr.so.3, withoutKonstantin Belousov2016-02-281-18/+42
| | | | | | | | | | | | | | | breaking the ABI. Special value is stored in the lock pointer to indicate shared lock, and offline page in the shared memory is allocated to store the actual lock. Reviewed by: vangyzen (previous version) Discussed with: deischen, emaste, jhb, rwatson, Martin Simmons <martin@lispworks.com> Tested by: pho Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=296162
* Follow changes made in revision 232144, pass absolute timeout to kernel,David Xu2012-02-271-24/+2
| | | | | | | this eliminates a clock_gettime() syscall. Notes: svn path=/head/; revision=232209
* Revert revision 214007, I realized that MySQL wants to resolveDavid Xu2010-10-201-23/+2
| | | | | | | | | | 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. Notes: svn path=/head/; revision=214093
* Add pthread_rwlockattr_setkind_np and pthread_rwlockattr_getkind_np, theDavid Xu2010-10-181-2/+23
| | | | | | | | | | | | 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. Notes: svn path=/head/; revision=214007
* In current code, statically initialized and destroyed object haveDavid Xu2010-09-281-58/+25
| | | | | | | | | | | 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. Notes: svn path=/head/; revision=213241
* In the current code, rdlock_count is not correctly handled for some cases.Attilio Rao2009-07-061-1/+2
| | | | | | | | | | | | | | | | | | The most notable is that it is not bumped in rwlock_rdlock_common() when the hard path (__thr_rwlock_rdlock()) returns successfully. This can lead to deadlocks in libthr when rwlocks recursion in read mode happens. Fix the interested parts by correctly handling rdlock_count. PR: threads/136345 Reported by: rink Tested by: rink Reviewed by: jeff Approved by: re (kib) MFC: 2 weeks Notes: svn path=/head/; revision=195403
* don't include pthread_np.h, it is not used.David Xu2008-04-141-1/+0
| | | | Notes: svn path=/head/; revision=178194
* Replace userland rwlock with a pure kernel based rwlock, the newDavid Xu2008-04-021-217/+93
| | | | | | | | | implementation does not switch pointers when it resumes waiters. Asked by: jeff Notes: svn path=/head/; revision=177850
* Restore normal pthread_cond_signal path to avoid some obscure races.David Xu2008-04-011-2/+3
| | | | Notes: svn path=/head/; revision=177823
* return EAGAIN early rather than running bunch of code later, micro optimizeDavid Xu2008-04-011-1/+3
| | | | | | | static branch prediction. Notes: svn path=/head/; revision=177818
* Rewrite rwlock to user atomic operations to change rwlock state, thisDavid Xu2008-03-311-140/+223
| | | | | | | | | | eliminates internal mutex lock contention when most rwlock operations are read. Orignal patch provided by: jeff Notes: svn path=/head/; revision=177770
* Remove multiple _get_curthread() calls.David Xu2006-04-231-4/+1
| | | | Notes: svn path=/head/; revision=157976
* WARNS level 4 cleanup.David Xu2006-04-041-1/+1
| | | | Notes: svn path=/head/; revision=157457
* Import my recent 1:1 threading working. some features improved includes:David Xu2005-04-021-316/+263
| | | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=144518
* o Assertions to catch that stuff that shouldn't happen is not happening.Mike Makonnen2004-07-301-20/+16
| | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=132890
* There are consumers of rwlocks, inluding our own libc, that depend onMike Makonnen2004-02-181-96/+24
| | | | | | | | | | | | | a PTHREAD_RWLOCK_INITIALIZER to do for rwlocks what a similarly named symbol does for statically initialized mutexes. This symbol was dropped in The Open Group Base Specifications Issue 6 and does not exist in IEEE Std 1003.1, 2003, but it should still be supported for backwards compatibility. Pointy hat: mtm Notes: svn path=/head/; revision=125969
* I update the rwlock code in libthr to be more standards compliant andMike Makonnen2004-01-291-12/+119
| | | | | | | | | | | | | what do I get for my troubles? libc breaks offcourse! Reimplement a hack (in libthr) that allows libc to use rwlocks without initializing them first. The hack was reimplemented so that only a private libc version of the rwlock locking functions initializes an uninitialized rwlock. The application version will correctly fail. Notes: svn path=/head/; revision=125192
* Implement reference counting of read-write locks. This usesMike Makonnen2004-01-191-8/+133
| | | | | | | | | | | | | | | | | | | | a list in the thread structure to keep track of the locks and how many times they have been locked. This list is checked on every lock and unlock. The traversal through the list is O(n). Most applications don't hold so many locks at once that this will become a problem. However, if it does become a problem it might be a good idea to review this once libthr is off probation and in the optimization cycle. This fixes: o deadlock when a thread tries to recursively acquire a read lock when a writer is waiting on the lock. o a thread could previously successfully unlock a lock it did not own o deadlock when a thread tries to acquire a write lock on a lock it already owns for reading or writing [ this is admittedly not required by POSIX, but is nice to have ] Notes: svn path=/head/; revision=124718
* Add an implementation of pthread_rwlock_timed{rd,wr}lock() to libthr withMike Makonnen2004-01-161-11/+54
| | | | | | | attendant documentation. Notes: svn path=/head/; revision=124586
* o We are not required to initialize an invalid rwlock. So axe all thatMike Makonnen2004-01-161-160/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | code and simply return EINVAL (which is allowed by the standard) in all those pthread functions that previously initialized it. o Refactor the pthread_rwlock_[try]rdlock() and pthread_rwlock_[try]wrlock() functions. They are now completeley condensed into rwlock_rdlock_common() and rwlock_wrlock_common(), respectively. o If the application tries to destroy an rwlock that is currently held by a thread return EBUSY where it previously went ahead and freed all resources associated with the lock. o Refactor _pthread_rwlock_init() to make it look (relatively) sane. o When obtaining a read lock on an rwlock the check for whether it would exceed the maximum allowed read locks should happen *before* we obtain the lock. o The pthread_rwlock_* functions shall *never* return EINTR, so make sure to requeue/resuspend the thread if it encounters such an error. o Make a note that pthread_rwlock_unlock() needs to ensure it holds a lock on an rwlock it tries to unlock. It will be implemented in a separate commit because it requires some additional rwlock infrastructure. Notes: svn path=/head/; revision=124583
* - Add libthr but don't hook it up to the regular build yet. This is anJeff Roberson2003-04-011-0/+341
adaptation of libc_r for the thr system call interface. This is beta quality code. Notes: svn path=/head/; revision=112918