Change in vdsm[master]: rwlock: Add simpler RWLock
nsoffer at redhat.com
nsoffer at redhat.com
Mon Jul 27 10:59:13 UTC 2015
Nir Soffer has posted comments on this change.
Change subject: rwlock: Add simpler RWLock
......................................................................
Patch Set 16:
(5 comments)
https://gerrit.ovirt.org/#/c/42908/16/lib/vdsm/rwlock.py
File lib/vdsm/rwlock.py:
Line 39: lock.release()
Line 40:
Line 41: If possible, use the RWLock.exclusive contextmanager:
Line 42:
Line 43: with lock.exclusive:
> the syntax is not symmetric. 'acquire_write' vs. 'exclusive'. while it is s
This is out of the scope of this effort. I'm intentionally keeping the api as is (except using pep8 style function names).
Line 44: do stuff that require an exclusive lock..
Line 45:
Line 46: When a thread is holding a write lock, other threads requesting a write or
Line 47: read lock will be blocked. When you release the write lock, the waiting
Line 91: if me in self._holders:
Line 92: raise RuntimeError("Lock promotion is forbidden")
Line 93: with self._lock:
Line 94: if self._holders or self._waiters:
Line 95: self._wait(True)
> can you name the parameter? it makes it read beeter
See bellow.
Line 96: self._holders[me] = 1
Line 97: self._writer = me
Line 98:
Line 99: def acquire_read(self):
Line 104: self._holders[me] += 1
Line 105: return
Line 106: with self._lock:
Line 107: if self._writer or self._waiters:
Line 108: self._wait(False)
> can you name the parameter? it makes it read beeter
wants_write is positional parameter. Calling with as kwarg parameter is confusing and fragile. The name of a positional argument does not matter, and can be safely changed without affecting the callers, unless the callers are using kwargs call style.
I intentionally not using kwarg parameter since wants_write should not have a default.
Line 109: self._holders[me] = 1
Line 110: if self._waiters:
Line 111: self._wakeup_next_waiter()
Line 112:
Line 135: self._lock.acquire()
Line 136: finally:
Line 137: self._waiters.remove(waiter)
Line 138:
Line 139: def _wakeup_next_waiter(self):
> wake_up
wakeup is nicer.
Line 140: if self._holders and self._waiters[0].wants_write:
Line 141: return
Line 142: self._waiters[0].wakeup()
Line 143:
Line 150:
Line 151: def wait(self):
Line 152: self._event.wait()
Line 153:
Line 154: def wakeup(self):
> wake_up
wakeup is nicer.
Line 155: self._event.set()
Line 156:
Line 157:
Line 158: class Context(object):
--
To view, visit https://gerrit.ovirt.org/42908
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I2466c137c89598772fb46347eb02195916883cac
Gerrit-PatchSet: 16
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>
Gerrit-Reviewer: Adam Litke <alitke at redhat.com>
Gerrit-Reviewer: Ala Hino <ahino at redhat.com>
Gerrit-Reviewer: Allon Mureinik <amureini at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Dima Kuznetsov <dkuznets at redhat.com>
Gerrit-Reviewer: Federico Simoncelli <fsimonce at redhat.com>
Gerrit-Reviewer: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Freddy Rolland <frolland at redhat.com>
Gerrit-Reviewer: Ido Barkan <ibarkan at redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer <nsoffer at redhat.com>
Gerrit-Reviewer: Yaniv Bronhaim <ybronhei at redhat.com>
Gerrit-Reviewer: automation at ovirt.org
Gerrit-HasComments: Yes
More information about the vdsm-patches
mailing list