71 lines
1.8 KiB
C++
71 lines
1.8 KiB
C++
|
|
/*
|
|||
|
|
* SharedData.hh
|
|||
|
|
*
|
|||
|
|
* Created on: 5 <EFBFBD><EFBFBD><EFBFBD>. 2021 <EFBFBD>.
|
|||
|
|
* Author: titov
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
#ifndef UMLIBRARY_SYSTEMIC_SHAREDDATA_HH_
|
|||
|
|
#define UMLIBRARY_SYSTEMIC_SHAREDDATA_HH_
|
|||
|
|
|
|||
|
|
#include "../peripheral/ProtectedMemory.hh"
|
|||
|
|
|
|||
|
|
#include <utility>
|
|||
|
|
|
|||
|
|
namespace systemic {
|
|||
|
|
|
|||
|
|
struct SharedData {
|
|||
|
|
|
|||
|
|
std::pair<peripheral::protected_char *, std::size_t> get() const;
|
|||
|
|
|
|||
|
|
// exclusive ownership
|
|||
|
|
void lock(); // blocking
|
|||
|
|
bool try_lock();
|
|||
|
|
void unlock();
|
|||
|
|
|
|||
|
|
// shared ownership
|
|||
|
|
void lock_shared(); // blocking
|
|||
|
|
bool try_lock_shared();
|
|||
|
|
void unlock_shared();
|
|||
|
|
|
|||
|
|
SharedData();
|
|||
|
|
SharedData( std::pair<peripheral::protected_char *, std::size_t> data );
|
|||
|
|
SharedData( peripheral::protected_char * buff, std::size_t size );
|
|||
|
|
SharedData( const SharedData & );
|
|||
|
|
SharedData & operator=( SharedData data );
|
|||
|
|
~SharedData();
|
|||
|
|
|
|||
|
|
SharedData part( peripheral::protected_char * buff, std::size_t size );
|
|||
|
|
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
std::pair<peripheral::protected_char *, std::size_t> data;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
struct ProtectedDataView {
|
|||
|
|
|
|||
|
|
std::pair<const peripheral::protected_char *, std::size_t> get() const;
|
|||
|
|
|
|||
|
|
// shared ownership
|
|||
|
|
void lock_shared(); // blocking
|
|||
|
|
bool try_lock_shared();
|
|||
|
|
void unlock_shared();
|
|||
|
|
|
|||
|
|
ProtectedDataView();
|
|||
|
|
ProtectedDataView( std::pair<const peripheral::protected_char *, std::size_t> data );
|
|||
|
|
ProtectedDataView( const peripheral::protected_char * buff, std::size_t size );
|
|||
|
|
ProtectedDataView( const ProtectedDataView & );
|
|||
|
|
ProtectedDataView & operator=( ProtectedDataView data );
|
|||
|
|
~ProtectedDataView();
|
|||
|
|
|
|||
|
|
ProtectedDataView part( const peripheral::protected_char * buff, std::size_t size );
|
|||
|
|
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
std::pair<const peripheral::protected_char *, std::size_t> data;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endif /* UMLIBRARY_SYSTEMIC_SHAREDDATA_HH_ */
|