Make pthread mutex locking more generic. Instead of