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

research st: refine skt.

This commit is contained in:
winlin 2014-11-06 13:55:06 +08:00
parent 22710db911
commit 3377df0bea

View file

@ -46,7 +46,6 @@
#include <sys/mman.h>
#include "common.h"
/* How much space to leave between the stacks, at each end */
#define REDZONE _ST_PAGE_SIZE
@ -75,8 +74,9 @@ _st_stack_t *_st_stack_new(int stack_size)
}
/* Make a new thread stack object. */
if ((ts = (_st_stack_t *)calloc(1, sizeof(_st_stack_t))) == NULL)
if ((ts = (_st_stack_t *)calloc(1, sizeof(_st_stack_t))) == NULL) {
return NULL;
}
extra = _st_randomize_stacks ? _ST_PAGE_SIZE : 0;
ts->vaddr_size = stack_size + 2*REDZONE + extra;
ts->vaddr = _st_new_stk_segment(ts->vaddr_size);
@ -103,21 +103,20 @@ _st_stack_t *_st_stack_new(int stack_size)
return ts;
}
/*
* Free the stack for the current thread
*/
void _st_stack_free(_st_stack_t *ts)
{
if (!ts)
if (!ts) {
return;
}
/* Put the stack on the free list */
ST_APPEND_LINK(&ts->links, _st_free_stacks.prev);
_st_num_free_stacks++;
}
static char *_st_new_stk_segment(int size)
{
#ifdef MALLOC_STACK
@ -127,28 +126,29 @@ static char *_st_new_stk_segment(int size)
int mmap_flags = MAP_PRIVATE;
void *vaddr;
#if defined (MD_USE_SYSV_ANON_MMAP)
#if defined (MD_USE_SYSV_ANON_MMAP)
if (zero_fd < 0) {
if ((zero_fd = open("/dev/zero", O_RDWR, 0)) < 0)
if ((zero_fd = open("/dev/zero", O_RDWR, 0)) < 0) {
return NULL;
}
fcntl(zero_fd, F_SETFD, FD_CLOEXEC);
}
#elif defined (MD_USE_BSD_ANON_MMAP)
#elif defined (MD_USE_BSD_ANON_MMAP)
mmap_flags |= MAP_ANON;
#else
#error Unknown OS
#endif
#else
#error Unknown OS
#endif
vaddr = mmap(NULL, size, PROT_READ | PROT_WRITE, mmap_flags, zero_fd, 0);
if (vaddr == (void *)MAP_FAILED)
if (vaddr == (void *)MAP_FAILED) {
return NULL;
}
#endif /* MALLOC_STACK */
#endif
return (char *)vaddr;
}
/* Not used */
#if 0
void _st_delete_stk_segment(char *vaddr, int size)
@ -166,8 +166,9 @@ int st_randomize_stacks(int on)
int wason = _st_randomize_stacks;
_st_randomize_stacks = on;
if (on)
if (on) {
srandom((unsigned int) st_utime());
}
return wason;
}