@@ -562,11 +562,11 @@ static int exec_cmd(const struct shell *sh, size_t argc, const char **argv,
562
562
/* Unlock thread mutex in case command would like to borrow
563
563
* shell context to other thread to avoid mutex deadlock.
564
564
*/
565
- k_mutex_unlock ( & sh -> ctx -> wr_mtx );
565
+ z_shell_unlock ( sh );
566
566
ret_val = sh -> ctx -> active_cmd .handler (sh , argc ,
567
567
(char * * )argv );
568
568
/* Bring back mutex to shell thread. */
569
- k_mutex_lock ( & sh -> ctx -> wr_mtx , K_FOREVER );
569
+ z_shell_lock ( sh );
570
570
z_flag_cmd_ctx_set (sh , false);
571
571
}
572
572
@@ -1217,7 +1217,7 @@ static int instance_init(const struct shell *sh,
1217
1217
history_init (sh );
1218
1218
1219
1219
k_event_init (& sh -> ctx -> signal_event );
1220
- k_mutex_init (& sh -> ctx -> wr_mtx );
1220
+ k_sem_init (& sh -> ctx -> lock_sem , 1 , 1 );
1221
1221
1222
1222
if (IS_ENABLED (CONFIG_SHELL_STATS )) {
1223
1223
sh -> stats -> log_lost_cnt = 0 ;
@@ -1342,7 +1342,7 @@ void shell_thread(void *shell_handle, void *arg_log_backend,
1342
1342
false,
1343
1343
K_FOREVER );
1344
1344
1345
- k_mutex_lock ( & sh -> ctx -> wr_mtx , K_FOREVER );
1345
+ z_shell_lock ( sh );
1346
1346
1347
1347
shell_signal_handle (sh , SHELL_SIGNAL_KILL , kill_handler );
1348
1348
shell_signal_handle (sh , SHELL_SIGNAL_RXRDY , shell_process );
@@ -1355,7 +1355,7 @@ void shell_thread(void *shell_handle, void *arg_log_backend,
1355
1355
sh -> iface -> api -> update (sh -> iface );
1356
1356
}
1357
1357
1358
- k_mutex_unlock ( & sh -> ctx -> wr_mtx );
1358
+ z_shell_unlock ( sh );
1359
1359
}
1360
1360
}
1361
1361
@@ -1420,7 +1420,7 @@ int shell_start(const struct shell *sh)
1420
1420
z_shell_log_backend_enable (sh -> log_backend , (void * )sh , sh -> ctx -> log_level );
1421
1421
}
1422
1422
1423
- if (k_mutex_lock ( & sh -> ctx -> wr_mtx , SHELL_TX_MTX_TIMEOUT ) != 0 ) {
1423
+ if (! z_shell_trylock ( sh , SHELL_TX_MTX_TIMEOUT )) {
1424
1424
return - EBUSY ;
1425
1425
}
1426
1426
@@ -1442,7 +1442,7 @@ int shell_start(const struct shell *sh)
1442
1442
*/
1443
1443
z_shell_backend_rx_buffer_flush (sh );
1444
1444
1445
- k_mutex_unlock ( & sh -> ctx -> wr_mtx );
1445
+ z_shell_unlock ( sh );
1446
1446
1447
1447
return 0 ;
1448
1448
}
@@ -1524,7 +1524,7 @@ void shell_vfprintf(const struct shell *sh, enum shell_vt100_color color,
1524
1524
return ;
1525
1525
}
1526
1526
1527
- if (k_mutex_lock ( & sh -> ctx -> wr_mtx , SHELL_TX_MTX_TIMEOUT ) != 0 ) {
1527
+ if (! z_shell_trylock ( sh , SHELL_TX_MTX_TIMEOUT )) {
1528
1528
return ;
1529
1529
}
1530
1530
@@ -1537,7 +1537,7 @@ void shell_vfprintf(const struct shell *sh, enum shell_vt100_color color,
1537
1537
}
1538
1538
z_transport_buffer_flush (sh );
1539
1539
1540
- k_mutex_unlock ( & sh -> ctx -> wr_mtx );
1540
+ z_shell_unlock ( sh );
1541
1541
}
1542
1542
1543
1543
/* These functions mustn't be used from shell context to avoid deadlock:
@@ -1664,20 +1664,20 @@ int shell_prompt_change(const struct shell *sh, const char *prompt)
1664
1664
1665
1665
size_t prompt_length = z_shell_strlen (prompt );
1666
1666
1667
- if (k_mutex_lock ( & sh -> ctx -> wr_mtx , SHELL_TX_MTX_TIMEOUT ) != 0 ) {
1667
+ if (! z_shell_trylock ( sh , SHELL_TX_MTX_TIMEOUT )) {
1668
1668
return - EBUSY ;
1669
1669
}
1670
1670
1671
1671
if ((prompt_length + 1 > CONFIG_SHELL_PROMPT_BUFF_SIZE ) || (prompt_length == 0 )) {
1672
- k_mutex_unlock ( & sh -> ctx -> wr_mtx );
1672
+ z_shell_unlock ( sh );
1673
1673
return - EINVAL ;
1674
1674
}
1675
1675
1676
1676
strcpy (sh -> ctx -> prompt , prompt );
1677
1677
1678
1678
sh -> ctx -> vt100_ctx .cons .name_len = prompt_length ;
1679
1679
1680
- k_mutex_unlock ( & sh -> ctx -> wr_mtx );
1680
+ z_shell_unlock ( sh );
1681
1681
1682
1682
return 0 ;
1683
1683
#else
@@ -1687,11 +1687,11 @@ int shell_prompt_change(const struct shell *sh, const char *prompt)
1687
1687
1688
1688
void shell_help (const struct shell * sh )
1689
1689
{
1690
- if (k_mutex_lock ( & sh -> ctx -> wr_mtx , SHELL_TX_MTX_TIMEOUT ) != 0 ) {
1690
+ if (! z_shell_trylock ( sh , SHELL_TX_MTX_TIMEOUT )) {
1691
1691
return ;
1692
1692
}
1693
1693
shell_internal_help_print (sh );
1694
- k_mutex_unlock ( & sh -> ctx -> wr_mtx );
1694
+ z_shell_unlock ( sh );
1695
1695
}
1696
1696
1697
1697
int shell_execute_cmd (const struct shell * sh , const char * cmd )
@@ -1722,11 +1722,11 @@ int shell_execute_cmd(const struct shell *sh, const char *cmd)
1722
1722
sh -> ctx -> cmd_buff_len = cmd_len ;
1723
1723
sh -> ctx -> cmd_buff_pos = cmd_len ;
1724
1724
1725
- if (k_mutex_lock ( & sh -> ctx -> wr_mtx , SHELL_TX_MTX_TIMEOUT ) != 0 ) {
1725
+ if (! z_shell_trylock ( sh , SHELL_TX_MTX_TIMEOUT )) {
1726
1726
return - ENOEXEC ;
1727
1727
}
1728
1728
ret_val = execute (sh );
1729
- k_mutex_unlock ( & sh -> ctx -> wr_mtx );
1729
+ z_shell_unlock ( sh );
1730
1730
1731
1731
cmd_buffer_clear (sh );
1732
1732
0 commit comments