Skip to content

Fix serial putchar newline deadlock#306

Merged
Ivan-Velickovic merged 1 commit intomainfrom
fix_putchar_newline_deadlock
Jan 30, 2025
Merged

Fix serial putchar newline deadlock#306
Ivan-Velickovic merged 1 commit intomainfrom
fix_putchar_newline_deadlock

Conversation

@Courtney3141
Copy link
Contributor

@Courtney3141 Courtney3141 commented Jan 13, 2025

While making recent changes to the serial subsystem, I notice a potential deadlock in the _sddf_putchar function.

Prior to this PR, the function only signals the TX_CH if the queue is full after inserting a character, or if the character inserted was the FLUSH_CHAR. However, the function only actually inserts a character into the queue if it is not full, or in the case of a \n character, the queue has space for 2 characters.

This means that if the queue only has space for one character, and a \n is attempted to be inserted, the function will immediately return without signalling, and there is no guarantee the function signalled on its previous invocation. This is a potential deadlock, as the virtualiser has potentially not yet been signalled for the remaining characters in the queue, and the system is dependent on the client enqueuing another non \n character for a signal to occur.

This PR fixes this deadlock situation by signalling if either the queue is full, the flush character is seen, or if the queue is one from full, which eliminates the scenario that a signal is missed. It also stops any characters from being enqueued if the queue is 1 from full, to prevent against accidental double signals which would interfere with the multiplexing.

Merge after #305.

@Courtney3141 Courtney3141 force-pushed the fix_putchar_newline_deadlock branch from 5a65364 to d6908c5 Compare January 13, 2025 04:43
@JE-Archer JE-Archer changed the base branch from main to serial_producer_signal_unconditional January 14, 2025 07:14
@Courtney3141 Courtney3141 force-pushed the serial_producer_signal_unconditional branch 2 times, most recently from 079bbdc to 23a7090 Compare January 15, 2025 07:17
@Courtney3141 Courtney3141 force-pushed the fix_putchar_newline_deadlock branch from d6908c5 to b716a8c Compare January 15, 2025 07:24
@Courtney3141 Courtney3141 force-pushed the serial_producer_signal_unconditional branch from 23a7090 to 0df8f55 Compare January 15, 2025 07:26
@Courtney3141 Courtney3141 force-pushed the fix_putchar_newline_deadlock branch from b716a8c to ac14b64 Compare January 15, 2025 07:27
@Courtney3141 Courtney3141 force-pushed the serial_producer_signal_unconditional branch from 0df8f55 to ea468fb Compare January 17, 2025 07:02
@Courtney3141 Courtney3141 force-pushed the fix_putchar_newline_deadlock branch from ac14b64 to 50d849a Compare January 17, 2025 07:03
@Ivan-Velickovic Ivan-Velickovic force-pushed the serial_producer_signal_unconditional branch from ea468fb to 42d5e9a Compare January 30, 2025 06:04
Base automatically changed from serial_producer_signal_unconditional to main January 30, 2025 06:07
Signed-off-by: Courtney Darville <courtneydarville94@outlook.com>
@Ivan-Velickovic Ivan-Velickovic force-pushed the fix_putchar_newline_deadlock branch from 50d849a to dbc195d Compare January 30, 2025 06:07
@Ivan-Velickovic Ivan-Velickovic merged commit 367d423 into main Jan 30, 2025
7 checks passed
@Ivan-Velickovic Ivan-Velickovic deleted the fix_putchar_newline_deadlock branch January 30, 2025 06:09
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

Successfully merging this pull request may close these issues.

2 participants

Comments