shell: allow commands to suspend shell thread
It was possible to deadlock the shell when command suspended shell's thread and next another thread wanted to print something on the shell. To avoid that shell releases mutex before entering command handler. Due to this change some adapations to shell internal print functions have been applied. This change addresses following usecase: 1. A command handler needs to call a (system) function which communicate results via a callback, and this callback is expected to print these results. The callback is called by the system from another thread. 2. To achieve that, the handler needs to pass `struct shell *` to callbacks, but also some other data specific to callback. Thus, handles allocates some structure will those fields on the stack. 3. The handler schedules this callback to be called. 4. As a reference to stack structure is passed to the callback, the handler can't return immediately (or stack data will go out of scope and will be overwritten). 5. So, the handler blocks waiting for callback to finish. Previously, this scenario led to deadlock when the callback trying or print to shell. With these changes, it just works, as long as main handler and callback serialize there access to the shell structure (i.e. when callback prints, the main handler is blocked waiting for its completion). Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
This commit is contained in:
parent
0604c30a1b
commit
46a02322ec
6 changed files with 143 additions and 80 deletions
|
@ -374,6 +374,7 @@ struct shell_flags {
|
|||
u32_t tx_rdy :1;
|
||||
u32_t mode_delete :1; /*!< Operation mode of backspace key */
|
||||
u32_t history_exit:1; /*!< Request to exit history mode */
|
||||
u32_t cmd_ctx :1; /*!< Shell is executing command */
|
||||
u32_t last_nl :8; /*!< Last received new line character */
|
||||
};
|
||||
|
||||
|
@ -683,7 +684,10 @@ void shell_help(const struct shell *shell);
|
|||
* Pass command line to shell to execute.
|
||||
*
|
||||
* Note: This by no means makes any of the commands a stable interface, so
|
||||
* this function should only be used for debugging/diagnostic.
|
||||
* this function should only be used for debugging/diagnostic.
|
||||
*
|
||||
* This function must not be called from shell command context!
|
||||
|
||||
*
|
||||
* @param[in] shell Pointer to the shell instance. It can be NULL when
|
||||
* the :option:`CONFIG_SHELL_BACKEND_DUMMY` option is
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue