mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-16 03:40:34 +08:00
TransferPerfCounter made noncopyable, returns counters by references
This commit is contained in:
@@ -7,13 +7,14 @@
|
||||
|
||||
#include <uavcan/std.hpp>
|
||||
#include <uavcan/build_config.hpp>
|
||||
#include <uavcan/util/templates.hpp>
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
#if UAVCAN_TINY
|
||||
|
||||
class UAVCAN_EXPORT TransferPerfCounter
|
||||
class UAVCAN_EXPORT TransferPerfCounter : Noncopyable
|
||||
{
|
||||
public:
|
||||
void addTxTransfer() { }
|
||||
@@ -27,7 +28,12 @@ public:
|
||||
|
||||
#else
|
||||
|
||||
class UAVCAN_EXPORT TransferPerfCounter
|
||||
/**
|
||||
* The class is declared noncopyable for two reasons:
|
||||
* - to prevent accidental pass-by-value into a mutator
|
||||
* - to make the addresses of the counters fixed and exposable to the user of the library
|
||||
*/
|
||||
class UAVCAN_EXPORT TransferPerfCounter : Noncopyable
|
||||
{
|
||||
uint64_t transfers_tx_;
|
||||
uint64_t transfers_rx_;
|
||||
@@ -50,9 +56,13 @@ public:
|
||||
errors_ += errors;
|
||||
}
|
||||
|
||||
uint64_t getTxTransferCount() const { return transfers_tx_; }
|
||||
uint64_t getRxTransferCount() const { return transfers_rx_; }
|
||||
uint64_t getErrorCount() const { return errors_; }
|
||||
/**
|
||||
* Returned references are guaranteed to be valid as long as this instance of Node exists.
|
||||
* This is enforced by virtue of the class being Noncopyable.
|
||||
*/
|
||||
const uint64_t& getTxTransferCount() const { return transfers_tx_; }
|
||||
const uint64_t& getRxTransferCount() const { return transfers_rx_; }
|
||||
const uint64_t& getErrorCount() const { return errors_; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user