/* * SharedData.cpp * * Created on: 6 апр. 2021 г. * Author: titov */ #include "SharedData.hh" std::pair systemic::SharedData::get() const { return data; } void systemic::SharedData::lock() { while( not try_lock() ); } bool systemic::SharedData::try_lock() { return peripheral::write_lock(data.first, data.second); } void systemic::SharedData::unlock() { peripheral::write_unlock(data.first, data.second); } void systemic::SharedData::lock_shared() { while( not try_lock_shared() ); } bool systemic::SharedData::try_lock_shared() { return peripheral::read_lock(data.first, data.second); } void systemic::SharedData::unlock_shared() { peripheral::read_unlock(data.first, data.second); } systemic::SharedData::SharedData( std::pair data ) : data(data) {} systemic::SharedData::SharedData( peripheral::protected_char * buff, std::size_t size ) : data( buff, size ) {} systemic::SharedData::SharedData( const SharedData & right ) : data(right.data) {} systemic::SharedData::~SharedData() {} systemic::SharedData & systemic::SharedData::operator=( SharedData right ) { data = right.data; return *this; } systemic::SharedData systemic::SharedData::part( peripheral::protected_char * buff, std::size_t size ) { if( buff >= data.first and ( buff + size ) < ( data.first + data.second) ) return systemic::SharedData( buff, size ); return systemic::SharedData( nullptr, 0 ); } systemic::SharedData::SharedData() : data( nullptr, 0) {} std::pair systemic::ProtectedDataView::get() const { return data; } void systemic::ProtectedDataView::lock_shared() { while( not try_lock_shared() ); } bool systemic::ProtectedDataView::try_lock_shared() { return peripheral::read_lock( const_cast( data.first ), data.second ); } void systemic::ProtectedDataView::unlock_shared() { peripheral::read_unlock( const_cast( data.first ), data.second ); } systemic::ProtectedDataView::ProtectedDataView() : data( nullptr, 0 ) {} systemic::ProtectedDataView::ProtectedDataView( std::pair data) : data(data) {} systemic::ProtectedDataView::ProtectedDataView( const peripheral::protected_char * buff, std::size_t size) : data( buff, size ) {} systemic::ProtectedDataView::ProtectedDataView( const ProtectedDataView & right ) : data(right.data) {} systemic::ProtectedDataView & systemic::ProtectedDataView::operator=( ProtectedDataView right ) { data = right.data; return *this; } systemic::ProtectedDataView::~ProtectedDataView() {} systemic::ProtectedDataView systemic::ProtectedDataView::part( const peripheral::protected_char * buff, std::size_t size) { if( buff >= data.first and ( buff + size ) < ( data.first + data.second) ) return systemic::ProtectedDataView( buff, size ); return systemic::ProtectedDataView( nullptr, 0 ); }