Fix deadlock on waiting for pending_writers to be empty

Deadlock can occur when a reader X waits for pending writers
to be empty but the reader X already owns a read lock (since
it will then wait for pending writers to be empty which it
will never be, since pending writers is only empty when
there are no readers - but since the current thread X is getting
another read lock it result in deadlock for the reader and
deadlock for the writer).

Closes-Bug: #1276868

Change-Id: Ibe13eafa4bd0bc817e8bfe3cf303c54298778b37
Merge "Fix deadlock on waiting for pending_writers to be empty"