Skip to content

Commit 0422bb8

Browse files
committed
feat(class): add usb_osal_thread_schedule_other to allow the applications which use the struct usbh_xxx to exit properly before free struct usbh_xxx
Signed-off-by: sakumisu <[email protected]>
1 parent 8cb16bc commit 0422bb8

25 files changed

+111
-0
lines changed

class/audio/usbh_audio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ static int usbh_audio_ctrl_disconnect(struct usbh_hubport *hport, uint8_t intf)
594594
}
595595

596596
if (hport->config.intf[intf].devname[0] != '\0') {
597+
usb_osal_thread_schedule_other();
597598
USB_LOG_INFO("Unregister Audio Class:%s\r\n", hport->config.intf[intf].devname);
598599
usbh_audio_stop(audio_class);
599600
}

class/cdc/usbh_cdc_acm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ static int usbh_cdc_acm_disconnect(struct usbh_hubport *hport, uint8_t intf)
193193
#endif
194194

195195
if (hport->config.intf[intf].devname[0] != '\0') {
196+
usb_osal_thread_schedule_other();
196197
USB_LOG_INFO("Unregister CDC ACM Class:%s\r\n", hport->config.intf[intf].devname);
197198
usbh_cdc_acm_stop(cdc_acm_class);
198199
}

class/cdc/usbh_cdc_ecm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ static int usbh_cdc_ecm_disconnect(struct usbh_hubport *hport, uint8_t intf)
221221
}
222222

223223
if (hport->config.intf[intf].devname[0] != '\0') {
224+
usb_osal_thread_schedule_other();
224225
USB_LOG_INFO("Unregister CDC ECM Class:%s\r\n", hport->config.intf[intf].devname);
225226
usbh_cdc_ecm_stop(cdc_ecm_class);
226227
}

class/cdc/usbh_cdc_ncm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ static int usbh_cdc_ncm_disconnect(struct usbh_hubport *hport, uint8_t intf)
239239
}
240240

241241
if (hport->config.intf[intf].devname[0] != '\0') {
242+
usb_osal_thread_schedule_other();
242243
USB_LOG_INFO("Unregister CDC NCM Class:%s\r\n", hport->config.intf[intf].devname);
243244
usbh_cdc_ncm_stop(cdc_ncm_class);
244245
}

class/hid/usbh_hid.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ int usbh_hid_disconnect(struct usbh_hubport *hport, uint8_t intf)
299299
}
300300

301301
if (hport->config.intf[intf].devname[0] != '\0') {
302+
usb_osal_thread_schedule_other();
302303
USB_LOG_INFO("Unregister HID Class:%s\r\n", hport->config.intf[intf].devname);
303304
usbh_hid_stop(hid_class);
304305
}

class/msc/usbh_msc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ static int usbh_msc_disconnect(struct usbh_hubport *hport, uint8_t intf)
342342
}
343343

344344
if (hport->config.intf[intf].devname[0] != '\0') {
345+
usb_osal_thread_schedule_other();
345346
USB_LOG_INFO("Unregister MSC Class:%s\r\n", hport->config.intf[intf].devname);
346347
usbh_msc_stop(msc_class);
347348
}

class/vendor/net/usbh_asix.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ static int usbh_asix_disconnect(struct usbh_hubport *hport, uint8_t intf)
638638
}
639639

640640
if (hport->config.intf[intf].devname[0] != '\0') {
641+
usb_osal_thread_schedule_other();
641642
USB_LOG_INFO("Unregister ASIX Class:%s\r\n", hport->config.intf[intf].devname);
642643
usbh_asix_stop(asix_class);
643644
}

class/vendor/net/usbh_rtl8152.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,6 +2121,7 @@ static int usbh_rtl8152_disconnect(struct usbh_hubport *hport, uint8_t intf)
21212121
}
21222122

21232123
if (hport->config.intf[intf].devname[0] != '\0') {
2124+
usb_osal_thread_schedule_other();
21242125
USB_LOG_INFO("Unregister rtl8152 Class:%s\r\n", hport->config.intf[intf].devname);
21252126
usbh_rtl8152_stop(rtl8152_class);
21262127
}

class/vendor/serial/usbh_ch34x.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ static int usbh_ch34x_disconnect(struct usbh_hubport *hport, uint8_t intf)
311311
}
312312

313313
if (hport->config.intf[intf].devname[0] != '\0') {
314+
usb_osal_thread_schedule_other();
314315
USB_LOG_INFO("Unregister CH34X Class:%s\r\n", hport->config.intf[intf].devname);
315316
usbh_ch34x_stop(ch34x_class);
316317
}

class/vendor/serial/usbh_cp210x.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ static int usbh_cp210x_disconnect(struct usbh_hubport *hport, uint8_t intf)
260260
}
261261

