mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 03:41:55 +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
6
trunk/3rdparty/st-srs/common.h
vendored
6
trunk/3rdparty/st-srs/common.h
vendored
|
@ -266,9 +266,9 @@ typedef struct _st_netfd {
|
||||||
* Current vp, thread, and event system
|
* Current vp, thread, and event system
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern _st_vp_t _st_this_vp;
|
extern __thread _st_vp_t _st_this_vp;
|
||||||
extern _st_thread_t *_st_this_thread;
|
extern __thread _st_thread_t *_st_this_thread;
|
||||||
extern _st_eventsys_t *_st_eventsys;
|
extern __thread _st_eventsys_t *_st_eventsys;
|
||||||
|
|
||||||
#define _ST_CURRENT_THREAD() (_st_this_thread)
|
#define _ST_CURRENT_THREAD() (_st_this_thread)
|
||||||
#define _ST_SET_CURRENT_THREAD(_thread) (_st_this_thread = (_thread))
|
#define _ST_SET_CURRENT_THREAD(_thread) (_st_this_thread = (_thread))
|
||||||
|
|
14
trunk/3rdparty/st-srs/event.c
vendored
14
trunk/3rdparty/st-srs/event.c
vendored
|
@ -51,10 +51,10 @@
|
||||||
|
|
||||||
// Global stat.
|
// Global stat.
|
||||||
#if defined(DEBUG) && defined(DEBUG_STATS)
|
#if defined(DEBUG) && defined(DEBUG_STATS)
|
||||||
unsigned long long _st_stat_epoll = 0;
|
__thread unsigned long long _st_stat_epoll = 0;
|
||||||
unsigned long long _st_stat_epoll_zero = 0;
|
__thread unsigned long long _st_stat_epoll_zero = 0;
|
||||||
unsigned long long _st_stat_epoll_shake = 0;
|
__thread unsigned long long _st_stat_epoll_shake = 0;
|
||||||
unsigned long long _st_stat_epoll_spin = 0;
|
__thread unsigned long long _st_stat_epoll_spin = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(MD_HAVE_KQUEUE) && !defined(MD_HAVE_EPOLL) && !defined(MD_HAVE_SELECT)
|
#if !defined(MD_HAVE_KQUEUE) && !defined(MD_HAVE_EPOLL) && !defined(MD_HAVE_SELECT)
|
||||||
|
@ -86,7 +86,7 @@ typedef struct _kq_fd_data {
|
||||||
int revents;
|
int revents;
|
||||||
} _kq_fd_data_t;
|
} _kq_fd_data_t;
|
||||||
|
|
||||||
static struct _st_kqdata {
|
static __thread struct _st_kqdata {
|
||||||
_kq_fd_data_t *fd_data;
|
_kq_fd_data_t *fd_data;
|
||||||
struct kevent *evtlist;
|
struct kevent *evtlist;
|
||||||
struct kevent *addlist;
|
struct kevent *addlist;
|
||||||
|
@ -119,7 +119,7 @@ typedef struct _epoll_fd_data {
|
||||||
int revents;
|
int revents;
|
||||||
} _epoll_fd_data_t;
|
} _epoll_fd_data_t;
|
||||||
|
|
||||||
static struct _st_epolldata {
|
static __thread struct _st_epolldata {
|
||||||
_epoll_fd_data_t *fd_data;
|
_epoll_fd_data_t *fd_data;
|
||||||
struct epoll_event *evtlist;
|
struct epoll_event *evtlist;
|
||||||
int fd_data_size;
|
int fd_data_size;
|
||||||
|
@ -147,7 +147,7 @@ static struct _st_epolldata {
|
||||||
|
|
||||||
#endif /* MD_HAVE_EPOLL */
|
#endif /* MD_HAVE_EPOLL */
|
||||||
|
|
||||||
_st_eventsys_t *_st_eventsys = NULL;
|
__thread _st_eventsys_t *_st_eventsys = NULL;
|
||||||
|
|
||||||
|
|
||||||
#ifdef MD_HAVE_SELECT
|
#ifdef MD_HAVE_SELECT
|
||||||
|
|
30
trunk/3rdparty/st-srs/io.c
vendored
30
trunk/3rdparty/st-srs/io.c
vendored
|
@ -56,20 +56,20 @@
|
||||||
|
|
||||||
// Global stat.
|
// Global stat.
|
||||||
#if defined(DEBUG) && defined(DEBUG_STATS)
|
#if defined(DEBUG) && defined(DEBUG_STATS)
|
||||||
unsigned long long _st_stat_recvfrom = 0;
|
__thread unsigned long long _st_stat_recvfrom = 0;
|
||||||
unsigned long long _st_stat_recvfrom_eagain = 0;
|
__thread unsigned long long _st_stat_recvfrom_eagain = 0;
|
||||||
unsigned long long _st_stat_sendto = 0;
|
__thread unsigned long long _st_stat_sendto = 0;
|
||||||
unsigned long long _st_stat_sendto_eagain = 0;
|
__thread unsigned long long _st_stat_sendto_eagain = 0;
|
||||||
unsigned long long _st_stat_read = 0;
|
__thread unsigned long long _st_stat_read = 0;
|
||||||
unsigned long long _st_stat_read_eagain = 0;
|
__thread unsigned long long _st_stat_read_eagain = 0;
|
||||||
unsigned long long _st_stat_readv = 0;
|
__thread unsigned long long _st_stat_readv = 0;
|
||||||
unsigned long long _st_stat_readv_eagain = 0;
|
__thread unsigned long long _st_stat_readv_eagain = 0;
|
||||||
unsigned long long _st_stat_writev = 0;
|
__thread unsigned long long _st_stat_writev = 0;
|
||||||
unsigned long long _st_stat_writev_eagain = 0;
|
__thread unsigned long long _st_stat_writev_eagain = 0;
|
||||||
unsigned long long _st_stat_recvmsg = 0;
|
__thread unsigned long long _st_stat_recvmsg = 0;
|
||||||
unsigned long long _st_stat_recvmsg_eagain = 0;
|
__thread unsigned long long _st_stat_recvmsg_eagain = 0;
|
||||||
unsigned long long _st_stat_sendmsg = 0;
|
__thread unsigned long long _st_stat_sendmsg = 0;
|
||||||
unsigned long long _st_stat_sendmsg_eagain = 0;
|
__thread unsigned long long _st_stat_sendmsg_eagain = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if EAGAIN != EWOULDBLOCK
|
#if EAGAIN != EWOULDBLOCK
|
||||||
|
@ -81,7 +81,7 @@ unsigned long long _st_stat_sendmsg_eagain = 0;
|
||||||
#define _LOCAL_MAXIOV 16
|
#define _LOCAL_MAXIOV 16
|
||||||
|
|
||||||
/* File descriptor object free list */
|
/* File descriptor object free list */
|
||||||
static _st_netfd_t *_st_netfd_freelist = NULL;
|
static __thread _st_netfd_t *_st_netfd_freelist = NULL;
|
||||||
/* Maximum number of file descriptors that the process can open */
|
/* Maximum number of file descriptors that the process can open */
|
||||||
static int _st_osfd_limit = -1;
|
static int _st_osfd_limit = -1;
|
||||||
|
|
||||||
|
|
50
trunk/3rdparty/st-srs/sched.c
vendored
50
trunk/3rdparty/st-srs/sched.c
vendored
|
@ -56,31 +56,33 @@
|
||||||
|
|
||||||
// Global stat.
|
// Global stat.
|
||||||
#if defined(DEBUG) && defined(DEBUG_STATS)
|
#if defined(DEBUG) && defined(DEBUG_STATS)
|
||||||
unsigned long long _st_stat_sched_15ms = 0;
|
__thread unsigned long long _st_stat_sched_15ms = 0;
|
||||||
unsigned long long _st_stat_sched_20ms = 0;
|
__thread unsigned long long _st_stat_sched_20ms = 0;
|
||||||
unsigned long long _st_stat_sched_25ms = 0;
|
__thread unsigned long long _st_stat_sched_25ms = 0;
|
||||||
unsigned long long _st_stat_sched_30ms = 0;
|
__thread unsigned long long _st_stat_sched_30ms = 0;
|
||||||
unsigned long long _st_stat_sched_35ms = 0;
|
__thread unsigned long long _st_stat_sched_35ms = 0;
|
||||||
unsigned long long _st_stat_sched_40ms = 0;
|
__thread unsigned long long _st_stat_sched_40ms = 0;
|
||||||
unsigned long long _st_stat_sched_80ms = 0;
|
__thread unsigned long long _st_stat_sched_80ms = 0;
|
||||||
unsigned long long _st_stat_sched_160ms = 0;
|
__thread unsigned long long _st_stat_sched_160ms = 0;
|
||||||
unsigned long long _st_stat_sched_s = 0;
|
__thread unsigned long long _st_stat_sched_s = 0;
|
||||||
|
|
||||||
unsigned long long _st_stat_thread_run = 0;
|
__thread unsigned long long _st_stat_thread_run = 0;
|
||||||
unsigned long long _st_stat_thread_idle = 0;
|
__thread unsigned long long _st_stat_thread_idle = 0;
|
||||||
unsigned long long _st_stat_thread_yield = 0;
|
__thread unsigned long long _st_stat_thread_yield = 0;
|
||||||
unsigned long long _st_stat_thread_yield2 = 0;
|
__thread unsigned long long _st_stat_thread_yield2 = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Global data */
|
/* Global data */
|
||||||
_st_vp_t _st_this_vp; /* This VP */
|
__thread _st_vp_t _st_this_vp; /* This VP */
|
||||||
_st_thread_t *_st_this_thread; /* Current thread */
|
__thread _st_thread_t *_st_this_thread; /* Current thread */
|
||||||
int _st_active_count = 0; /* Active thread count */
|
__thread int _st_active_count = 0; /* Active thread count */
|
||||||
|
|
||||||
time_t _st_curr_time = 0; /* Current time as returned by time(2) */
|
__thread 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 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)
|
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)
|
int st_init(void)
|
||||||
{
|
{
|
||||||
_st_thread_t *thread;
|
_st_thread_t *thread;
|
||||||
|
|
||||||
if (_st_active_count) {
|
if (_st_active_count) {
|
||||||
/* Already initialized */
|
/* Already initialized */
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -178,7 +180,11 @@ int st_init(void)
|
||||||
|
|
||||||
if (_st_io_init() < 0)
|
if (_st_io_init() < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
// Initialize the thread-local variables.
|
||||||
|
ST_INIT_CLIST(&_st_free_stacks);
|
||||||
|
|
||||||
|
// Initialize ST.
|
||||||
memset(&_st_this_vp, 0, sizeof(_st_vp_t));
|
memset(&_st_this_vp, 0, sizeof(_st_vp_t));
|
||||||
|
|
||||||
ST_INIT_CLIST(&_ST_RUNQ);
|
ST_INIT_CLIST(&_ST_RUNQ);
|
||||||
|
@ -713,8 +719,8 @@ int _st_iterate_threads_flag = 0;
|
||||||
|
|
||||||
void _st_iterate_threads(void)
|
void _st_iterate_threads(void)
|
||||||
{
|
{
|
||||||
static _st_thread_t *thread = NULL;
|
static __thread _st_thread_t *thread = NULL;
|
||||||
static jmp_buf orig_jb, save_jb;
|
static __thread jmp_buf orig_jb, save_jb;
|
||||||
_st_clist_t *q;
|
_st_clist_t *q;
|
||||||
|
|
||||||
if (!_st_iterate_threads_flag) {
|
if (!_st_iterate_threads_flag) {
|
||||||
|
|
6
trunk/3rdparty/st-srs/stk.c
vendored
6
trunk/3rdparty/st-srs/stk.c
vendored
|
@ -52,9 +52,9 @@
|
||||||
/* How much space to leave between the stacks, at each end */
|
/* How much space to leave between the stacks, at each end */
|
||||||
#define REDZONE _ST_PAGE_SIZE
|
#define REDZONE _ST_PAGE_SIZE
|
||||||
|
|
||||||
_st_clist_t _st_free_stacks = ST_INIT_STATIC_CLIST(&_st_free_stacks);
|
__thread _st_clist_t _st_free_stacks;
|
||||||
int _st_num_free_stacks = 0;
|
__thread int _st_num_free_stacks = 0;
|
||||||
int _st_randomize_stacks = 0;
|
__thread int _st_randomize_stacks = 0;
|
||||||
|
|
||||||
static char *_st_new_stk_segment(int size);
|
static char *_st_new_stk_segment(int size);
|
||||||
|
|
||||||
|
|
6
trunk/3rdparty/st-srs/sync.c
vendored
6
trunk/3rdparty/st-srs/sync.c
vendored
|
@ -47,9 +47,9 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
|
||||||
extern time_t _st_curr_time;
|
extern __thread time_t _st_curr_time;
|
||||||
extern st_utime_t _st_last_tset;
|
extern __thread st_utime_t _st_last_tset;
|
||||||
extern int _st_active_count;
|
extern __thread int _st_active_count;
|
||||||
|
|
||||||
static st_utime_t (*_st_utime)(void) = NULL;
|
static st_utime_t (*_st_utime)(void) = NULL;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ The changelog for SRS.
|
||||||
|
|
||||||
## SRS 5.0 Changelog
|
## SRS 5.0 Changelog
|
||||||
|
|
||||||
|
* v5.0, 2022-06-28, ST: Support thread-local for multiple threads. v5.0.31
|
||||||
* v5.0, 2022-06-17, Merge [#3010](https://github.com/ossrs/srs/pull/3010): SRT: Support Coroutine Native SRT over ST. (#3010). v5.0.30
|
* v5.0, 2022-06-17, Merge [#3010](https://github.com/ossrs/srs/pull/3010): SRT: Support Coroutine Native SRT over ST. (#3010). v5.0.30
|
||||||
* v5.0, 2022-06-15, For [#3058](https://github.com/ossrs/srs/pull/3058): Docker: Support x86_64, armv7 and aarch64 docker image (#3058). v5.0.29
|
* v5.0, 2022-06-15, For [#3058](https://github.com/ossrs/srs/pull/3058): Docker: Support x86_64, armv7 and aarch64 docker image (#3058). v5.0.29
|
||||||
* v5.0, 2022-04-04, Support NGINX HLS Cluster, see [CN](https://github.com/ossrs/srs/wiki/v4_CN_SampleHlsCluster) or [EN](https://github.com/ossrs/srs/wiki/v4_EN_SampleHlsCluster). v5.0.28
|
* v5.0, 2022-04-04, Support NGINX HLS Cluster, see [CN](https://github.com/ossrs/srs/wiki/v4_CN_SampleHlsCluster) or [EN](https://github.com/ossrs/srs/wiki/v4_EN_SampleHlsCluster). v5.0.28
|
||||||
|
|
|
@ -9,6 +9,6 @@
|
||||||
|
|
||||||
#define VERSION_MAJOR 5
|
#define VERSION_MAJOR 5
|
||||||
#define VERSION_MINOR 0
|
#define VERSION_MINOR 0
|
||||||
#define VERSION_REVISION 30
|
#define VERSION_REVISION 31
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue