Why can I not writeLock after ReadLock?

Milian Wolff mail at milianw.de
Sat Nov 13 12:01:59 UTC 2010

On Saturday 13 November 2010 00:40:06 Milian Wolff wrote:
> Hey there, esp. David.
> why is this not allowed (see also duchainlock.cpp:163):
> DUChainReadLocker lockRead;
> /* do stuff that only requires a read lock */
> ...
> DUChainWriteLocker lockWrite;
> /* do stuff that also needs a write lock */
> I assumed that a write lock is the same as a read lock, just with
> *additional* checks. Since the above is not possible, I have to unlock the
> chain (if only for a *very* short time) which would potentially make it
> possible for declarations to get invalid (DeclarationPointer, I know - but
> still, it should *not* happen to begin with).
> And to have a write lock *all the time* sounds like overkill to me. The
> usebuilder e.g. needs to find some declaration (read) which takes most of
> the time probably, then only it has to report a new use (only write
> operation).
> PHP did this up until now (which is of course hazardous, thanks for
> pointing that out through your commit):
> Declaration* dec = findDeclaration(someIdentifier);
> newUse(node, dec);
> i.e. no locking at all - yay :)
> Now I thought let's fix it this way:
> DUChainReadLocker lock;
> Declaration* dec = findDeclaration(someIdentifier);
> DUChainWriteLocker lockW;
> newUse(node, dec);
> But well, it's not working as I said above. Why?

This attached patch makes things work in a manner I'd like. Anything wrong 
with it? David?

Milian Wolff
mail at milianw.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: readwritelock.patch
Type: text/x-patch
Size: 2271 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20101113/9b21d7a8/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20101113/9b21d7a8/attachment.sig>

More information about the KDevelop-devel mailing list