summaryrefslogtreecommitdiff
path: root/sys/src/libc/9sys/qlock.c
AgeCommit message (Collapse)Author
2017-10-28libc: improve alignment of QLp structure on amd64, cosmeticscinap_lenrek
the QLp structure used to occupy 24 bytes on amd64. with some rearranging the fields we can get it to 16 bytes, saving 8K in the data section for the 1024 preallocated structs in the ql arena. the rest of the changes are of cosmetic nature: - getqlp() zeros the next pointer, so there is no need to set it when queueing the entry. - always explicitely compare pointers to nil. - delete unused code from ape's qlock.c
2017-10-26libc: wunlock() part 2cinap_lenrek
the initial issue was that wunlock() would wakeup readers while holding the spinlock causing deadlock in libthread programs where rendezvous() would do a thread switch within the same process which then can acquire the RWLock again. the first fix tried to prevent holding the spinlock, waking up one reader at a time with releasing an re-acquiering the spinlock. this violates the invariant that readers can only wakup writers in runlock() when multiple readers where queued at the time of wunlock(). at the first wakeup, q->head != nil so runlock() would find a reader queued on runlock() when it expected a writer. this (hopefully last) fix unlinks *all* the reader QLp's atomically and in order while holding the spinlock and then traverses the dequeued chain of QLp structures again to call rendezvous() so the invariant described above holds.
2016-03-19libc: trailing whitespace cleanupBurnZeZ
2015-08-10libc: fix wunlock() libthread deadlockcinap_lenrek
when wunlock() was used by threads running within the same proc, the wunlock() can deadlock as it keeps holding the RWLock.lock spinlock while indirectly calling _threadrendezvous(). when _threadrendezvous() switches to another thread in the same proc, then that thread can hang at rlock()/wlock()/runlock() again waiting for wunlock() to release the spinlock which will never happen as lock() does not schedule threads. wunlock() is changed to release the spinlock during rendezvous wakeup of readers. note that this is a bit dangerous as more readers might queue concurrently now which means that if we cannot keep up with the wakeups, we might keep on waking readers forever. that will be another patch for the future.
2011-03-30Import sources from 2011-03-30 iso image - libTaru Karttunen
2011-03-30Import sources from 2011-03-30 iso imageTaru Karttunen