262262
if (hport->config.intf[intf].devname[0] != '\0') {
263+
usb_osal_thread_schedule_other();
263264
USB_LOG_INFO("Unregister CP210X Class:%s\r\n", hport->config.intf[intf].devname);
264265
usbh_cp210x_stop(cp210x_class);
265266
}

class/vendor/serial/usbh_ftdi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ static int usbh_ftdi_disconnect(struct usbh_hubport *hport, uint8_t intf)
440440
}
441441

442442
if (hport->config.intf[intf].devname[0] != '\0') {
443+
usb_osal_thread_schedule_other();
443444
USB_LOG_INFO("Unregister FTDI Class:%s\r\n", hport->config.intf[intf].devname);
444445
usbh_ftdi_stop(ftdi_class);
445446
}

class/vendor/serial/usbh_pl2303.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ static int usbh_pl2303_disconnect(struct usbh_hubport *hport, uint8_t intf)
375375
}
376376

377377
if (hport->config.intf[intf].devname[0] != '\0') {
378+
usb_osal_thread_schedule_other();
378379
USB_LOG_INFO("Unregister PL2303 Class:%s\r\n", hport->config.intf[intf].devname);
379380
usbh_pl2303_stop(pl2303_class);
380381
}

class/vendor/wifi/usbh_bl616.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ static int usbh_bl616_disconnect(struct usbh_hubport *hport, uint8_t intf)
337337
}
338338

339339
if (hport->config.intf[intf].devname[0] != '\0') {
340+
usb_osal_thread_schedule_other();
340341
USB_LOG_INFO("Unregister BL616 WIFI Class:%s\r\n", hport->config.intf[intf].devname);
341342
usbh_bl616_stop(bl616_class);
342343
}

class/vendor/xbox/usbh_xbox.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ int usbh_xbox_disconnect(struct usbh_hubport *hport, uint8_t intf)
8686
}
8787

8888
if (hport->config.intf[intf].devname[0] != '\0') {
89+
usb_osal_thread_schedule_other();
8990
USB_LOG_INFO("Unregister XBOX Class:%s\r\n", hport->config.intf[intf].devname);
9091
usbh_xbox_stop(xbox_class);
9192
}

class/video/usbh_video.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ static int usbh_video_ctrl_disconnect(struct usbh_hubport *hport, uint8_t intf)
483483
}
484484

485485
if (hport->config.intf[intf].devname[0] != '\0') {
486+
usb_osal_thread_schedule_other();
486487
USB_LOG_INFO("Unregister Video Class:%s\r\n", hport->config.intf[intf].devname);
487488
usbh_video_stop(video_class);
488489
}

class/wireless/usbh_bluetooth.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ static int usbh_bluetooth_disconnect(struct usbh_hubport *hport, uint8_t intf)
134134
// }
135135
#endif
136136
if (hport->config.intf[intf].devname[0] != '\0') {
137+
usb_osal_thread_schedule_other();
137138
USB_LOG_INFO("Unregister Bluetooth Class:%s\r\n", hport->config.intf[intf].devname);
138139
usbh_bluetooth_stop(bluetooth_class);
139140
}

class/wireless/usbh_rndis.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ static int usbh_rndis_disconnect(struct usbh_hubport *hport, uint8_t intf)
438438
// }
439439

440440
if (hport->config.intf[intf].devname[0] != '\0') {
441+
usb_osal_thread_schedule_other();
441442
USB_LOG_INFO("Unregister RNDIS Class:%s\r\n", hport->config.intf[intf].devname);
442443
usbh_rndis_stop(rndis_class);
443444
}

common/usb_osal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct usb_osal_timer {
4242
*/
4343
usb_osal_thread_t usb_osal_thread_create(const char *name, uint32_t stack_size, uint32_t prio, usb_thread_entry_t entry, void *args);
4444
void usb_osal_thread_delete(usb_osal_thread_t thread);
45+
void usb_osal_thread_schedule_other(void);
4546

4647
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count);
4748
void usb_osal_sem_delete(usb_osal_sem_t sem);

osal/idf/usb_osal_idf.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ void usb_osal_thread_delete(usb_osal_thread_t thread)
2525
vTaskDelete(thread);
2626
}
2727

28+
void usb_osal_thread_schedule_other(void)
29+
{
30+
TaskHandle_t xCurrentTask = xTaskGetCurrentTaskHandle();
31+
const UBaseType_t old_priority = uxTaskPriorityGet(xCurrentTask);
32+
33+
vTaskPrioritySet(xCurrentTask, tskIDLE_PRIORITY);
34+
35+
taskYIELD();
36+
37+
vTaskPrioritySet(xCurrentTask, old_priority);
38+
}
39+
2840
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
2941
{
3042
return (usb_osal_sem_t)xSemaphoreCreateCounting(1, initial_count);

osal/usb_osal_freertos.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ void usb_osal_thread_delete(usb_osal_thread_t thread)
3030
vTaskDelete(thread);
3131
}
3232

