mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
ST: Support thread-local for multiple threads.
1. All statick and global variables is thread-local. 2. Call st_init() to init st for each thread. 3. Notice that ST is isolate for threads.
This commit is contained in:
parent
d117145b95
commit
339d3b31cc
8 changed files with 61 additions and 54 deletions
50
trunk/3rdparty/st-srs/sched.c
vendored
50
trunk/3rdparty/st-srs/sched.c
vendored
|
@ -56,31 +56,33 @@
|
|||
|
||||
// Global stat.
|
||||
#if defined(DEBUG) && defined(DEBUG_STATS)
|
||||
unsigned long long _st_stat_sched_15ms = 0;
|
||||
unsigned long long _st_stat_sched_20ms = 0;
|
||||
unsigned long long _st_stat_sched_25ms = 0;
|
||||
unsigned long long _st_stat_sched_30ms = 0;
|
||||
unsigned long long _st_stat_sched_35ms = 0;
|
||||
unsigned long long _st_stat_sched_40ms = 0;
|
||||
unsigned long long _st_stat_sched_80ms = 0;
|
||||
unsigned long long _st_stat_sched_160ms = 0;
|
||||
unsigned long long _st_stat_sched_s = 0;
|
||||
__thread unsigned long long _st_stat_sched_15ms = 0;
|
||||
__thread unsigned long long _st_stat_sched_20ms = 0;
|
||||
__thread unsigned long long _st_stat_sched_25ms = 0;
|
||||
__thread unsigned long long _st_stat_sched_30ms = 0;
|
||||
__thread unsigned long long _st_stat_sched_35ms = 0;
|
||||
__thread unsigned long long _st_stat_sched_40ms = 0;
|
||||
__thread unsigned long long _st_stat_sched_80ms = 0;
|
||||
__thread unsigned long long _st_stat_sched_160ms = 0;
|
||||
__thread 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;
|
||||
unsigned long long _st_stat_thread_yield2 = 0;
|
||||
__thread unsigned long long _st_stat_thread_run = 0;
|
||||
__thread unsigned long long _st_stat_thread_idle = 0;
|
||||
__thread unsigned long long _st_stat_thread_yield = 0;
|
||||
__thread unsigned long long _st_stat_thread_yield2 = 0;
|
||||
#endif
|
||||
|
||||
|
||||
/* Global data */
|
||||
_st_vp_t _st_this_vp; /* This VP */
|
||||
_st_thread_t *_st_this_thread; /* Current thread */
|
||||
int _st_active_count = 0; /* Active thread count */
|
||||
__thread _st_vp_t _st_this_vp; /* This VP */
|
||||
__thread _st_thread_t *_st_this_thread; /* Current thread */
|
||||
__thread int _st_active_count = 0; /* Active thread count */
|
||||
|
||||
time_t _st_curr_time = 0; /* Current time as returned by time(2) */
|
||||
st_utime_t _st_last_tset; /* Last time it was fetched */
|
||||
__thread time_t _st_curr_time = 0; /* Current time as returned by time(2) */
|
||||
__thread st_utime_t _st_last_tset; /* Last time it was fetched */
|
||||
|
||||
// We should initialize the thread-local variable in st_init().
|
||||
extern __thread _st_clist_t _st_free_stacks;
|
||||
|
||||
int st_poll(struct pollfd *pds, int npds, st_utime_t timeout)
|
||||
{
|
||||
|
@ -167,7 +169,7 @@ void _st_vp_schedule(void)
|
|||
int st_init(void)
|
||||
{
|
||||
_st_thread_t *thread;
|
||||
|
||||
|
||||
if (_st_active_count) {
|
||||
/* Already initialized */
|
||||
return 0;
|
||||
|
@ -178,7 +180,11 @@ int st_init(void)
|
|||
|
||||
if (_st_io_init() < 0)
|
||||
return -1;
|
||||
|
||||
|
||||
// Initialize the thread-local variables.
|
||||
ST_INIT_CLIST(&_st_free_stacks);
|
||||
|
||||
// Initialize ST.
|
||||
memset(&_st_this_vp, 0, sizeof(_st_vp_t));
|
||||
|
||||
ST_INIT_CLIST(&_ST_RUNQ);
|
||||
|
@ -713,8 +719,8 @@ int _st_iterate_threads_flag = 0;
|
|||
|
||||
void _st_iterate_threads(void)
|
||||
{
|
||||
static _st_thread_t *thread = NULL;
|
||||
static jmp_buf orig_jb, save_jb;
|
||||
static __thread _st_thread_t *thread = NULL;
|
||||
static __thread jmp_buf orig_jb, save_jb;
|
||||
_st_clist_t *q;
|
||||
|
||||
if (!_st_iterate_threads_flag) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue