Re-writing locking around dispatch_queues. The old pthread_rwlock had some (rare) deadlocking cases.