From 2acf61d901a173fa5401cfb8c0e2ed87059cf489 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 22 Aug 2024 11:32:12 +0800 Subject: [PATCH] ST: Refine switch context. --- trunk/3rdparty/st-srs/common.c | 18 --------- trunk/3rdparty/st-srs/common.h | 70 ++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 46 deletions(-) diff --git a/trunk/3rdparty/st-srs/common.c b/trunk/3rdparty/st-srs/common.c index 5184440d232..1b71b17552c 100644 --- a/trunk/3rdparty/st-srs/common.c +++ b/trunk/3rdparty/st-srs/common.c @@ -3,21 +3,3 @@ #include "common.h" -void _st_switch_context(_st_thread_t *thread) -{ - ST_SWITCH_OUT_CB(thread); - - if (!_st_md_cxt_save(thread->context)) { - _st_vp_schedule(); - } - - ST_DEBUG_ITERATE_THREADS(); - ST_SWITCH_IN_CB(thread); -} - -void _st_restore_context(_st_thread_t *thread) -{ - _st_this_thread = thread; - _st_md_cxt_restore(thread->context, 1); -} - diff --git a/trunk/3rdparty/st-srs/common.h b/trunk/3rdparty/st-srs/common.h index 1d497ba3165..b915c265fe0 100644 --- a/trunk/3rdparty/st-srs/common.h +++ b/trunk/3rdparty/st-srs/common.h @@ -310,6 +310,32 @@ extern __thread _st_eventsys_t *_st_eventsys; #endif +/***************************************** + * Forward declarations + */ + +void _st_vp_schedule(void); +void _st_vp_check_clock(void); +void *_st_idle_thread_start(void *arg); +void _st_thread_main(void); +void _st_thread_cleanup(_st_thread_t *thread); +void _st_add_sleep_q(_st_thread_t *thread, st_utime_t timeout); +void _st_del_sleep_q(_st_thread_t *thread); +_st_stack_t *_st_stack_new(int stack_size); +void _st_stack_free(_st_stack_t *ts); +int _st_io_init(void); + +st_utime_t st_utime(void); +_st_cond_t *st_cond_new(void); +int st_cond_destroy(_st_cond_t *cvar); +int st_cond_timedwait(_st_cond_t *cvar, st_utime_t timeout); +int st_cond_signal(_st_cond_t *cvar); +ssize_t st_read(_st_netfd_t *fd, void *buf, size_t nbyte, st_utime_t timeout); +ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte, st_utime_t timeout); +int st_poll(struct pollfd *pds, int npds, st_utime_t timeout); +_st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg, int joinable, int stk_size); + + /***************************************** * Threads context switching */ @@ -343,45 +369,33 @@ extern __thread _st_eventsys_t *_st_eventsys; * Switch away from the current thread context by saving its state and * calling the thread scheduler */ -void _st_switch_context(_st_thread_t *thread); +static inline void _st_switch_context(_st_thread_t *thread) +{ + ST_SWITCH_OUT_CB(thread); + + if (!_st_md_cxt_save(thread->context)) { + _st_vp_schedule(); + } + + ST_DEBUG_ITERATE_THREADS(); + ST_SWITCH_IN_CB(thread); +} /* * Restore a thread context that was saved by _st_switch_context or * initialized by _ST_INIT_CONTEXT */ -void _st_restore_context(_st_thread_t *thread); +static inline void _st_restore_context(_st_thread_t *thread); +{ + _st_this_thread = thread; + _st_md_cxt_restore(thread->context, 1); +} /* * Number of bytes reserved under the stack "bottom" */ #define _ST_STACK_PAD_SIZE 128 - -/***************************************** - * Forward declarations - */ - -void _st_vp_schedule(void); -void _st_vp_check_clock(void); -void *_st_idle_thread_start(void *arg); -void _st_thread_main(void); -void _st_thread_cleanup(_st_thread_t *thread); -void _st_add_sleep_q(_st_thread_t *thread, st_utime_t timeout); -void _st_del_sleep_q(_st_thread_t *thread); -_st_stack_t *_st_stack_new(int stack_size); -void _st_stack_free(_st_stack_t *ts); -int _st_io_init(void); - -st_utime_t st_utime(void); -_st_cond_t *st_cond_new(void); -int st_cond_destroy(_st_cond_t *cvar); -int st_cond_timedwait(_st_cond_t *cvar, st_utime_t timeout); -int st_cond_signal(_st_cond_t *cvar); -ssize_t st_read(_st_netfd_t *fd, void *buf, size_t nbyte, st_utime_t timeout); -ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte, st_utime_t timeout); -int st_poll(struct pollfd *pds, int npds, st_utime_t timeout); -_st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg, int joinable, int stk_size); - #ifdef __cplusplus } /* extern "C" */ #endif