Skip to content

Commit ca71e74

Browse files
committed
fix(osal/usb_osal_liteos_m): fix task delete when thread is null
Signed-off-by: sakumisu <[email protected]>
1 parent 16858c1 commit ca71e74

File tree

1 file changed

+24
-38
lines changed

1 file changed

+24
-38
lines changed

osal/usb_osal_liteos_m.c

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,59 +15,44 @@
1515
#include "los_memory.h"
1616
#include "los_swtmr.h"
1717

18-
typedef struct _usb_osal_thread {
19-
UINT32 task_id;
20-
char name[128];
21-
} _usb_osal_thread_t;
22-
2318
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)
2419
{
25-
_usb_osal_thread_t *t;
2620
UINT32 task_id;
2721
UINT32 ret;
22+
2823
TSK_INIT_PARAM_S task_init_param = {
2924
.usTaskPrio = prio,
3025
.pfnTaskEntry = (TSK_ENTRY_FUNC)entry,
3126
.uwStackSize = stack_size,
3227
.uwArg = (UINT32)args,
28+
.pcName = name
3329
};
3430

35-
t = usb_osal_malloc(sizeof(_usb_osal_thread_t));
36-
if (t == NULL) {
37-
USB_LOG_ERR("alloc thread %s failed\r\n", name);
38-
while (1) {
39-
}
40-
}
41-
42-
strncpy(t->name, name, sizeof(t->name));
43-
task_init_param.pcName = t->name;
44-
4531
ret = LOS_TaskCreate(&task_id, &task_init_param);
4632
if (ret != LOS_OK) {
4733
USB_LOG_ERR("Create task[%s] failed code[%u]\r\n", name, ret);
4834
while (1) {
4935
}
5036
}
5137

52-
t->task_id = task_id;
53-
54-
return (usb_osal_thread_t)t;
38+
return (usb_osal_thread_t)task_id;
5539
}
5640

5741
void usb_osal_thread_delete(usb_osal_thread_t thread)
5842
{
59-
_usb_osal_thread_t *t = (_usb_osal_thread_t *)thread;
60-
UINT32 task_id = t->task_id;
43+
UINT32 task_id = (UINT32)thread;
6144
UINT32 ret;
6245

46+
if (thread == NULL) {
47+
task_id = LOS_CurTaskIDGet();
48+
}
49+
6350
ret = LOS_TaskDelete(task_id);
6451
if (ret != LOS_OK) {
6552
USB_LOG_ERR("Delete task id[%u] failed code[%u]\r\n", task_id, ret);
6653
while (1) {
6754
}
6855
}
69-
70-
usb_osal_free(t);
7156
}
7257

7358
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
@@ -91,7 +76,7 @@ void usb_osal_sem_delete(usb_osal_sem_t sem)
9176

9277
ret = LOS_SemDelete(sem_handle);
9378
if (ret != LOS_OK) {
94-
USB_LOG_ERR("Delete sem handle[%u] failed code[%u]\r\n",\
79+
USB_LOG_ERR("Delete sem handle[%u] failed code[%u]\r\n",
9580
sem_handle, ret);
9681
while (1) {
9782
}
@@ -103,9 +88,10 @@ int usb_osal_sem_take(usb_osal_sem_t sem, uint32_t timeout)
10388
UINT32 sem_handle = (UINT32)sem;
10489
UINT32 ret;
10590

106-
ret = LOS_SemPend(sem_handle, \
107-
timeout == USB_OSAL_WAITING_FOREVER ? \
108-
LOS_WAIT_FOREVER : timeout);
91+
ret = LOS_SemPend(sem_handle,
92+
timeout == USB_OSAL_WAITING_FOREVER ?
93+
LOS_WAIT_FOREVER :
94+
timeout);
10995

11096
return ret == LOS_OK ? 0 : -USB_ERR_TIMEOUT;
11197
}
@@ -122,7 +108,6 @@ int usb_osal_sem_give(usb_osal_sem_t sem)
122108

123109
void usb_osal_sem_reset(usb_osal_sem_t sem)
124110
{
125-
126111
}
127112

128113
usb_osal_mutex_t usb_osal_mutex_create(void)
@@ -146,8 +131,8 @@ void usb_osal_mutex_delete(usb_osal_mutex_t mutex)
146131

147132
ret = LOS_MuxDelete(mux_handle);
148133
if (ret != LOS_OK) {
149-
USB_LOG_ERR("Delete mux handle[%u] failed code[%u]\r\n",\
150-
mux_handle, ret);
134+
USB_LOG_ERR("Delete mux handle[%u] failed code[%u]\r\n",
135+
mux_handle, ret);
151136
while (1) {
152137
}
153138
}
@@ -194,7 +179,7 @@ void usb_osal_mq_delete(usb_osal_mq_t mq)
194179

195180
ret = LOS_QueueDelete(queue_id);
196181
if (ret != LOS_OK) {
197-
USB_LOG_ERR("Delete queue id[%u] failed code[%u]\r\n",\
182+
USB_LOG_ERR("Delete queue id[%u] failed code[%u]\r\n",
198183
queue_id, ret);
199184
while (1) {
200185
}
@@ -247,12 +232,13 @@ struct usb_osal_timer *usb_osal_timer_create(const char *name, uint32_t timeout_
247232
memset(timer_handle, 0x00, sizeof(struct usb_osal_timer));
248233

249234
ret = LOS_SwtmrCreate(timeout_ms,
250-
is_period ? LOS_SWTMR_MODE_PERIOD : LOS_SWTMR_MODE_NO_SELFDELETE,
251-
(SWTMR_PROC_FUNC)handler, &timer_id, (UINT32)argument
235+
is_period ? LOS_SWTMR_MODE_PERIOD : LOS_SWTMR_MODE_NO_SELFDELETE,
236+
(SWTMR_PROC_FUNC)handler, &timer_id, (UINT32)argument
252237
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
253-
,OS_SWTMR_ROUSES_IGNORE, OS_SWTMR_ALIGN_INSENSITIVE
238+
,
239+
OS_SWTMR_ROUSES_IGNORE, OS_SWTMR_ALIGN_INSENSITIVE
254240
#endif
255-
);
241+
);
256242

257243
if (ret != LOS_OK) {
258244
USB_LOG_ERR("Create software timer failed code[%u]\r\n", ret);
@@ -276,7 +262,7 @@ void usb_osal_timer_delete(struct usb_osal_timer *timer)
276262

277263
ret = LOS_SwtmrDelete(timer_id);
278264
if (ret != LOS_OK) {
279-
USB_LOG_ERR("Delete software timer id[%u] failed code[%u]\r\n",\
265+
USB_LOG_ERR("Delete software timer id[%u] failed code[%u]\r\n",
280266
timer_id, ret);
281267
while (1) {
282268
}
@@ -291,7 +277,7 @@ void usb_osal_timer_start(struct usb_osal_timer *timer)
291277

292278
ret = LOS_SwtmrStart(timer_id);
293279
if (ret != LOS_OK) {
294-
USB_LOG_ERR("Start software timer id[%u] failed code[%u]\r\n",\
280+
USB_LOG_ERR("Start software timer id[%u] failed code[%u]\r\n",
295281
timer_id, ret);
296282
while (1) {
297283
}
@@ -305,7 +291,7 @@ void usb_osal_timer_stop(struct usb_osal_timer *timer)
305291

306292
ret = LOS_SwtmrStop(timer_id);
307293
if (ret != LOS_OK) {
308-
USB_LOG_ERR("Stop software timer id[%u] failed code[%u]\r\n",\
294+
USB_LOG_ERR("Stop software timer id[%u] failed code[%u]\r\n",
309295
timer_id, ret);
310296
while (1) {
311297
}

0 commit comments

Comments
 (0)