33+
void usb_osal_thread_schedule_other(void)
34+
{
35+
TaskHandle_t xCurrentTask = xTaskGetCurrentTaskHandle();
36+
const UBaseType_t old_priority = uxTaskPriorityGet(xCurrentTask);
37+
38+
vTaskPrioritySet(xCurrentTask, tskIDLE_PRIORITY);
39+
40+
taskYIELD();
41+
42+
vTaskPrioritySet(xCurrentTask, old_priority);
43+
}
44+
3345
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
3446
{
3547
usb_osal_sem_t sem = (usb_osal_sem_t)xSemaphoreCreateCounting(1, initial_count);

osal/usb_osal_liteos_m.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ void usb_osal_thread_delete(usb_osal_thread_t thread)
5555
}
5656
}
5757

58+
void usb_osal_thread_schedule_other(void)
59+
{
60+
UINT32 task_id = LOS_CurTaskIDGet();
61+
const UINT16 old_priority = LOS_TaskPriGet(task_id);
62+
63+
LOS_TaskPriSet(task_id, OS_TASK_PRIORITY_LOWEST);
64+
65+
LOS_TaskYield();
66+
67+
LOS_TaskPriSet(task_id, old_priority);
68+
}
69+
5870
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
5971
{
6072
UINT32 sem_handle;

osal/usb_osal_nuttx.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ void usb_osal_thread_delete(usb_osal_thread_t thread)
6363
kthread_delete(pid);
6464
}
6565

66+
void usb_osal_thread_schedule_other(void)
67+
{
68+
struct tcb_s *tcb = nxsched_self();
69+
const int old_priority = tcb->sched_priority;
70+
71+
nxsched_set_priority(tcb, SCHED_PRIORITY_MIN);
72+
73+
sched_yield();
74+
75+
nxsched_set_priority(tcb, old_priority);
76+
}
77+
6678
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
6779
{
6880
int ret;

osal/usb_osal_rtthread.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ void usb_osal_thread_delete(usb_osal_thread_t thread)
3434
rt_thread_delete(thread);
3535
}
3636

37+
void usb_osal_thread_schedule_other(void)
38+
{
39+
rt_thread_t self = rt_thread_self();
40+
rt_uint8_t priority;
41+
#if (RTTHREAD_VERSION >= RT_VERSION_CHECK(5, 0, 0))
42+
const rt_uint8_t old_priority = RT_SCHED_PRIV(self).current_priority;
43+
#else
44+
const rt_uint8_t old_priority = self->current_priority;
45+
#endif
46+
priority = RT_THREAD_PRIORITY_MAX - 1;
47+
rt_thread_control(self, RT_THREAD_CTRL_CHANGE_PRIORITY, (void *)&priority);
48+
49+
rt_thread_yield();
50+
51+
rt_thread_control(self, RT_THREAD_CTRL_CHANGE_PRIORITY, (void *)&old_priority);
52+
}
53+
3754
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
3855
{
3956
usb_osal_sem_t sem = (usb_osal_sem_t)rt_sem_create("usbh_sem", initial_count, RT_IPC_FLAG_FIFO);

osal/usb_osal_threadx.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ void usb_osal_thread_delete(usb_osal_thread_t thread)
6969
tx_byte_release(thread);
7070
}
7171

72+
void usb_osal_thread_schedule_other(void)
73+
{
74+
TX_THREAD *current_thread = tx_thread_identify();
75+
const UINT old_priority = current_thread->tx_thread_priority;
76+
77+
tx_thread_priority_change(current_thread, TX_MAX_PRIORITIES - 1, &old_priority);
78+
79+
tx_thread_relinquish();
80+
81+
tx_thread_priority_change(current_thread, old_priority, &old_priority);
82+
}
83+
7284
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
7385
{
7486
TX_SEMAPHORE *sem_ptr = TX_NULL;

osal/usb_osal_zephyr.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ void usb_osal_thread_delete(usb_osal_thread_t thread)
7474
k_free(thread);
7575
}
7676

77+
void usb_osal_thread_schedule_other(void)
78+
{
79+
#if (KERNELVERSION >= 0x3070000)
80+
struct k_thread *current_thread = k_sched_current_thread_query();
81+
#else
82+
struct k_thread *current_thread = z_current_get();
83+
#endif
84+
const int old_priority = k_thread_priority_get(current_thread);
85+
86+
k_thread_priority_set(current_thread, K_LOWEST_APPLICATION_THREAD_PRIO);
87+
88+
k_yield();
89+
90+
k_thread_priority_set(current_thread, old_priority);
91+
}
92+
7793
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
7894
{
7995
struct k_sem *sem;

0 commit comments

Comments
 (0)