1 /* 2 * Copyright (C) 2005-2018 Team Kodi 3 * This file is part of Kodi - https://kodi.tv 4 * 5 * SPDX-License-Identifier: GPL-2.0-or-later 6 * See LICENSES/README.md for more information. 7 */ 8 9 #include "Atomics.h" 10 11 /////////////////////////////////////////////////////////////////////////// 12 // Fast spinlock implementation. No backoff when busy 13 /////////////////////////////////////////////////////////////////////////// CAtomicSpinLock(std::atomic_flag & lock)14CAtomicSpinLock::CAtomicSpinLock(std::atomic_flag& lock) : m_Lock(lock) 15 { 16 while (atomic_flag_test_and_set(&m_Lock)) {} // Lock 17 } 18 ~CAtomicSpinLock()19CAtomicSpinLock::~CAtomicSpinLock() 20 { 21 std::atomic_flag_clear(&m_Lock); // Unlock 22 } 23