-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Allow the command queue to be cleared by commands, lcd menus #4214
Merged
thinkyhead
merged 2 commits into
MarlinFirmware:RCBugFix
from
thinkyhead:fix_clear_command_queue
Jul 5, 2016
+9
−6
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not volatile?
loop()
might loadcommands_in_queue
into a register. When callingprocess_next_command()
this register might be saved to the stack.process_next_command()
might try to store a move in the planner. If the planner buffer is full it callsidle()
, callingmanage_inactivity()
, callingget_available_commands()
. That may add a a new command into the buffer -commands_in_queue
is increased in memory. All called functions may return - the registers restored andloop()
may have a wrong value forcommands_in_queue
now, what is decreased and stored back to memory.There are so many ways you can reach idle().
A static volatile uint8_t at least can not hurt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are damn fast.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that the compiler is smart enough not to presume that variables that you use within a function are "non-volatile" when calling a function in a separate execution unit. The compiler understands that any variable passed as public to the linker might be altered in the other execution unit. If the compiler didn't take this sort of thing into account, we would have to declare most variables as
volatile
.In other words, the compiler should never try to optimize the second test of the value here…
…because the interceding function calls are free to alter it.
I believe the intended use of
volatile
is when an interrupt might alter it outside the normal execution flow. Not that it might be altered by some function that you call from within the main thread.But I will look further into when it is recommended for use!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure enough, the variable (
0x04A5
) is treated as if it werevolatile
in theloop()
function…See that immediately after
process_next_command()
is called,commands_in_queue
is reloaded from RAM:lds r24, 0x04A5
. So the compiler is smartly not assuming it was unaltered.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If after the above happened and the buffer is filled up to
BUFSIZE-1
commands - one will become written over. However - the host will not see enough 'ok's and might stop sending.#4075?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Contrast this with what happens if I remove the call to
process_next_command
… Of course it totally optimizes out the second test ofcommands_in_queue
…Insert a meaningless function call in the same execution unit and the compiler still optimizes…
But not if the function we call alters the counter…
…or if the function body exists someplace the compiler can't see…