mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #2674 from Darredevil/patch-1
core: limit message queue size
This commit is contained in:
commit
2bb5468df4
@ -18,8 +18,10 @@
|
||||
* @author unknown, propably Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*/
|
||||
|
||||
#ifndef __CIB_H
|
||||
#define __CIB_H
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef CIB_H
|
||||
#define CIB_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -29,9 +31,9 @@ extern "C" {
|
||||
* @brief circular integer buffer structure
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned int read_count; /**< number of (successful) read accesses */
|
||||
unsigned int write_count; /**< number of (successful) write accesses */
|
||||
unsigned int mask; /**< Size of buffer -1, i.e. mask of the bits */
|
||||
uint16_t read_count; /**< number of (successful) read accesses */
|
||||
uint16_t write_count; /**< number of (successful) write accesses */
|
||||
uint16_t mask; /**< Size of buffer -1, i.e. mask of the bits */
|
||||
} cib_t;
|
||||
|
||||
/**
|
||||
@ -44,9 +46,9 @@ typedef struct {
|
||||
*
|
||||
* @param[out] cib Buffer to initialize.
|
||||
* Must not be NULL.
|
||||
* @param[in] size Size of the buffer, must not exceed MAXINT/2.
|
||||
* @param[in] size Size of the buffer, must not exceed 32,768
|
||||
*/
|
||||
static inline void cib_init(cib_t *__restrict cib, unsigned int size)
|
||||
static inline void cib_init(cib_t *__restrict cib, uint16_t size)
|
||||
{
|
||||
cib_t c = CIB_INIT(size);
|
||||
*cib = c;
|
||||
@ -59,7 +61,7 @@ static inline void cib_init(cib_t *__restrict cib, unsigned int size)
|
||||
* Must not be NULL.
|
||||
* @return How often cib_get() can be called before the CIB is empty.
|
||||
*/
|
||||
static inline unsigned int cib_avail(cib_t *__restrict cib)
|
||||
static inline uint16_t cib_avail(cib_t *__restrict cib)
|
||||
{
|
||||
return cib->write_count - cib->read_count;
|
||||
}
|
||||
@ -71,12 +73,12 @@ static inline unsigned int cib_avail(cib_t *__restrict cib)
|
||||
* Must not be NULL.
|
||||
* @return index of next item, -1 if the buffer is empty
|
||||
*/
|
||||
static inline int cib_get(cib_t *__restrict cib)
|
||||
static inline int16_t cib_get(cib_t *__restrict cib)
|
||||
{
|
||||
unsigned int avail = cib_avail(cib);
|
||||
uint16_t avail = cib_avail(cib);
|
||||
|
||||
if (avail > 0) {
|
||||
return (int) (cib->read_count++ & cib->mask);
|
||||
return (int16_t) (cib->read_count++ & cib->mask);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@ -89,13 +91,13 @@ static inline int cib_get(cib_t *__restrict cib)
|
||||
* Must not be NULL.
|
||||
* @return index of item to put to, -1 if the buffer is full
|
||||
*/
|
||||
static inline int cib_put(cib_t *__restrict cib)
|
||||
static inline int16_t cib_put(cib_t *__restrict cib)
|
||||
{
|
||||
unsigned int avail = cib_avail(cib);
|
||||
uint16_t avail = cib_avail(cib);
|
||||
|
||||
/* We use a signed compare, because the mask is -1u for an empty CIB. */
|
||||
if ((int) avail <= (int) cib->mask) {
|
||||
return (int) (cib->write_count++ & cib->mask);
|
||||
if ((int16_t) avail <= (int16_t) cib->mask) {
|
||||
return (int16_t) (cib->write_count++ & cib->mask);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@ -105,5 +107,5 @@ static inline int cib_put(cib_t *__restrict cib)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CIB_H */
|
||||
#endif /* CIB_H */
|
||||
/** @} */
|
||||
|
Loading…
Reference in New Issue
Block a user