Locking fixes (I think)

I was getting into a condition (Java 7 on OS X) where the writeLock vs readLock were conflicting. The holder of the writeLock was semi-busy-looping, waiting for the `writeCache` to empty, but never released the lock (or awaited a condition) before entering that loop.

Also maybe fixes lock confusion in `compareAndSwap`, because as is that method would lock the read lock, but unlock the write lock. I assumed you meant to use the write lock.