replace synchronized w/ lock for openStreamWrites

also move new stream event reporting outside of lock
make trimOutputBuffers use a tryLock
make waitForWriteClosure use tryLock()s
fix possible overflow error in cache comparator