code format

This commit is contained in:
2022-12-14 14:13:52 +03:00
parent 430a41fefc
commit c2b8a8d6da
297 changed files with 27331 additions and 24162 deletions

View File

@@ -5,39 +5,39 @@
* \~russian Быстрая блокировка с полной нагрузкой
*/
/*
PIP - Platform Independent Primitives
PISpinlock
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
PISpinlock
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PISPINLOCK_H
#define PISPINLOCK_H
#include "piinit.h"
#include <atomic>
class PIP_EXPORT PISpinlock
{
class PIP_EXPORT PISpinlock {
public:
NO_COPY_CLASS(PISpinlock);
//! \~english Constructs unlocked spinlock
//! \~russian Создает незаблокированный спинлок
explicit PISpinlock() {flag.clear();}
explicit PISpinlock() { flag.clear(); }
//! \~english Destroy spinlock
//! \~russian Деструктор спинлока
@@ -53,7 +53,10 @@ public:
//! \~russian
//! Если спинлок свободен, то блокирует его и возвращает управление немедленно.
//! Если спинлок заблокирован, то ожидает разблокировки, затем блокирует и возвращает управление
void lock() {while (flag.test_and_set(std::memory_order_acquire));}
void lock() {
while (flag.test_and_set(std::memory_order_acquire))
;
}
//! \~english Unlock spinlock
//! \~russian Разблокирует спинлок
@@ -62,31 +65,32 @@ public:
//! In any case this function returns immediate
//! \~russian
//! В любом случае возвращает управление немедленно
void unlock() {flag.clear(std::memory_order_release);}
void unlock() { flag.clear(std::memory_order_release); }
private:
std::atomic_flag flag;
};
class PIP_EXPORT PISpinlockLocker
{
class PIP_EXPORT PISpinlockLocker {
public:
NO_COPY_CLASS(PISpinlockLocker);
//! \~english Constructs and lock "s" if "condition" is \c true
//! \~russianСоздает и блокирует спинлок "m" если "condition" \c true
PISpinlockLocker(PISpinlock & s, bool condition = true): spinlock(s), cond(condition) {if (cond) spinlock.lock();}
PISpinlockLocker(PISpinlock & s, bool condition = true): spinlock(s), cond(condition) {
if (cond) spinlock.lock();
}
//! \~english Unlock "s" if "condition" was \c true
//! \~russian Разблокирует спинлок "m" если "condition" был \c true
~PISpinlockLocker() {if (cond) spinlock.unlock();}
~PISpinlockLocker() {
if (cond) spinlock.unlock();
}
private:
PISpinlock & spinlock;
bool cond;
};