Skip to content

Commit e8a9673

Browse files
committed
Refactor uses of unsigned for buffer sizes and item counts to size_t.
1 parent 55347b0 commit e8a9673

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/circular_queue/MultiDelegate.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ namespace detail
8787
};
8888
};
8989

90-
template< typename Delegate, typename R = void, bool ISQUEUE = false, unsigned QUEUE_CAPACITY = 32, typename... P>
90+
template< typename Delegate, typename R = void, bool ISQUEUE = false, size_t QUEUE_CAPACITY = 32, typename... P>
9191
class MultiDelegatePImpl
9292
{
9393
public:
@@ -176,7 +176,7 @@ namespace detail
176176
Node_t* first = nullptr;
177177
Node_t* last = nullptr;
178178
Node_t* unused = nullptr;
179-
unsigned nodeCount = 0;
179+
size_t nodeCount = 0;
180180

181181
// Returns a pointer to an unused Node_t,
182182
// or if none are available allocates a new one,
@@ -370,7 +370,7 @@ namespace detail
370370
}
371371
};
372372

373-
template< typename Delegate, typename R = void, bool ISQUEUE = false, unsigned QUEUE_CAPACITY = 32>
373+
template< typename Delegate, typename R = void, bool ISQUEUE = false, size_t QUEUE_CAPACITY = 32>
374374
class MultiDelegateImpl : public MultiDelegatePImpl<Delegate, R, ISQUEUE, QUEUE_CAPACITY>
375375
{
376376
protected:
@@ -456,16 +456,16 @@ namespace detail
456456
}
457457
};
458458

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

461-
template< typename Delegate, typename R, bool ISQUEUE, unsigned QUEUE_CAPACITY, typename... P>
461+
template< typename Delegate, typename R, bool ISQUEUE, size_t QUEUE_CAPACITY, typename... P>
462462
class MultiDelegate<Delegate, R(P...), ISQUEUE, QUEUE_CAPACITY> : public MultiDelegatePImpl<Delegate, R, ISQUEUE, QUEUE_CAPACITY, P...>
463463
{
464464
public:
465465
using MultiDelegatePImpl<Delegate, R, ISQUEUE, QUEUE_CAPACITY, P...>::MultiDelegatePImpl;
466466
};
467467

468-
template< typename Delegate, typename R, bool ISQUEUE, unsigned QUEUE_CAPACITY>
468+
template< typename Delegate, typename R, bool ISQUEUE, size_t QUEUE_CAPACITY>
469469
class MultiDelegate<Delegate, R(), ISQUEUE, QUEUE_CAPACITY> : public MultiDelegateImpl<Delegate, R, ISQUEUE, QUEUE_CAPACITY>
470470
{
471471
public:
@@ -493,7 +493,7 @@ It is designed to be used with Delegate, the efficient runtime wrapper for C fun
493493
allocates from the heap. Unused items are not returned to the heap, but are managed by the MultiDelegate
494494
instance during its own lifetime for efficiency.
495495
*/
496-
template< typename Delegate, bool ISQUEUE = false, unsigned QUEUE_CAPACITY = 32>
496+
template< typename Delegate, bool ISQUEUE = false, size_t QUEUE_CAPACITY = 32>
497497
class MultiDelegate : public detail::MultiDelegate<Delegate, typename Delegate::target_type, ISQUEUE, QUEUE_CAPACITY>
498498
{
499499
public:

src/circular_queue/circular_queue.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,14 @@ class circular_queue
224224

225225
protected:
226226
const T defaultValue = {};
227-
unsigned m_bufSize;
227+
size_t m_bufSize;
228228
#if defined(ESP8266) || defined(ESP32) || !defined(ARDUINO)
229229
std::unique_ptr<T[]> m_buffer;
230230
#else
231231
std::unique_ptr<T> m_buffer;
232232
#endif
233-
std::atomic<unsigned> m_inPos;
234-
std::atomic<unsigned> m_outPos;
233+
std::atomic<size_t> m_inPos;
234+
std::atomic<size_t> m_outPos;
235235
};
236236

237237
template< typename T, typename ForEachArg >
@@ -253,7 +253,7 @@ template< typename T, typename ForEachArg >
253253
bool IRAM_ATTR circular_queue<T, ForEachArg>::push()
254254
{
255255
const auto inPos = m_inPos.load(std::memory_order_acquire);
256-
const unsigned next = (inPos + 1) % m_bufSize;
256+
const size_t next = (inPos + 1) % m_bufSize;
257257
if (next == m_outPos.load(std::memory_order_relaxed)) {
258258
return false;
259259
}
@@ -268,7 +268,7 @@ template< typename T, typename ForEachArg >
268268
bool IRAM_ATTR circular_queue<T, ForEachArg>::push(T&& val)
269269
{
270270
const auto inPos = m_inPos.load(std::memory_order_acquire);
271-
const unsigned next = (inPos + 1) % m_bufSize;
271+
const size_t next = (inPos + 1) % m_bufSize;
272272
if (next == m_outPos.load(std::memory_order_relaxed)) {
273273
return false;
274274
}

src/circular_queue/ghostl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2626
#include <atomic>
2727
#endif
2828

29+
using size_t = decltype(sizeof(char));
30+
2931
namespace std
3032
{
3133
#if !defined(ARDUINO_ARCH_SAMD)
@@ -48,7 +50,7 @@ namespace std
4850
template< typename T > T&& move(T& t) noexcept { return static_cast<T&&>(t); }
4951
#endif
5052

51-
template< typename T, unsigned long N > struct array
53+
template< typename T, size_t long N > struct array
5254
{
5355
T _M_elems[N];
5456
decltype(sizeof(0)) size() const { return N; }

0 commit comments

Comments
 (0)