MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/systemic/SharedData.hh
2024-06-07 11:12:56 +03:00

71 lines
1.8 KiB
C++
Raw 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.

/*
* SharedData.hh
*
* Created on: 5 апр. 2021 г.
* 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_ */