Skip to content

Commit

Permalink
Refactor uses of unsigned for buffer sizes and item counts to size_t.
Browse files Browse the repository at this point in the history
  • Loading branch information
dok-net committed Jan 19, 2020
1 parent 55347b0 commit e8a9673
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
14 changes: 7 additions & 7 deletions src/circular_queue/MultiDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace detail
};
};

template< typename Delegate, typename R = void, bool ISQUEUE = false, unsigned QUEUE_CAPACITY = 32, typename... P>
template< typename Delegate, typename R = void, bool ISQUEUE = false, size_t QUEUE_CAPACITY = 32, typename... P>
class MultiDelegatePImpl
{
public:
Expand Down Expand Up @@ -176,7 +176,7 @@ namespace detail
Node_t* first = nullptr;
Node_t* last = nullptr;
Node_t* unused = nullptr;
unsigned nodeCount = 0;
size_t nodeCount = 0;

// Returns a pointer to an unused Node_t,
// or if none are available allocates a new one,
Expand Down Expand Up @@ -370,7 +370,7 @@ namespace detail
}
};

template< typename Delegate, typename R = void, bool ISQUEUE = false, unsigned QUEUE_CAPACITY = 32>
template< typename Delegate, typename R = void, bool ISQUEUE = false, size_t QUEUE_CAPACITY = 32>
class MultiDelegateImpl : public MultiDelegatePImpl<Delegate, R, ISQUEUE, QUEUE_CAPACITY>
{
protected:
Expand Down Expand Up @@ -456,16 +456,16 @@ namespace detail
}
};

template< typename Delegate, typename R, bool ISQUEUE, unsigned QUEUE_CAPACITY, typename... P> class MultiDelegate;
template< typename Delegate, typename R, bool ISQUEUE, size_t QUEUE_CAPACITY, typename... P> class MultiDelegate;

template< typename Delegate, typename R, bool ISQUEUE, unsigned QUEUE_CAPACITY, typename... P>
template< typename Delegate, typename R, bool ISQUEUE, size_t QUEUE_CAPACITY, typename... P>
class MultiDelegate<Delegate, R(P...), ISQUEUE, QUEUE_CAPACITY> : public MultiDelegatePImpl<Delegate, R, ISQUEUE, QUEUE_CAPACITY, P...>
{
public:
using MultiDelegatePImpl<Delegate, R, ISQUEUE, QUEUE_CAPACITY, P...>::MultiDelegatePImpl;
};

template< typename Delegate, typename R, bool ISQUEUE, unsigned QUEUE_CAPACITY>
template< typename Delegate, typename R, bool ISQUEUE, size_t QUEUE_CAPACITY>
class MultiDelegate<Delegate, R(), ISQUEUE, QUEUE_CAPACITY> : public MultiDelegateImpl<Delegate, R, ISQUEUE, QUEUE_CAPACITY>
{
public:
Expand Down Expand Up @@ -493,7 +493,7 @@ It is designed to be used with Delegate, the efficient runtime wrapper for C fun
allocates from the heap. Unused items are not returned to the heap, but are managed by the MultiDelegate
instance during its own lifetime for efficiency.
*/
template< typename Delegate, bool ISQUEUE = false, unsigned QUEUE_CAPACITY = 32>
template< typename Delegate, bool ISQUEUE = false, size_t QUEUE_CAPACITY = 32>
class MultiDelegate : public detail::MultiDelegate<Delegate, typename Delegate::target_type, ISQUEUE, QUEUE_CAPACITY>
{
public:
Expand Down
10 changes: 5 additions & 5 deletions src/circular_queue/circular_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,14 @@ class circular_queue

protected:
const T defaultValue = {};
unsigned m_bufSize;
size_t m_bufSize;
#if defined(ESP8266) || defined(ESP32) || !defined(ARDUINO)
std::unique_ptr<T[]> m_buffer;
#else
std::unique_ptr<T> m_buffer;
#endif
std::atomic<unsigned> m_inPos;
std::atomic<unsigned> m_outPos;
std::atomic<size_t> m_inPos;
std::atomic<size_t> m_outPos;
};

template< typename T, typename ForEachArg >
Expand All @@ -253,7 +253,7 @@ template< typename T, typename ForEachArg >
bool IRAM_ATTR circular_queue<T, ForEachArg>::push()
{
const auto inPos = m_inPos.load(std::memory_order_acquire);
const unsigned next = (inPos + 1) % m_bufSize;
const size_t next = (inPos + 1) % m_bufSize;
if (next == m_outPos.load(std::memory_order_relaxed)) {
return false;
}
Expand All @@ -268,7 +268,7 @@ template< typename T, typename ForEachArg >
bool IRAM_ATTR circular_queue<T, ForEachArg>::push(T&& val)
{
const auto inPos = m_inPos.load(std::memory_order_acquire);
const unsigned next = (inPos + 1) % m_bufSize;
const size_t next = (inPos + 1) % m_bufSize;
if (next == m_outPos.load(std::memory_order_relaxed)) {
return false;
}
Expand Down
4 changes: 3 additions & 1 deletion src/circular_queue/ghostl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <atomic>
#endif

using size_t = decltype(sizeof(char));

namespace std
{
#if !defined(ARDUINO_ARCH_SAMD)
Expand All @@ -48,7 +50,7 @@ namespace std
template< typename T > T&& move(T& t) noexcept { return static_cast<T&&>(t); }
#endif

template< typename T, unsigned long N > struct array
template< typename T, size_t long N > struct array
{
T _M_elems[N];
decltype(sizeof(0)) size() const { return N; }
Expand Down

0 comments on commit e8a9673

Please sign in to comment.