1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

ST: Replace macros with explicit code for better understanding. v7.0.7 (#4149)

Improvements for ST(State Threads):

1. ST: Use g++ for CXX compiler.
2. ST: Remove macros for clist.
3. ST: Remove macros for global thread and vp.
4. ST: Remove macros for vp queue operations.
5. ST: Remove macros for context switch.
6. ST: Remove macros for setjmp/longjmp.
7. ST: Remove macro for stack pad.
8. ST: Refine macro for valgrind.

---------

Co-authored-by: Jacob Su <suzp1984@gmail.com>
This commit is contained in:
Winlin 2024-08-22 11:28:25 +08:00 committed by GitHub
parent 0d76081430
commit ff6a608099
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 228 additions and 285 deletions

View file

@ -233,7 +233,7 @@ ST_HIDDEN void _st_select_find_bad_fd(void)
_ST_SELECT_MAX_OSFD = -1;
for (q = _ST_IOQ.next; q != &_ST_IOQ; q = q->next) {
for (q = _st_this_vp.io_q.next; q != &_st_this_vp.io_q; q = q->next) {
pq = _ST_POLLQUEUE_PTR(q);
notify = 0;
epds = pq->pds + pq->npds;
@ -254,7 +254,7 @@ ST_HIDDEN void _st_select_find_bad_fd(void)
}
if (notify) {
ST_REMOVE_LINK(&pq->links);
st_clist_remove(&pq->links);
pq->on_ioq = 0;
/*
* Decrement the count of descriptors for each descriptor/event
@ -281,9 +281,9 @@ ST_HIDDEN void _st_select_find_bad_fd(void)
}
if (pq->thread->flags & _ST_FL_ON_SLEEPQ)
_ST_DEL_SLEEPQ(pq->thread);
_st_del_sleep_q(pq->thread);
pq->thread->state = _ST_ST_RUNNABLE;
_ST_ADD_RUNQ(pq->thread);
st_clist_insert_before(&pq->thread->links, &_st_this_vp.run_q);
} else {
if (_ST_SELECT_MAX_OSFD < pq_max_osfd)
_ST_SELECT_MAX_OSFD = pq_max_osfd;
@ -315,11 +315,11 @@ ST_HIDDEN void _st_select_dispatch(void)
wp = &w;
ep = &e;
if (_ST_SLEEPQ == NULL) {
if (_st_this_vp.sleep_q == NULL) {
tvp = NULL;
} else {
min_timeout = (_ST_SLEEPQ->due <= _ST_LAST_CLOCK) ? 0 :
(_ST_SLEEPQ->due - _ST_LAST_CLOCK);
min_timeout = (_st_this_vp.sleep_q->due <= _st_this_vp.last_clock) ? 0 :
(_st_this_vp.sleep_q->due - _st_this_vp.last_clock);
timeout.tv_sec = (int) (min_timeout / 1000000);
timeout.tv_usec = (int) (min_timeout % 1000000);
tvp = &timeout;
@ -331,7 +331,7 @@ ST_HIDDEN void _st_select_dispatch(void)
/* Notify threads that are associated with the selected descriptors */
if (nfd > 0) {
_ST_SELECT_MAX_OSFD = -1;
for (q = _ST_IOQ.next; q != &_ST_IOQ; q = q->next) {
for (q = _st_this_vp.io_q.next; q != &_st_this_vp.io_q; q = q->next) {
pq = _ST_POLLQUEUE_PTR(q);
notify = 0;
epds = pq->pds + pq->npds;
@ -359,7 +359,7 @@ ST_HIDDEN void _st_select_dispatch(void)
}
}
if (notify) {
ST_REMOVE_LINK(&pq->links);
st_clist_remove(&pq->links);
pq->on_ioq = 0;
/*
* Decrement the count of descriptors for each descriptor/event
@ -386,9 +386,9 @@ ST_HIDDEN void _st_select_dispatch(void)
}
if (pq->thread->flags & _ST_FL_ON_SLEEPQ)
_ST_DEL_SLEEPQ(pq->thread);
_st_del_sleep_q(pq->thread);
pq->thread->state = _ST_ST_RUNNABLE;
_ST_ADD_RUNQ(pq->thread);
st_clist_insert_before(&pq->thread->links, &_st_this_vp.run_q);
} else {
if (_ST_SELECT_MAX_OSFD < pq_max_osfd)
_ST_SELECT_MAX_OSFD = pq_max_osfd;
@ -697,10 +697,10 @@ ST_HIDDEN void _st_kq_dispatch(void)
int nfd, i, osfd, notify, filter;
short events, revents;
if (_ST_SLEEPQ == NULL) {
if (_st_this_vp.sleep_q == NULL) {
tsp = NULL;
} else {
min_timeout = (_ST_SLEEPQ->due <= _ST_LAST_CLOCK) ? 0 : (_ST_SLEEPQ->due - _ST_LAST_CLOCK);
min_timeout = (_st_this_vp.sleep_q->due <= _st_this_vp.last_clock) ? 0 : (_st_this_vp.sleep_q->due - _st_this_vp.last_clock);
timeout.tv_sec = (time_t) (min_timeout / 1000000);
timeout.tv_nsec = (long) ((min_timeout % 1000000) * 1000);
tsp = &timeout;
@ -735,7 +735,7 @@ ST_HIDDEN void _st_kq_dispatch(void)
_st_kq_data->dellist_cnt = 0;
for (q = _ST_IOQ.next; q != &_ST_IOQ; q = q->next) {
for (q = _st_this_vp.io_q.next; q != &_st_this_vp.io_q; q = q->next) {
pq = _ST_POLLQUEUE_PTR(q);
notify = 0;
epds = pq->pds + pq->npds;
@ -756,7 +756,7 @@ ST_HIDDEN void _st_kq_dispatch(void)
}
}
if (notify) {
ST_REMOVE_LINK(&pq->links);
st_clist_remove(&pq->links);
pq->on_ioq = 0;
for (pds = pq->pds; pds < epds; pds++) {
osfd = pds->fd;
@ -782,9 +782,9 @@ ST_HIDDEN void _st_kq_dispatch(void)
}
if (pq->thread->flags & _ST_FL_ON_SLEEPQ)
_ST_DEL_SLEEPQ(pq->thread);
_st_del_sleep_q(pq->thread);
pq->thread->state = _ST_ST_RUNNABLE;
_ST_ADD_RUNQ(pq->thread);
st_clist_insert_before(&pq->thread->links, &_st_this_vp.run_q);
}
}
@ -811,7 +811,7 @@ ST_HIDDEN void _st_kq_dispatch(void)
_st_kq_data->pid = getpid();
/* Re-register all descriptors on ioq with new kqueue */
memset(_st_kq_data->fd_data, 0, _st_kq_data->fd_data_size * sizeof(_kq_fd_data_t));
for (q = _ST_IOQ.next; q != &_ST_IOQ; q = q->next) {
for (q = _st_this_vp.io_q.next; q != &_st_this_vp.io_q; q = q->next) {
pq = _ST_POLLQUEUE_PTR(q);
_st_kq_pollset_add(pq->pds, pq->npds);
}
@ -1064,10 +1064,10 @@ ST_HIDDEN void _st_epoll_dispatch(void)
++_st_stat_epoll;
#endif
if (_ST_SLEEPQ == NULL) {
if (_st_this_vp.sleep_q == NULL) {
timeout = -1;
} else {
min_timeout = (_ST_SLEEPQ->due <= _ST_LAST_CLOCK) ? 0 : (_ST_SLEEPQ->due - _ST_LAST_CLOCK);
min_timeout = (_st_this_vp.sleep_q->due <= _st_this_vp.last_clock) ? 0 : (_st_this_vp.sleep_q->due - _st_this_vp.last_clock);
timeout = (int) (min_timeout / 1000);
// At least wait 1ms when <1ms, to avoid epoll_wait spin loop.
@ -1105,7 +1105,7 @@ ST_HIDDEN void _st_epoll_dispatch(void)
}
}
for (q = _ST_IOQ.next; q != &_ST_IOQ; q = q->next) {
for (q = _st_this_vp.io_q.next; q != &_st_this_vp.io_q; q = q->next) {
pq = _ST_POLLQUEUE_PTR(q);
notify = 0;
epds = pq->pds + pq->npds;
@ -1135,7 +1135,7 @@ ST_HIDDEN void _st_epoll_dispatch(void)
}
}
if (notify) {
ST_REMOVE_LINK(&pq->links);
st_clist_remove(&pq->links);
pq->on_ioq = 0;
/*
* Here we will only delete/modify descriptors that
@ -1144,9 +1144,9 @@ ST_HIDDEN void _st_epoll_dispatch(void)
_st_epoll_pollset_del(pq->pds, pq->npds);
if (pq->thread->flags & _ST_FL_ON_SLEEPQ)
_ST_DEL_SLEEPQ(pq->thread);
_st_del_sleep_q(pq->thread);
pq->thread->state = _ST_ST_RUNNABLE;
_ST_ADD_RUNQ(pq->thread);
st_clist_insert_before(&pq->thread->links, &_st_this_vp.run_q);
}
}