From c50e4a6e21c3207dc839284bfc38483447b44171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Tue, 18 Oct 2016 13:20:19 +0200 Subject: [PATCH] uORB::DeviceNode: reduce the size of some members The limits the maximum queue size to 255, which I think is ok for the forseable future. sizeof(uORB::DeviceNode) is reduces from 128 to 112 on NuttX, and with ~80 instances, this saves over 1KB of RAM. --- src/modules/uORB/uORBDevices.cpp | 12 +++++------- src/modules/uORB/uORBDevices.hpp | 9 ++++----- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/modules/uORB/uORBDevices.cpp b/src/modules/uORB/uORBDevices.cpp index de4d99129d..b03a2980a2 100644 --- a/src/modules/uORB/uORBDevices.cpp +++ b/src/modules/uORB/uORBDevices.cpp @@ -93,14 +93,11 @@ uORB::DeviceNode::DeviceNode(const struct orb_metadata *meta, const char *name, _data(nullptr), _last_update(0), _generation(0), - _priority(priority), + _priority((uint8_t)priority), _published(false), _queue_size(queue_size), - _publisher(0), -#ifdef __PX4_NUTTX - _IsRemoteSubscriberPresent(false), -#endif - _subscriber_count(0) + _subscriber_count(0), + _publisher(0) { // enable debug() calls //_debug_enabled = true; @@ -749,7 +746,8 @@ int uORB::DeviceNode::update_queue_size(unsigned int queue_size) return PX4_OK; } - if (_data || _queue_size > queue_size) { + //queue size is limited to 255 for the single reason that we use uint8 to store it + if (_data || _queue_size > queue_size || queue_size > 255) { return ERROR; } diff --git a/src/modules/uORB/uORBDevices.hpp b/src/modules/uORB/uORBDevices.hpp index 69d6df099c..01ab0aa0de 100644 --- a/src/modules/uORB/uORBDevices.hpp +++ b/src/modules/uORB/uORBDevices.hpp @@ -186,7 +186,7 @@ public: bool print_statistics(bool reset); unsigned int get_queue_size() const { return _queue_size; } - int32_t subscriber_count() const { return _subscriber_count; } + int16_t subscriber_count() const { return _subscriber_count; } uint32_t lost_message_count() const { return _lost_messages; } unsigned int published_message_count() const { return _generation; } const struct orb_metadata *get_meta() const { return _meta; } @@ -221,21 +221,20 @@ private: uint8_t *_data; /**< allocated object buffer */ hrt_abstime _last_update; /**< time the object was last updated */ volatile unsigned _generation; /**< object generation count */ - const int _priority; /**< priority of topic */ + const uint8_t _priority; /**< priority of the topic */ bool _published; /**< has ever data been published */ - unsigned int _queue_size; /**< maximum number of elements in the queue */ + uint8_t _queue_size; /**< maximum number of elements in the queue */ + int16_t _subscriber_count; inline static SubscriberData *filp_to_sd(device::file_t *filp); #ifdef __PX4_NUTTX pid_t _publisher; /**< if nonzero, current publisher. Only used inside the advertise call. We allow one publisher to have an open file descriptor at the same time. */ - bool _IsRemoteSubscriberPresent; #else px4_task_t _publisher; /**< if nonzero, current publisher. Only used inside the advertise call. We allow one publisher to have an open file descriptor at the same time. */ #endif - int32_t _subscriber_count; //statistics uint32_t _lost_messages = 0; ///< nr of lost messages for all subscribers. If two subscribers lose the same