some renaming
This commit is contained in:
parent
3365b9eed7
commit
02ed253b88
3 changed files with 36 additions and 39 deletions
|
@ -1,10 +1,7 @@
|
||||||
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
|
#include "j_esp32_queue.h"
|
||||||
|
|
||||||
#if defined(_POSIX_THREADS)
|
/*void queue_init(queue_t *q, uint element_size, uint element_count) {
|
||||||
#include "esp32_queue.h"
|
|
||||||
|
|
||||||
#include "Arduino.h"
|
|
||||||
|
|
||||||
void queue_init(queue_t *q, uint element_size, uint element_count) {
|
|
||||||
mutex_init(&q->core);
|
mutex_init(&q->core);
|
||||||
q->cond = PTHREAD_COND_INITIALIZER;
|
q->cond = PTHREAD_COND_INITIALIZER;
|
||||||
q->data = (uint8_t *)calloc(element_count + 1, element_size);
|
q->data = (uint8_t *)calloc(element_count + 1, element_size);
|
||||||
|
@ -12,24 +9,10 @@ void queue_init(queue_t *q, uint element_size, uint element_count) {
|
||||||
q->element_size = (uint16_t)element_size;
|
q->element_size = (uint16_t)element_size;
|
||||||
q->wptr = 0;
|
q->wptr = 0;
|
||||||
q->rptr = 0;
|
q->rptr = 0;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void queue_free(queue_t *q) { free(q->data); }
|
void queue_free(queue_t *q) { free(q->data); }
|
||||||
|
|
||||||
static inline uint queue_get_level_unsafe(queue_t *q) {
|
|
||||||
int32_t rc = (int32_t)q->wptr - (int32_t)q->rptr;
|
|
||||||
if (rc < 0) {
|
|
||||||
rc += q->element_count + 1;
|
|
||||||
}
|
|
||||||
return (uint)rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint queue_get_level(queue_t *q) {
|
|
||||||
mutex_enter_blocking(&q->core);
|
|
||||||
uint level = queue_get_level_unsafe(q);
|
|
||||||
mutex_exit(&q->core);
|
|
||||||
return level;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void *element_ptr(queue_t *q, uint index) {
|
static inline void *element_ptr(queue_t *q, uint index) {
|
||||||
assert(index <= q->element_count);
|
assert(index <= q->element_count);
|
||||||
|
@ -131,4 +114,5 @@ void queue_remove_blocking(queue_t *q, void *data) {
|
||||||
void queue_peek_blocking(queue_t *q, void *data) {
|
void queue_peek_blocking(queue_t *q, void *data) {
|
||||||
queue_peek_internal(q, data, true);
|
queue_peek_internal(q, data, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,7 +1,7 @@
|
||||||
#if defined(_POSIX_THREADS)
|
// #if defined(ARDUINO_ARCH_ESP32)
|
||||||
|
|
||||||
#ifndef ESP32_QUEUE_H
|
#ifndef J_ESP32_QUEUE_H
|
||||||
#define ESP32_QUEUE_H
|
#define J_ESP32_QUEUE_H
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
||||||
|
@ -11,7 +11,8 @@
|
||||||
* Modified to run on an esp32.
|
* Modified to run on an esp32.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../jmutex.h"
|
#include <jmutex.h>
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "pthread.h"
|
#include "pthread.h"
|
||||||
|
|
||||||
|
@ -19,10 +20,6 @@
|
||||||
#define PICO_QUEUE_MAX_LEVEL 0
|
#define PICO_QUEUE_MAX_LEVEL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
mutex_t core;
|
mutex_t core;
|
||||||
pthread_cond_t cond;
|
pthread_cond_t cond;
|
||||||
|
@ -44,7 +41,15 @@ typedef struct {
|
||||||
* \param element_count Maximum number of entries in the queue
|
* \param element_count Maximum number of entries in the queue
|
||||||
*/
|
*/
|
||||||
static inline void queue_init(queue_t *q, uint element_size,
|
static inline void queue_init(queue_t *q, uint element_size,
|
||||||
uint element_count);
|
uint element_count) {
|
||||||
|
mutex_init(&q->core);
|
||||||
|
q->cond = PTHREAD_COND_INITIALIZER;
|
||||||
|
q->data = (uint8_t *)calloc(element_count + 1, element_size);
|
||||||
|
q->element_count = (uint16_t)element_count;
|
||||||
|
q->element_size = (uint16_t)element_size;
|
||||||
|
q->wptr = 0;
|
||||||
|
q->rptr = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*! \brief Destroy the specified queue.
|
/*! \brief Destroy the specified queue.
|
||||||
* \ingroup queue
|
* \ingroup queue
|
||||||
|
@ -64,7 +69,14 @@ void queue_free(queue_t *q);
|
||||||
* This does not use the mutex, so may return incorrect results if the
|
* This does not use the mutex, so may return incorrect results if the
|
||||||
* mutex is not externally locked
|
* mutex is not externally locked
|
||||||
*/
|
*/
|
||||||
static inline uint queue_get_level_unsafe(queue_t *q);
|
static inline uint queue_get_level_unsafe(queue_t *q) {
|
||||||
|
int32_t rc = (int32_t)q->wptr - (int32_t)q->rptr;
|
||||||
|
if (rc < 0) {
|
||||||
|
rc += q->element_count + 1;
|
||||||
|
}
|
||||||
|
return (uint)rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! \brief Check of level of the specified queue.
|
/*! \brief Check of level of the specified queue.
|
||||||
* \ingroup queue
|
* \ingroup queue
|
||||||
|
@ -72,7 +84,12 @@ static inline uint queue_get_level_unsafe(queue_t *q);
|
||||||
* \param q Pointer to a queue_t structure, used as a handle
|
* \param q Pointer to a queue_t structure, used as a handle
|
||||||
* \return Number of entries in the queue
|
* \return Number of entries in the queue
|
||||||
*/
|
*/
|
||||||
static inline uint queue_get_level(queue_t *q);
|
static inline uint queue_get_level(queue_t *q) {
|
||||||
|
mutex_enter_blocking(&q->core);
|
||||||
|
uint level = queue_get_level_unsafe(q);
|
||||||
|
mutex_exit(&q->core);
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
#if PICO_QUEUE_MAX_LEVEL
|
#if PICO_QUEUE_MAX_LEVEL
|
||||||
/*! \brief Returns the highest level reached by the specified queue since it was
|
/*! \brief Returns the highest level reached by the specified queue since it was
|
||||||
|
@ -195,10 +212,6 @@ void queue_remove_blocking(queue_t *q, void *data);
|
||||||
*/
|
*/
|
||||||
void queue_peek_blocking(queue_t *q, void *data);
|
void queue_peek_blocking(queue_t *q, void *data);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
// #endif
|
||||||
#endif
|
|
||||||
#endif
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
|
||||||
#include "esp32/esp32_queue.h"
|
#include "j_esp32/j_esp32_queue.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
Loading…
Reference in a new issue