esp-modbus
esp-modbus copied to clipboard
Fix for a deadlock startup problem where "port_serial_task" is suspended and never resumed. (IDFGH-14964)
port_serial_task is started with "enable" set to false. Then in main loop it checked if "enable" was false and called vTaskSuspend. Another task, which called mbc_slave_create_serial and mbc_slave_start, may cause that mb_port_ser_enable is called between checking "enable" flag and vTaskSuspend in port_serial_task. As a result, mb_port_ser_enable calls vTaskResume on a non-suspended task. Then control is given back to port_serial_task, which calls vTaskSuspend and stucks in this state forever.
Fix is replacing vTaskSuspend and vTaskResume with a semaphore based ulTaskNotifyWait and vTaskNotifyGive. Additionally "enable" flag is checked in while loop instead of "if".
@klew,
Thank you for contribution. Looks good for now. I will take a look a bit later to check and apply.