Skip to content

Commit

Permalink
v1.7:
Browse files Browse the repository at this point in the history
- Fixed README.md thanks to @reydelleon
- INC_IDX & DEC_IDX macros changed to inlines
- Added nonnull function attribute where needed
- Updated Doxyfile
  • Loading branch information
SMFSW committed Jun 2, 2019
1 parent 00e6ec8 commit c1222e6
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 43 deletions.
5 changes: 3 additions & 2 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = Queue
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.6
PROJECT_NUMBER = 1.7

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down Expand Up @@ -2051,7 +2051,8 @@ INCLUDE_FILE_PATTERNS = *.h
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

PREDEFINED = ARDUINO=10506 \
DBG_QUEUE
DOXY=1 \
__attribute__(x)=

# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
Expand Down
5 changes: 3 additions & 2 deletions Doxyfile.auto
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = Queue
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.6
PROJECT_NUMBER = 1.7

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down Expand Up @@ -2051,7 +2051,8 @@ INCLUDE_FILE_PATTERNS = *.h
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

PREDEFINED = ARDUINO=10506 \
DBG_QUEUE
DOXY=1 \
__attribute__(x)=

# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
Expand Down
8 changes: 7 additions & 1 deletion ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Queue handling library (designed on Arduino)
2017-2018 SMFSW
2017-2019 SMFSW

Feel free to share your thoughts @ xgarmanboziax@gmail.com about:
- issues encountered
Expand All @@ -10,6 +10,12 @@ Feel free to share your thoughts @ xgarmanboziax@gmail.com about:

** Actual:

v1.7: 2 Jun 2019:
- Fixed README.md thanks to @reydelleon
- INC_IDX & DEC_IDX macros changed to inlines
- Added nonnull function attribute where needed
- Updated Doxyfile

