tsan: minor refactoring

Replace duplicate code snippet with function.