Skip to content

Commit

Permalink
Core: Support yield current coroutine for high performance timer.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 19, 2021
1 parent d856339 commit b4b9776
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions trunk/3rdparty/st-srs/public.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ extern st_thread_t st_thread_self(void);
extern void st_thread_exit(void *retval);
extern int st_thread_join(st_thread_t thread, void **retvalp);
extern void st_thread_interrupt(st_thread_t thread);
extern void st_thread_yield();
extern st_thread_t st_thread_create(void *(*start)(void *arg), void *arg, int joinable, int stack_size);
extern int st_randomize_stacks(int on);
extern int st_set_utime_function(st_utime_t (*func)(void));
Expand Down
26 changes: 26 additions & 0 deletions trunk/3rdparty/st-srs/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ unsigned long long _st_stat_sched_s = 0;

unsigned long long _st_stat_thread_run = 0;
unsigned long long _st_stat_thread_idle = 0;
unsigned long long _st_stat_thread_yield = 0;
#endif


Expand Down Expand Up @@ -554,6 +555,31 @@ void _st_vp_check_clock(void)
}


void st_thread_yield()
{
_st_thread_t *me = _ST_CURRENT_THREAD();

// If not thread in RunQ to yield to, ignore and continue to run.
if (_ST_RUNQ.next == &_ST_RUNQ) {
return;
}

#ifdef DEBUG
++_st_stat_thread_yield;
#endif

/* Check sleep queue for expired threads */
_st_vp_check_clock();

// Append thread to the tail of RunQ, we will back after all threads executed.
me->state = _ST_ST_RUNNABLE;
_ST_ADD_RUNQ(me);

// Yield to other threads in the RunQ.
_ST_SWITCH_CONTEXT(me);
}


void st_thread_interrupt(_st_thread_t *thread)
{
/* If thread is already dead */
Expand Down

0 comments on commit b4b9776

Please sign in to comment.