v1.6 26 May 2018:
- Constructor does not check anymore if class instance is already allocated (as it supposedly isn't)
- Added getRemainingCount inline returning how much records are left in the queue
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Queue
version=1.6
version=1.7
author=SMFSW <xgarmanboziax@gmail.com>
maintainer=SMFSW <xgarmanboziax@gmail.com>
sentence=Queue handling library.
Expand Down
75 changes: 46 additions & 29 deletions src/cppQueue.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*!\file cppQueue.cpp
** \author SMFSW
** \date 2018/05/26
** \copyright BSD 3-Clause License (c) 2017-2018, SMFSW
** \copyright BSD 3-Clause License (c) 2017-2019, SMFSW
** \brief Queue handling library (designed on Arduino)
** \details Queue handling library (designed on Arduino)
** This library was designed for Arduino, yet may be compiled without change with gcc for other purposes/targets
Expand All @@ -16,11 +15,29 @@ extern "C" {
/****************************************************************/


#define INC_IDX(ctr, end, start) if (ctr < (end-1)) { ctr++; } \
else { ctr = start; } //!< Increments buffer index \b ctr rolling back to \b start when limit \b end is reached
/*! \brief Increment index
** \details Increment buffer index \b pIdx rolling back to \b start when limit \b end is reached
** \param [in,out] pIdx - pointer to index value
** \param [in] end - counter upper limit value
** \param [in] start - counter lower limit value
**/
static inline void __attribute__((nonnull, always_inline)) inc_idx(uint16_t * pIdx, const uint16_t end, const uint16_t start)
{
if (*pIdx < end - 1) { (*pIdx)++; }
else { *pIdx = start; }
}

#define DEC_IDX(ctr, end, start) if (ctr > (start)) { ctr--; } \
else { ctr = end-1; } //!< Decrements buffer index \b ctr rolling back to \b end when limit \b start is reached
/*! \brief Decrement index
** \details Decrement buffer index \b pIdx rolling back to \b end when limit \b start is reached
** \param [in,out] pIdx - pointer to index value
** \param [in] end - counter upper limit value
** \param [in] start - counter lower limit value
**/
static inline void __attribute__((nonnull, always_inline)) dec_idx(uint16_t * pIdx, const uint16_t end, const uint16_t start)
{
if (*pIdx > start) { (*pIdx)--; }
else { *pIdx = end - 1; }
}


Queue::Queue(const uint16_t size_rec, const uint16_t nb_recs, const QueueType type, const bool overwrite)
Expand Down Expand Up @@ -58,68 +75,68 @@ void Queue::flush(void)
}


bool Queue::push(const void * record)
bool __attribute__((nonnull)) Queue::push(const void * record)
{
if ((!ovw) && isFull()) { return false; }

uint8_t * pStart = queue + (rec_sz * in);
memcpy(pStart, record, rec_sz);
INC_IDX(in, rec_nb, 0);

inc_idx(&in, rec_nb, 0);

if (!isFull()) { cnt++; } // Increase records count
else if (ovw) // Queue is full and overwrite is allowed
{
if (impl == FIFO) { INC_IDX(out, rec_nb, 0); } // as oldest record is overwritten, increment out
if (impl == FIFO) { inc_idx(&out, rec_nb, 0); } // as oldest record is overwritten, increment out
//else if (impl == LIFO) {} // Nothing to do in this case
}

return true;
}

bool Queue::pop(void * record)
bool __attribute__((nonnull)) Queue::pop(void * record)
{
uint8_t * pStart;

if (isEmpty()) { return false; } // No more records

if (impl == FIFO)
{
pStart = queue + (rec_sz * out);
INC_IDX(out, rec_nb, 0);
inc_idx(&out, rec_nb, 0);
}
else if (impl == LIFO)
{
DEC_IDX(in, rec_nb, 0);
dec_idx(&in, rec_nb, 0);
pStart = queue + (rec_sz * in);
}
else { return false; }

memcpy(record, pStart, rec_sz);
cnt--; // Decrease records count
return true;
}


bool Queue::peek(void * record)
bool __attribute__((nonnull)) Queue::peek(void * record)
{
uint8_t * pStart;

if (isEmpty()) { return false; } // No more records

if (impl == FIFO)
{
pStart = queue + (rec_sz * out);
// No change on out var as it's just a peek
}
else if (impl == LIFO)
{
uint16_t rec = in; // Temporary var for peek (no change on in with DEC_IDX)
DEC_IDX(rec, rec_nb, 0);
uint16_t rec = in; // Temporary var for peek (no change on in with dec_idx)
dec_idx(&rec, rec_nb, 0);
pStart = queue + (rec_sz * rec);
}
else { return false; }

memcpy(record, pStart, rec_sz);
return true;
}
Expand All @@ -128,11 +145,11 @@ bool Queue::peek(void * record)
bool Queue::drop(void)
{
if (isEmpty()) { return false; } // No more records
if (impl == FIFO) { INC_IDX(out, rec_nb, 0); }
else if (impl == LIFO) { DEC_IDX(in, rec_nb, 0); }

if (impl == FIFO) { inc_idx(&out, rec_nb, 0); }
else if (impl == LIFO) { dec_idx(&in, rec_nb, 0); }
else { return false; }

cnt--; // Decrease records count
return true;
}
15 changes: 7 additions & 8 deletions src/cppQueue.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*!\file cppQueue.h
** \author SMFSW
** \date 2018/05/26
** \copyright BSD 3-Clause License (c) 2017-2018, SMFSW
** \copyright BSD 3-Clause License (c) 2017-2019, SMFSW
** \brief Queue handling library (designed on Arduino)
** \details Queue handling library (designed on Arduino)
** This library was designed for Arduino, yet may be compiled without change with gcc for other purposes/targets
Expand Down Expand Up @@ -38,7 +37,7 @@ class Queue
uint16_t rec_sz; //!< Size of a record
uint32_t queue_sz; //!< Size of the full queue
uint8_t * queue; //!< Queue start pointer (when allocated)

uint16_t in; //!< number of records pushed into the queue
uint16_t out; //!< number of records pulled from the queue (only for FIFO)
uint16_t cnt; //!< number of records not retrieved from the queue
Expand All @@ -64,7 +63,7 @@ class Queue
/*! \brief Clean queue, restarting from empty queue
** \deprecated clean was already used in Queue lib, alias is made to keep compatibility with earlier versions
**/
inline void clean(void)__attribute__((always_inline)) {
inline void clean(void) __attribute__((always_inline)) {
flush(); }

/*! \brief get initialization state of the queue
Expand Down Expand Up @@ -123,7 +122,7 @@ class Queue
** \retval true if successfully pushed into queue
** \retval false if queue is full
**/
bool push(const void * record);
bool push(const void * record) __attribute__((nonnull));

/*! \brief Pop record from queue
** \warning If using push, pop, peek and/or drop in both interrupts and main application,
Expand All @@ -133,7 +132,7 @@ class Queue
** \retval true if successfully popped from queue
** \retval false if queue is empty
**/
bool pop(void * record);
bool pop(void * record) __attribute__((nonnull));

/*! \brief Pull record from queue (same as pop)
** \warning If using push, pop, peek and/or drop in both interrupts and main application,
Expand All @@ -144,7 +143,7 @@ class Queue
** \retval true if successfully pulled from queue
** \retval false if queue is empty
**/
inline bool pull(void * record)__attribute__((always_inline)) {
inline bool pull(void * record) __attribute__((nonnull,always_inline)) {
return pop(record); }

/*! \brief Peek record from queue
Expand All @@ -155,7 +154,7 @@ class Queue
** \retval true if successfully peeked from queue
** \retval false if queue is empty
**/
bool peek(void * record);
bool peek(void * record) __attribute__((nonnull));

/*! \brief Drop current record from queue
** \warning If using push, pop, peek and/or drop in both interrupts and main application,
Expand Down

0 comments on commit c1222e6

Please sign in to comment.