139 lines
3.1 KiB
C++
139 lines
3.1 KiB
C++
|
|
/*
|
|||
|
|
* SharedData.cpp
|
|||
|
|
*
|
|||
|
|
* Created on: 6 <EFBFBD><EFBFBD><EFBFBD>. 2021 <EFBFBD>.
|
|||
|
|
* Author: titov
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
#include "SharedData.hh"
|
|||
|
|
|
|||
|
|
std::pair<char *, std::size_t> 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<peripheral::protected_char *, std::size_t> 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<const peripheral::protected_char *, std::size_t> 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<peripheral::protected_char * >( data.first ), data.second );
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void systemic::ProtectedDataView::unlock_shared() {
|
|||
|
|
|
|||
|
|
peripheral::read_unlock( const_cast<peripheral::protected_char * >( data.first ), data.second );
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
systemic::ProtectedDataView::ProtectedDataView() :
|
|||
|
|
data( nullptr, 0 ) {}
|
|||
|
|
|
|||
|
|
systemic::ProtectedDataView::ProtectedDataView(
|
|||
|
|
std::pair<const peripheral::protected_char *, std::size_t> 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 );
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|