Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugg or not using it correctly?? #4

Open
lgLindstrom opened this issue Nov 14, 2022 · 1 comment
Open

Bugg or not using it correctly?? #4

lgLindstrom opened this issue Nov 14, 2022 · 1 comment

Comments

@lgLindstrom
Copy link

Hi (again)

I am using your DynamicQueue_t class. Testing it in a separate environment ( no wifi, mqtt etc) it works correctly,

Using DynamicQueue_t in a more complex environment I have some problems. I dont know if it a bug in the class or if I am using it in the wring way.

This setup is like this.

Generator task generates mqtt messages that are pushed into the queue. I have removed how payload is generated but basically a counter is updated by 1 every loop. This seems to be working fine according to the log output.

static void GeneratorTask (void *data) {
            vTaskDelay(10 / portTICK_RATE_MS);
            int i=0;
            while(true){        
                while (! queue->full()) {
                    queue->send<mqtt_message_t>(mqtt_message_t {"testCounter",  <payload> } );
                    ESP_LOGW(TAG, "%s:%d topic: %s  payload: %s ",  __func__, __LINE__ , "testCounder", payload.c_str());
                    i++;
                    vTaskDelay(10 / portTICK_RATE_MS);
                };
            }

Then I have a publisher task reading the queu and publishing data to the Mqtt broker (raspberry pi) using ESP-MQTT client.

static void publishTask(void * bas) {
        mqtt_message_t message;
        while(true){
            vTaskDelay(10 / portTICK_RATE_MS);
            
         while ( ! queue->empty()  ) {
                esp_err_t result = queue->receive<mqtt_message_t>(message);
                if (ESP_OK == result) {
                    ESP_LOGI(TAG, "%s:%d Publishing message, topic: %s, payload: %s", __func__, __LINE__,topic.c_str(), payload.c_str());
                    mqtt->publish(topic, payload ) ;
                } else {
                    ESP_LOGE(TAG,"Error in queue" );
                }
                
              vTaskDelay(1000 / portTICK_RATE_MS);   //// DELAY 
            };   
        }
    };

Running this with wifi and mqtt the same message is published multiple times dependent on the line marked ///DELAY.

For me it looks like the line: !queue->empty not is updated directly when reading the queue. ??? Depending on what is happening in rest of the application it is updated or not.....

The queue supposed to work so ???
If so,, how do you use it in the best way....

@howroyd
Copy link
Owner

howroyd commented Dec 5, 2024

For some reason I didn't get a notification for this issue. My apologies.

Did you find the answer?

My gut feeling is that this return should be volatile as it can be effected by multiple cores. Then, followed forward, I would make the empty() call also return a volatile:

[[nodiscard]] size_t n_items_waiting(void) const

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants