diff options
| author | SunJ <[email protected]> | 2026-01-13 17:31:29 +0800 |
|---|---|---|
| committer | sakumisu <[email protected]> | 2026-01-13 17:43:29 +0800 |
| commit | 1de6b930458dec7bede07b02773d06bb3d5e5555 (patch) | |
| tree | 325a5247b1b47c8e8c2c9a7fde74950a58c053de | |
| parent | 43cf82642c730c7a66f207199b9db7eadcd385e1 (diff) | |
refactor(osal): replace NuttX internal APIs with POSIX APIs
Replace nxsched_self() and nxsched_set_priority() with
standard POSIX sched_getparam() and sched_setparam() in
usb_osal_thread_schedule_other().
This improves portability and follows POSIX standards for
thread priority management.
Change-Id: I2e637268f77e200fbdee3e7713cba1b115976696
Signed-off-by: SunJ <[email protected]>
| -rw-r--r-- | osal/usb_osal_nuttx.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/osal/usb_osal_nuttx.c b/osal/usb_osal_nuttx.c index 49911573..1a44fb48 100644 --- a/osal/usb_osal_nuttx.c +++ b/osal/usb_osal_nuttx.c @@ -65,14 +65,23 @@ void usb_osal_thread_delete(usb_osal_thread_t thread) void usb_osal_thread_schedule_other(void) { - struct tcb_s *tcb = nxsched_self(); - const int old_priority = tcb->sched_priority; + struct sched_param param; + int old_priority; - nxsched_set_priority(tcb, SCHED_PRIORITY_MIN); + /* Get current priority (pid=0 means current task) */ + assert(sched_getparam(0, ¶m) == 0); + old_priority = param.sched_priority; + /* Set to minimum priority to yield CPU to other tasks */ + param.sched_priority = SCHED_PRIORITY_MIN; + assert(sched_setparam(0, ¶m) == 0); + + /* Yield CPU to other tasks */ sched_yield(); - nxsched_set_priority(tcb, old_priority); + /* Restore original priority */ + param.sched_priority = old_priority; + assert(sched_setparam(0, ¶m) == 0); } usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count) |
