SDFM_CONTROL/EFC_PlatformC28x/Atomic.cpp

62 lines
1.1 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* \file Atomic.cpp
* \project EFC_PlatformC28x
* \date 23 мая 2024 г.
* \author leonidTitov
*
* \brief Создание флага atomic из одной ассемблерной операции (ну ладно, из трёх)
*/
#include "Atomic.hpp"
#ifndef ATOMIC_FLAGS_COUNT
#define ATOMIC_FLAGS_COUNT 32
#endif
extern "C" {
extern uint16_t _test_and_set_bit_1( volatile uint16_t * p );
extern void _clear_bit_1( volatile uint16_t * p );
}
namespace {
volatile uint16_t atomic_flags[ATOMIC_FLAGS_COUNT] = {};
volatile uint16_t * create_flag() {
for( int i = 0; i < ATOMIC_FLAGS_COUNT; i++ )
if( not( _test_and_set_bit_1( atomic_flags + i ) ) )
return &atomic_flags[i];
while(true);
}
void delete_flag( volatile uint16_t * atomic_flag ) {
_clear_bit_1( atomic_flag );
}
}
/**
* Create Flag
*/
umlib::imp::AtomicFlag::AtomicFlag() : flag( create_flag() ) {
clear();
}
/**
* Delete Flag
*/
umlib::imp::AtomicFlag::~AtomicFlag() {
delete_flag( flag );
}