mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
research st: replace the TAB with 4spaces
This commit is contained in:
parent
0faa38dc0c
commit
55bd1dd95e
7 changed files with 183 additions and 183 deletions
|
@ -61,7 +61,7 @@
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#define ST_HIDDEN /*nothing*/
|
#define ST_HIDDEN /*nothing*/
|
||||||
#else
|
#else
|
||||||
#define ST_HIDDEN static
|
#define ST_HIDDEN static
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "public.h"
|
#include "public.h"
|
||||||
|
@ -78,21 +78,21 @@ typedef struct _st_clist {
|
||||||
} _st_clist_t;
|
} _st_clist_t;
|
||||||
|
|
||||||
/* Insert element "_e" into the list, before "_l" */
|
/* Insert element "_e" into the list, before "_l" */
|
||||||
#define ST_INSERT_BEFORE(_e,_l) \
|
#define ST_INSERT_BEFORE(_e,_l) \
|
||||||
ST_BEGIN_MACRO \
|
ST_BEGIN_MACRO \
|
||||||
(_e)->next = (_l); \
|
(_e)->next = (_l); \
|
||||||
(_e)->prev = (_l)->prev; \
|
(_e)->prev = (_l)->prev; \
|
||||||
(_l)->prev->next = (_e); \
|
(_l)->prev->next = (_e); \
|
||||||
(_l)->prev = (_e); \
|
(_l)->prev = (_e); \
|
||||||
ST_END_MACRO
|
ST_END_MACRO
|
||||||
|
|
||||||
/* Insert element "_e" into the list, after "_l" */
|
/* Insert element "_e" into the list, after "_l" */
|
||||||
#define ST_INSERT_AFTER(_e,_l) \
|
#define ST_INSERT_AFTER(_e,_l) \
|
||||||
ST_BEGIN_MACRO \
|
ST_BEGIN_MACRO \
|
||||||
(_e)->next = (_l)->next; \
|
(_e)->next = (_l)->next; \
|
||||||
(_e)->prev = (_l); \
|
(_e)->prev = (_l); \
|
||||||
(_l)->next->prev = (_e); \
|
(_l)->next->prev = (_e); \
|
||||||
(_l)->next = (_e); \
|
(_l)->next = (_e); \
|
||||||
ST_END_MACRO
|
ST_END_MACRO
|
||||||
|
|
||||||
/* Return the element following element "_e" */
|
/* Return the element following element "_e" */
|
||||||
|
@ -109,10 +109,10 @@ typedef struct _st_clist {
|
||||||
#define ST_LIST_TAIL(_l) (_l)->prev
|
#define ST_LIST_TAIL(_l) (_l)->prev
|
||||||
|
|
||||||
/* Remove the element "_e" from it's circular list */
|
/* Remove the element "_e" from it's circular list */
|
||||||
#define ST_REMOVE_LINK(_e) \
|
#define ST_REMOVE_LINK(_e) \
|
||||||
ST_BEGIN_MACRO \
|
ST_BEGIN_MACRO \
|
||||||
(_e)->prev->next = (_e)->next; \
|
(_e)->prev->next = (_e)->next; \
|
||||||
(_e)->next->prev = (_e)->prev; \
|
(_e)->next->prev = (_e)->prev; \
|
||||||
ST_END_MACRO
|
ST_END_MACRO
|
||||||
|
|
||||||
/* Return non-zero if the given circular list "_l" is empty, */
|
/* Return non-zero if the given circular list "_l" is empty, */
|
||||||
|
@ -122,9 +122,9 @@ typedef struct _st_clist {
|
||||||
|
|
||||||
/* Initialize a circular list */
|
/* Initialize a circular list */
|
||||||
#define ST_INIT_CLIST(_l) \
|
#define ST_INIT_CLIST(_l) \
|
||||||
ST_BEGIN_MACRO \
|
ST_BEGIN_MACRO \
|
||||||
(_l)->next = (_l); \
|
(_l)->next = (_l); \
|
||||||
(_l)->prev = (_l); \
|
(_l)->prev = (_l); \
|
||||||
ST_END_MACRO
|
ST_END_MACRO
|
||||||
|
|
||||||
#define ST_INIT_STATIC_CLIST(_l) \
|
#define ST_INIT_STATIC_CLIST(_l) \
|
||||||
|
@ -153,7 +153,7 @@ typedef struct _st_stack {
|
||||||
|
|
||||||
|
|
||||||
typedef struct _st_cond {
|
typedef struct _st_cond {
|
||||||
_st_clist_t wait_q; /* Condition variable wait queue */
|
_st_clist_t wait_q; /* Condition variable wait queue */
|
||||||
} _st_cond_t;
|
} _st_cond_t;
|
||||||
|
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ struct _st_thread {
|
||||||
void *arg; /* Argument of the start function */
|
void *arg; /* Argument of the start function */
|
||||||
void *retval; /* Return value of the start function */
|
void *retval; /* Return value of the start function */
|
||||||
|
|
||||||
_st_stack_t *stack; /* Info about thread's stack */
|
_st_stack_t *stack; /* Info about thread's stack */
|
||||||
|
|
||||||
_st_clist_t links; /* For putting on run/sleep/zombie queue */
|
_st_clist_t links; /* For putting on run/sleep/zombie queue */
|
||||||
_st_clist_t wait_links; /* For putting on mutex/condvar wait queue */
|
_st_clist_t wait_links; /* For putting on mutex/condvar wait queue */
|
||||||
|
@ -177,7 +177,7 @@ struct _st_thread {
|
||||||
|
|
||||||
st_utime_t due; /* Wakeup time when thread is sleeping */
|
st_utime_t due; /* Wakeup time when thread is sleeping */
|
||||||
_st_thread_t *left; /* For putting in timeout heap */
|
_st_thread_t *left; /* For putting in timeout heap */
|
||||||
_st_thread_t *right; /* -- see docs/timeout_heap.txt for details */
|
_st_thread_t *right; /* -- see docs/timeout_heap.txt for details */
|
||||||
int heap_index;
|
int heap_index;
|
||||||
|
|
||||||
void **private_data; /* Per thread private data */
|
void **private_data; /* Per thread private data */
|
||||||
|
@ -229,11 +229,11 @@ typedef struct _st_vp {
|
||||||
int pagesize;
|
int pagesize;
|
||||||
|
|
||||||
_st_thread_t *sleep_q; /* sleep queue for this vp */
|
_st_thread_t *sleep_q; /* sleep queue for this vp */
|
||||||
int sleepq_size; /* number of threads on sleep queue */
|
int sleepq_size; /* number of threads on sleep queue */
|
||||||
|
|
||||||
#ifdef ST_SWITCH_CB
|
#ifdef ST_SWITCH_CB
|
||||||
st_switch_cb_t switch_out_cb; /* called when a thread is switched out */
|
st_switch_cb_t switch_out_cb; /* called when a thread is switched out */
|
||||||
st_switch_cb_t switch_in_cb; /* called when a thread is switched in */
|
st_switch_cb_t switch_in_cb; /* called when a thread is switched in */
|
||||||
#endif
|
#endif
|
||||||
} _st_vp_t;
|
} _st_vp_t;
|
||||||
|
|
||||||
|
@ -252,7 +252,7 @@ typedef struct _st_netfd {
|
||||||
* Current vp, thread, and event system
|
* Current vp, thread, and event system
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern _st_vp_t _st_this_vp;
|
extern _st_vp_t _st_this_vp;
|
||||||
extern _st_thread_t *_st_this_thread;
|
extern _st_thread_t *_st_this_thread;
|
||||||
extern _st_eventsys_t *_st_eventsys;
|
extern _st_eventsys_t *_st_eventsys;
|
||||||
|
|
||||||
|
@ -287,7 +287,7 @@ extern _st_eventsys_t *_st_eventsys;
|
||||||
#define _ST_DEL_RUNQ(_thr) ST_REMOVE_LINK(&(_thr)->links)
|
#define _ST_DEL_RUNQ(_thr) ST_REMOVE_LINK(&(_thr)->links)
|
||||||
|
|
||||||
#define _ST_ADD_SLEEPQ(_thr, _timeout) _st_add_sleep_q(_thr, _timeout)
|
#define _ST_ADD_SLEEPQ(_thr, _timeout) _st_add_sleep_q(_thr, _timeout)
|
||||||
#define _ST_DEL_SLEEPQ(_thr) _st_del_sleep_q(_thr)
|
#define _ST_DEL_SLEEPQ(_thr) _st_del_sleep_q(_thr)
|
||||||
|
|
||||||
#define _ST_ADD_ZOMBIEQ(_thr) ST_APPEND_LINK(&(_thr)->links, &_ST_ZOMBIEQ)
|
#define _ST_ADD_ZOMBIEQ(_thr) ST_APPEND_LINK(&(_thr)->links, &_ST_ZOMBIEQ)
|
||||||
#define _ST_DEL_ZOMBIEQ(_thr) ST_REMOVE_LINK(&(_thr)->links)
|
#define _ST_DEL_ZOMBIEQ(_thr) ST_REMOVE_LINK(&(_thr)->links)
|
||||||
|
@ -379,17 +379,17 @@ void _st_iterate_threads(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ST_SWITCH_CB
|
#ifdef ST_SWITCH_CB
|
||||||
#define ST_SWITCH_OUT_CB(_thread) \
|
#define ST_SWITCH_OUT_CB(_thread) \
|
||||||
if (_st_this_vp.switch_out_cb != NULL && \
|
if (_st_this_vp.switch_out_cb != NULL && \
|
||||||
_thread != _st_this_vp.idle_thread && \
|
_thread != _st_this_vp.idle_thread && \
|
||||||
_thread->state != _ST_ST_ZOMBIE) { \
|
_thread->state != _ST_ST_ZOMBIE) { \
|
||||||
_st_this_vp.switch_out_cb(); \
|
_st_this_vp.switch_out_cb(); \
|
||||||
}
|
}
|
||||||
#define ST_SWITCH_IN_CB(_thread) \
|
#define ST_SWITCH_IN_CB(_thread) \
|
||||||
if (_st_this_vp.switch_in_cb != NULL && \
|
if (_st_this_vp.switch_in_cb != NULL && \
|
||||||
_thread != _st_this_vp.idle_thread && \
|
_thread != _st_this_vp.idle_thread && \
|
||||||
_thread->state != _ST_ST_ZOMBIE) { \
|
_thread->state != _ST_ST_ZOMBIE) { \
|
||||||
_st_this_vp.switch_in_cb(); \
|
_st_this_vp.switch_in_cb(); \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define ST_SWITCH_OUT_CB(_thread)
|
#define ST_SWITCH_OUT_CB(_thread)
|
||||||
|
@ -457,10 +457,10 @@ int st_cond_timedwait(_st_cond_t *cvar, st_utime_t timeout);
|
||||||
int st_cond_signal(_st_cond_t *cvar);
|
int st_cond_signal(_st_cond_t *cvar);
|
||||||
ssize_t st_read(_st_netfd_t *fd, void *buf, size_t nbyte, st_utime_t timeout);
|
ssize_t st_read(_st_netfd_t *fd, void *buf, size_t nbyte, st_utime_t timeout);
|
||||||
ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte,
|
ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte,
|
||||||
st_utime_t timeout);
|
st_utime_t timeout);
|
||||||
int st_poll(struct pollfd *pds, int npds, st_utime_t timeout);
|
int st_poll(struct pollfd *pds, int npds, st_utime_t timeout);
|
||||||
_st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg,
|
_st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg,
|
||||||
int joinable, int stk_size);
|
int joinable, int stk_size);
|
||||||
|
|
||||||
#endif /* !__ST_COMMON_H__ */
|
#endif /* !__ST_COMMON_H__ */
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,7 @@ static _st_netfd_t *_st_netfd_new(int osfd, int nonblock, int is_socket)
|
||||||
return fd;
|
return fd;
|
||||||
/* Do it the Posix way */
|
/* Do it the Posix way */
|
||||||
if ((flags = fcntl(osfd, F_GETFL, 0)) < 0 ||
|
if ((flags = fcntl(osfd, F_GETFL, 0)) < 0 ||
|
||||||
fcntl(osfd, F_SETFL, flags | O_NONBLOCK) < 0) {
|
fcntl(osfd, F_SETFL, flags | O_NONBLOCK) < 0) {
|
||||||
st_netfd_free(fd);
|
st_netfd_free(fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ int st_netfd_fileno(_st_netfd_t *fd)
|
||||||
|
|
||||||
|
|
||||||
void st_netfd_setspecific(_st_netfd_t *fd, void *value,
|
void st_netfd_setspecific(_st_netfd_t *fd, void *value,
|
||||||
_st_destructor_t destructor)
|
_st_destructor_t destructor)
|
||||||
{
|
{
|
||||||
if (value != fd->private_data) {
|
if (value != fd->private_data) {
|
||||||
/* Free up previously set non-NULL data value */
|
/* Free up previously set non-NULL data value */
|
||||||
|
@ -248,7 +248,7 @@ static void _st_netfd_free_aux_data(_st_netfd_t *fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
_st_netfd_t *st_accept(_st_netfd_t *fd, struct sockaddr *addr, int *addrlen,
|
_st_netfd_t *st_accept(_st_netfd_t *fd, struct sockaddr *addr, int *addrlen,
|
||||||
st_utime_t timeout)
|
st_utime_t timeout)
|
||||||
{
|
{
|
||||||
int osfd, err;
|
int osfd, err;
|
||||||
_st_netfd_t *newfd;
|
_st_netfd_t *newfd;
|
||||||
|
@ -335,7 +335,7 @@ static void _st_netfd_free_aux_data(_st_netfd_t *fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
_st_netfd_t *st_accept(_st_netfd_t *fd, struct sockaddr *addr, int *addrlen,
|
_st_netfd_t *st_accept(_st_netfd_t *fd, struct sockaddr *addr, int *addrlen,
|
||||||
st_utime_t timeout)
|
st_utime_t timeout)
|
||||||
{
|
{
|
||||||
int osfd, err;
|
int osfd, err;
|
||||||
_st_netfd_t *newfd;
|
_st_netfd_t *newfd;
|
||||||
|
@ -350,7 +350,7 @@ _st_netfd_t *st_accept(_st_netfd_t *fd, struct sockaddr *addr, int *addrlen,
|
||||||
/* Get the lock */
|
/* Get the lock */
|
||||||
n = st_read(p[0], &c, 1, timeout);
|
n = st_read(p[0], &c, 1, timeout);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
ST_ASSERT(n == 1);
|
ST_ASSERT(n == 1);
|
||||||
/* Got the lock */
|
/* Got the lock */
|
||||||
osfd = accept(fd->osfd, addr, (socklen_t *)addrlen);
|
osfd = accept(fd->osfd, addr, (socklen_t *)addrlen);
|
||||||
|
@ -393,7 +393,7 @@ _st_netfd_t *st_accept(_st_netfd_t *fd, struct sockaddr *addr, int *addrlen,
|
||||||
|
|
||||||
|
|
||||||
int st_connect(_st_netfd_t *fd, const struct sockaddr *addr, int addrlen,
|
int st_connect(_st_netfd_t *fd, const struct sockaddr *addr, int addrlen,
|
||||||
st_utime_t timeout)
|
st_utime_t timeout)
|
||||||
{
|
{
|
||||||
int n, err = 0;
|
int n, err = 0;
|
||||||
|
|
||||||
|
@ -408,18 +408,18 @@ int st_connect(_st_netfd_t *fd, const struct sockaddr *addr, int addrlen,
|
||||||
* ("Interrupted connect").
|
* ("Interrupted connect").
|
||||||
*/
|
*/
|
||||||
if (errno != EINPROGRESS && (errno != EADDRINUSE || err == 0))
|
if (errno != EINPROGRESS && (errno != EADDRINUSE || err == 0))
|
||||||
return -1;
|
return -1;
|
||||||
/* Wait until the socket becomes writable */
|
/* Wait until the socket becomes writable */
|
||||||
if (st_netfd_poll(fd, POLLOUT, timeout) < 0)
|
if (st_netfd_poll(fd, POLLOUT, timeout) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
/* Try to find out whether the connection setup succeeded or failed */
|
/* Try to find out whether the connection setup succeeded or failed */
|
||||||
n = sizeof(int);
|
n = sizeof(int);
|
||||||
if (getsockopt(fd->osfd, SOL_SOCKET, SO_ERROR, (char *)&err,
|
if (getsockopt(fd->osfd, SOL_SOCKET, SO_ERROR, (char *)&err,
|
||||||
(socklen_t *)&n) < 0)
|
(socklen_t *)&n) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (err) {
|
if (err) {
|
||||||
errno = err;
|
errno = err;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -449,7 +449,7 @@ ssize_t st_read(_st_netfd_t *fd, void *buf, size_t nbyte, st_utime_t timeout)
|
||||||
|
|
||||||
|
|
||||||
int st_read_resid(_st_netfd_t *fd, void *buf, size_t *resid,
|
int st_read_resid(_st_netfd_t *fd, void *buf, size_t *resid,
|
||||||
st_utime_t timeout)
|
st_utime_t timeout)
|
||||||
{
|
{
|
||||||
struct iovec iov, *riov;
|
struct iovec iov, *riov;
|
||||||
int riov_size, rv;
|
int riov_size, rv;
|
||||||
|
@ -465,7 +465,7 @@ int st_read_resid(_st_netfd_t *fd, void *buf, size_t *resid,
|
||||||
|
|
||||||
|
|
||||||
ssize_t st_readv(_st_netfd_t *fd, const struct iovec *iov, int iov_size,
|
ssize_t st_readv(_st_netfd_t *fd, const struct iovec *iov, int iov_size,
|
||||||
st_utime_t timeout)
|
st_utime_t timeout)
|
||||||
{
|
{
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
|
|
||||||
|
@ -483,7 +483,7 @@ ssize_t st_readv(_st_netfd_t *fd, const struct iovec *iov, int iov_size,
|
||||||
}
|
}
|
||||||
|
|
||||||
int st_readv_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size,
|
int st_readv_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size,
|
||||||
st_utime_t timeout)
|
st_utime_t timeout)
|
||||||
{
|
{
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
|
|
||||||
|
@ -494,23 +494,23 @@ int st_readv_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size,
|
||||||
n = readv(fd->osfd, *iov, *iov_size);
|
n = readv(fd->osfd, *iov, *iov_size);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
if (!_IO_NOT_READY_ERROR)
|
if (!_IO_NOT_READY_ERROR)
|
||||||
return -1;
|
return -1;
|
||||||
} else if (n == 0)
|
} else if (n == 0)
|
||||||
break;
|
break;
|
||||||
else {
|
else {
|
||||||
while ((size_t) n >= (*iov)->iov_len) {
|
while ((size_t) n >= (*iov)->iov_len) {
|
||||||
n -= (*iov)->iov_len;
|
n -= (*iov)->iov_len;
|
||||||
(*iov)->iov_base = (char *) (*iov)->iov_base + (*iov)->iov_len;
|
(*iov)->iov_base = (char *) (*iov)->iov_base + (*iov)->iov_len;
|
||||||
(*iov)->iov_len = 0;
|
(*iov)->iov_len = 0;
|
||||||
(*iov)++;
|
(*iov)++;
|
||||||
(*iov_size)--;
|
(*iov_size)--;
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (*iov_size == 0)
|
if (*iov_size == 0)
|
||||||
break;
|
break;
|
||||||
(*iov)->iov_base = (char *) (*iov)->iov_base + n;
|
(*iov)->iov_base = (char *) (*iov)->iov_base + n;
|
||||||
(*iov)->iov_len -= n;
|
(*iov)->iov_len -= n;
|
||||||
}
|
}
|
||||||
|
@ -524,7 +524,7 @@ int st_readv_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size,
|
||||||
|
|
||||||
|
|
||||||
ssize_t st_read_fully(_st_netfd_t *fd, void *buf, size_t nbyte,
|
ssize_t st_read_fully(_st_netfd_t *fd, void *buf, size_t nbyte,
|
||||||
st_utime_t timeout)
|
st_utime_t timeout)
|
||||||
{
|
{
|
||||||
size_t resid = nbyte;
|
size_t resid = nbyte;
|
||||||
return st_read_resid(fd, buf, &resid, timeout) == 0 ?
|
return st_read_resid(fd, buf, &resid, timeout) == 0 ?
|
||||||
|
@ -533,12 +533,12 @@ ssize_t st_read_fully(_st_netfd_t *fd, void *buf, size_t nbyte,
|
||||||
|
|
||||||
|
|
||||||
int st_write_resid(_st_netfd_t *fd, const void *buf, size_t *resid,
|
int st_write_resid(_st_netfd_t *fd, const void *buf, size_t *resid,
|
||||||
st_utime_t timeout)
|
st_utime_t timeout)
|
||||||
{
|
{
|
||||||
struct iovec iov, *riov;
|
struct iovec iov, *riov;
|
||||||
int riov_size, rv;
|
int riov_size, rv;
|
||||||
|
|
||||||
iov.iov_base = (void *) buf; /* we promise not to modify buf */
|
iov.iov_base = (void *) buf; /* we promise not to modify buf */
|
||||||
iov.iov_len = *resid;
|
iov.iov_len = *resid;
|
||||||
riov = &iov;
|
riov = &iov;
|
||||||
riov_size = 1;
|
riov_size = 1;
|
||||||
|
@ -549,7 +549,7 @@ int st_write_resid(_st_netfd_t *fd, const void *buf, size_t *resid,
|
||||||
|
|
||||||
|
|
||||||
ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte,
|
ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte,
|
||||||
st_utime_t timeout)
|
st_utime_t timeout)
|
||||||
{
|
{
|
||||||
size_t resid = nbyte;
|
size_t resid = nbyte;
|
||||||
return st_write_resid(fd, buf, &resid, timeout) == 0 ?
|
return st_write_resid(fd, buf, &resid, timeout) == 0 ?
|
||||||
|
@ -558,7 +558,7 @@ ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte,
|
||||||
|
|
||||||
|
|
||||||
ssize_t st_writev(_st_netfd_t *fd, const struct iovec *iov, int iov_size,
|
ssize_t st_writev(_st_netfd_t *fd, const struct iovec *iov, int iov_size,
|
||||||
st_utime_t timeout)
|
st_utime_t timeout)
|
||||||
{
|
{
|
||||||
ssize_t n, rv;
|
ssize_t n, rv;
|
||||||
size_t nleft, nbyte;
|
size_t nleft, nbyte;
|
||||||
|
@ -573,40 +573,40 @@ ssize_t st_writev(_st_netfd_t *fd, const struct iovec *iov, int iov_size,
|
||||||
|
|
||||||
rv = (ssize_t)nbyte;
|
rv = (ssize_t)nbyte;
|
||||||
nleft = nbyte;
|
nleft = nbyte;
|
||||||
tmp_iov = (struct iovec *) iov; /* we promise not to modify iov */
|
tmp_iov = (struct iovec *) iov; /* we promise not to modify iov */
|
||||||
iov_cnt = iov_size;
|
iov_cnt = iov_size;
|
||||||
|
|
||||||
while (nleft > 0) {
|
while (nleft > 0) {
|
||||||
if (iov_cnt == 1) {
|
if (iov_cnt == 1) {
|
||||||
if (st_write(fd, tmp_iov[0].iov_base, nleft, timeout) != (ssize_t) nleft)
|
if (st_write(fd, tmp_iov[0].iov_base, nleft, timeout) != (ssize_t) nleft)
|
||||||
rv = -1;
|
rv = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((n = writev(fd->osfd, tmp_iov, iov_cnt)) < 0) {
|
if ((n = writev(fd->osfd, tmp_iov, iov_cnt)) < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
if (!_IO_NOT_READY_ERROR) {
|
if (!_IO_NOT_READY_ERROR) {
|
||||||
rv = -1;
|
rv = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((size_t) n == nleft)
|
if ((size_t) n == nleft)
|
||||||
break;
|
break;
|
||||||
nleft -= n;
|
nleft -= n;
|
||||||
/* Find the next unwritten vector */
|
/* Find the next unwritten vector */
|
||||||
n = (ssize_t)(nbyte - nleft);
|
n = (ssize_t)(nbyte - nleft);
|
||||||
for (index = 0; (size_t) n >= iov[index].iov_len; index++)
|
for (index = 0; (size_t) n >= iov[index].iov_len; index++)
|
||||||
n -= iov[index].iov_len;
|
n -= iov[index].iov_len;
|
||||||
|
|
||||||
if (tmp_iov == iov) {
|
if (tmp_iov == iov) {
|
||||||
/* Must copy iov's around */
|
/* Must copy iov's around */
|
||||||
if (iov_size - index <= _LOCAL_MAXIOV) {
|
if (iov_size - index <= _LOCAL_MAXIOV) {
|
||||||
tmp_iov = local_iov;
|
tmp_iov = local_iov;
|
||||||
} else {
|
} else {
|
||||||
tmp_iov = calloc(1, (iov_size - index) * sizeof(struct iovec));
|
tmp_iov = calloc(1, (iov_size - index) * sizeof(struct iovec));
|
||||||
if (tmp_iov == NULL)
|
if (tmp_iov == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fill in the first partial read */
|
/* Fill in the first partial read */
|
||||||
|
@ -615,8 +615,8 @@ ssize_t st_writev(_st_netfd_t *fd, const struct iovec *iov, int iov_size,
|
||||||
index++;
|
index++;
|
||||||
/* Copy the remaining vectors */
|
/* Copy the remaining vectors */
|
||||||
for (iov_cnt = 1; index < iov_size; iov_cnt++, index++) {
|
for (iov_cnt = 1; index < iov_size; iov_cnt++, index++) {
|
||||||
tmp_iov[iov_cnt].iov_base = iov[index].iov_base;
|
tmp_iov[iov_cnt].iov_base = iov[index].iov_base;
|
||||||
tmp_iov[iov_cnt].iov_len = iov[index].iov_len;
|
tmp_iov[iov_cnt].iov_len = iov[index].iov_len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Wait until the socket becomes writable */
|
/* Wait until the socket becomes writable */
|
||||||
|
@ -634,7 +634,7 @@ ssize_t st_writev(_st_netfd_t *fd, const struct iovec *iov, int iov_size,
|
||||||
|
|
||||||
|
|
||||||
int st_writev_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size,
|
int st_writev_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size,
|
||||||
st_utime_t timeout)
|
st_utime_t timeout)
|
||||||
{
|
{
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
|
|
||||||
|
@ -645,21 +645,21 @@ int st_writev_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size,
|
||||||
n = writev(fd->osfd, *iov, *iov_size);
|
n = writev(fd->osfd, *iov, *iov_size);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
if (!_IO_NOT_READY_ERROR)
|
if (!_IO_NOT_READY_ERROR)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
while ((size_t) n >= (*iov)->iov_len) {
|
while ((size_t) n >= (*iov)->iov_len) {
|
||||||
n -= (*iov)->iov_len;
|
n -= (*iov)->iov_len;
|
||||||
(*iov)->iov_base = (char *) (*iov)->iov_base + (*iov)->iov_len;
|
(*iov)->iov_base = (char *) (*iov)->iov_base + (*iov)->iov_len;
|
||||||
(*iov)->iov_len = 0;
|
(*iov)->iov_len = 0;
|
||||||
(*iov)++;
|
(*iov)++;
|
||||||
(*iov_size)--;
|
(*iov_size)--;
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (*iov_size == 0)
|
if (*iov_size == 0)
|
||||||
break;
|
break;
|
||||||
(*iov)->iov_base = (char *) (*iov)->iov_base + n;
|
(*iov)->iov_base = (char *) (*iov)->iov_base + n;
|
||||||
(*iov)->iov_len -= n;
|
(*iov)->iov_len -= n;
|
||||||
}
|
}
|
||||||
|
@ -676,12 +676,12 @@ int st_writev_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size,
|
||||||
* Simple I/O functions for UDP.
|
* Simple I/O functions for UDP.
|
||||||
*/
|
*/
|
||||||
int st_recvfrom(_st_netfd_t *fd, void *buf, int len, struct sockaddr *from,
|
int st_recvfrom(_st_netfd_t *fd, void *buf, int len, struct sockaddr *from,
|
||||||
int *fromlen, st_utime_t timeout)
|
int *fromlen, st_utime_t timeout)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
while ((n = recvfrom(fd->osfd, buf, len, 0, from, (socklen_t *)fromlen))
|
while ((n = recvfrom(fd->osfd, buf, len, 0, from, (socklen_t *)fromlen))
|
||||||
< 0) {
|
< 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
if (!_IO_NOT_READY_ERROR)
|
if (!_IO_NOT_READY_ERROR)
|
||||||
|
@ -696,7 +696,7 @@ int st_recvfrom(_st_netfd_t *fd, void *buf, int len, struct sockaddr *from,
|
||||||
|
|
||||||
|
|
||||||
int st_sendto(_st_netfd_t *fd, const void *msg, int len,
|
int st_sendto(_st_netfd_t *fd, const void *msg, int len,
|
||||||
const struct sockaddr *to, int tolen, st_utime_t timeout)
|
const struct sockaddr *to, int tolen, st_utime_t timeout)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
|
@ -715,7 +715,7 @@ int st_sendto(_st_netfd_t *fd, const void *msg, int len,
|
||||||
|
|
||||||
|
|
||||||
int st_recvmsg(_st_netfd_t *fd, struct msghdr *msg, int flags,
|
int st_recvmsg(_st_netfd_t *fd, struct msghdr *msg, int flags,
|
||||||
st_utime_t timeout)
|
st_utime_t timeout)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
|
@ -734,7 +734,7 @@ int st_recvmsg(_st_netfd_t *fd, struct msghdr *msg, int flags,
|
||||||
|
|
||||||
|
|
||||||
int st_sendmsg(_st_netfd_t *fd, const struct msghdr *msg, int flags,
|
int st_sendmsg(_st_netfd_t *fd, const struct msghdr *msg, int flags,
|
||||||
st_utime_t timeout)
|
st_utime_t timeout)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ _st_md_cxt_save:
|
||||||
;;
|
;;
|
||||||
stf.spill.nta [r8] = f2,32
|
stf.spill.nta [r8] = f2,32
|
||||||
stf.spill.nta [r9] = f3,32
|
stf.spill.nta [r9] = f3,32
|
||||||
mov r15 = rp
|
mov r15 = rp
|
||||||
;;
|
;;
|
||||||
stf.spill.nta [r8] = f4,32
|
stf.spill.nta [r8] = f4,32
|
||||||
stf.spill.nta [r9] = f5,32
|
stf.spill.nta [r9] = f5,32
|
||||||
|
@ -143,7 +143,7 @@ _st_md_cxt_save:
|
||||||
;;
|
;;
|
||||||
st8.nta [r2] = r18,16 // b2
|
st8.nta [r2] = r18,16 // b2
|
||||||
st8.nta [r3] = r19,16 // b3
|
st8.nta [r3] = r19,16 // b3
|
||||||
mov r26 = ar.rsc
|
mov r26 = ar.rsc
|
||||||
;;
|
;;
|
||||||
st8.nta [r2] = r20,16 // b4
|
st8.nta [r2] = r20,16 // b4
|
||||||
st8.nta [r3] = r21,16 // b5
|
st8.nta [r3] = r21,16 // b5
|
||||||
|
@ -158,18 +158,18 @@ _st_md_cxt_save:
|
||||||
st8.nta [r3] = in0,16 // &__jmp_buf (just in case)
|
st8.nta [r3] = in0,16 // &__jmp_buf (just in case)
|
||||||
;;
|
;;
|
||||||
st8.nta [r2] = r26 // ar.rsc
|
st8.nta [r2] = r26 // ar.rsc
|
||||||
;;
|
;;
|
||||||
flushrs // flush dirty regs to backing store
|
flushrs // flush dirty regs to backing store
|
||||||
;;
|
;;
|
||||||
and r27 = ~0x3,r26 // clear ar.rsc.mode
|
and r27 = ~0x3,r26 // clear ar.rsc.mode
|
||||||
;;
|
;;
|
||||||
mov ar.rsc = r27 // put RSE in enforced lazy mode
|
mov ar.rsc = r27 // put RSE in enforced lazy mode
|
||||||
;;
|
;;
|
||||||
mov r28 = ar.rnat
|
mov r28 = ar.rnat
|
||||||
;;
|
;;
|
||||||
st8.nta [r3] = r28 // ar.rnat
|
st8.nta [r3] = r28 // ar.rnat
|
||||||
mov ar.rsc = r26 // restore ar.rsc
|
mov ar.rsc = r26 // restore ar.rsc
|
||||||
;;
|
;;
|
||||||
mov r8 = 0
|
mov r8 = 0
|
||||||
br.ret.sptk.few b0
|
br.ret.sptk.few b0
|
||||||
.endp _st_md_cxt_save
|
.endp _st_md_cxt_save
|
||||||
|
@ -183,31 +183,31 @@ _st_md_cxt_save:
|
||||||
_st_md_cxt_restore:
|
_st_md_cxt_restore:
|
||||||
alloc r8 = ar.pfs,2,0,0,0
|
alloc r8 = ar.pfs,2,0,0,0
|
||||||
add r2 = 0x88,in0 // r2 <- &jmpbuf.ar_bsp
|
add r2 = 0x88,in0 // r2 <- &jmpbuf.ar_bsp
|
||||||
mov r16 = ar.rsc
|
mov r16 = ar.rsc
|
||||||
;;
|
;;
|
||||||
flushrs // flush dirty regs to backing store
|
flushrs // flush dirty regs to backing store
|
||||||
;;
|
;;
|
||||||
and r17 = ~0x3,r16 // clear ar.rsc.mode
|
and r17 = ~0x3,r16 // clear ar.rsc.mode
|
||||||
;;
|
;;
|
||||||
mov ar.rsc = r17 // put RSE in enforced lazy mode
|
mov ar.rsc = r17 // put RSE in enforced lazy mode
|
||||||
;;
|
;;
|
||||||
invala // invalidate the ALAT
|
invala // invalidate the ALAT
|
||||||
;;
|
;;
|
||||||
ld8 r23 = [r2],8 // r23 <- jmpbuf.ar_bsp
|
ld8 r23 = [r2],8 // r23 <- jmpbuf.ar_bsp
|
||||||
;;
|
;;
|
||||||
mov ar.bspstore = r23 // write BSPSTORE
|
mov ar.bspstore = r23 // write BSPSTORE
|
||||||
ld8 r25 = [r2],24 // r25 <- jmpbuf.ar_unat
|
ld8 r25 = [r2],24 // r25 <- jmpbuf.ar_unat
|
||||||
;;
|
;;
|
||||||
ld8 r26 = [r2],-8 // r26 <- jmpbuf.ar_rnat
|
ld8 r26 = [r2],-8 // r26 <- jmpbuf.ar_rnat
|
||||||
;;
|
;;
|
||||||
mov ar.rnat = r26 // write RNAT
|
mov ar.rnat = r26 // write RNAT
|
||||||
ld8 r27 = [r2] // r27 <- jmpbuf.ar_rsc
|
ld8 r27 = [r2] // r27 <- jmpbuf.ar_rsc
|
||||||
;;
|
;;
|
||||||
mov ar.rsc = r27 // write RSE control
|
mov ar.rsc = r27 // write RSE control
|
||||||
mov r2 = in0
|
mov r2 = in0
|
||||||
;;
|
;;
|
||||||
mov ar.unat = r25 // write ar.unat
|
mov ar.unat = r25 // write ar.unat
|
||||||
add r3 = 8,in0
|
add r3 = 8,in0
|
||||||
;;
|
;;
|
||||||
ld8.fill.nta sp = [r2],16 // r12 (sp)
|
ld8.fill.nta sp = [r2],16 // r12 (sp)
|
||||||
ld8.fill.nta gp = [r3],16 // r1 (gp)
|
ld8.fill.nta gp = [r3],16 // r1 (gp)
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
|
|
||||||
#define ST_VERSION "1.9"
|
#define ST_VERSION "1.9"
|
||||||
#define ST_VERSION_MAJOR 1
|
#define ST_VERSION_MAJOR 1
|
||||||
#define ST_VERSION_MINOR 9
|
#define ST_VERSION_MINOR 9
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ extern void st_thread_exit(void *retval);
|
||||||
extern int st_thread_join(st_thread_t thread, void **retvalp);
|
extern int st_thread_join(st_thread_t thread, void **retvalp);
|
||||||
extern void st_thread_interrupt(st_thread_t thread);
|
extern void st_thread_interrupt(st_thread_t thread);
|
||||||
extern st_thread_t st_thread_create(void *(*start)(void *arg), void *arg,
|
extern st_thread_t st_thread_create(void *(*start)(void *arg), void *arg,
|
||||||
int joinable, int stack_size);
|
int joinable, int stack_size);
|
||||||
extern int st_randomize_stacks(int on);
|
extern int st_randomize_stacks(int on);
|
||||||
extern int st_set_utime_function(st_utime_t (*func)(void));
|
extern int st_set_utime_function(st_utime_t (*func)(void));
|
||||||
|
|
||||||
|
@ -132,43 +132,43 @@ extern void st_netfd_free(st_netfd_t fd);
|
||||||
extern int st_netfd_close(st_netfd_t fd);
|
extern int st_netfd_close(st_netfd_t fd);
|
||||||
extern int st_netfd_fileno(st_netfd_t fd);
|
extern int st_netfd_fileno(st_netfd_t fd);
|
||||||
extern void st_netfd_setspecific(st_netfd_t fd, void *value,
|
extern void st_netfd_setspecific(st_netfd_t fd, void *value,
|
||||||
void (*destructor)(void *));
|
void (*destructor)(void *));
|
||||||
extern void *st_netfd_getspecific(st_netfd_t fd);
|
extern void *st_netfd_getspecific(st_netfd_t fd);
|
||||||
extern int st_netfd_serialize_accept(st_netfd_t fd);
|
extern int st_netfd_serialize_accept(st_netfd_t fd);
|
||||||
extern int st_netfd_poll(st_netfd_t fd, int how, st_utime_t timeout);
|
extern int st_netfd_poll(st_netfd_t fd, int how, st_utime_t timeout);
|
||||||
|
|
||||||
extern int st_poll(struct pollfd *pds, int npds, st_utime_t timeout);
|
extern int st_poll(struct pollfd *pds, int npds, st_utime_t timeout);
|
||||||
extern st_netfd_t st_accept(st_netfd_t fd, struct sockaddr *addr, int *addrlen,
|
extern st_netfd_t st_accept(st_netfd_t fd, struct sockaddr *addr, int *addrlen,
|
||||||
st_utime_t timeout);
|
st_utime_t timeout);
|
||||||
extern int st_connect(st_netfd_t fd, const struct sockaddr *addr, int addrlen,
|
extern int st_connect(st_netfd_t fd, const struct sockaddr *addr, int addrlen,
|
||||||
st_utime_t timeout);
|
st_utime_t timeout);
|
||||||
extern ssize_t st_read(st_netfd_t fd, void *buf, size_t nbyte,
|
extern ssize_t st_read(st_netfd_t fd, void *buf, size_t nbyte,
|
||||||
st_utime_t timeout);
|
st_utime_t timeout);
|
||||||
extern ssize_t st_read_fully(st_netfd_t fd, void *buf, size_t nbyte,
|
extern ssize_t st_read_fully(st_netfd_t fd, void *buf, size_t nbyte,
|
||||||
st_utime_t timeout);
|
st_utime_t timeout);
|
||||||
extern int st_read_resid(st_netfd_t fd, void *buf, size_t *resid,
|
extern int st_read_resid(st_netfd_t fd, void *buf, size_t *resid,
|
||||||
st_utime_t timeout);
|
st_utime_t timeout);
|
||||||
extern ssize_t st_readv(st_netfd_t fd, const struct iovec *iov, int iov_size,
|
extern ssize_t st_readv(st_netfd_t fd, const struct iovec *iov, int iov_size,
|
||||||
st_utime_t timeout);
|
st_utime_t timeout);
|
||||||
extern int st_readv_resid(st_netfd_t fd, struct iovec **iov, int *iov_size,
|
extern int st_readv_resid(st_netfd_t fd, struct iovec **iov, int *iov_size,
|
||||||
st_utime_t timeout);
|
st_utime_t timeout);
|
||||||
extern ssize_t st_write(st_netfd_t fd, const void *buf, size_t nbyte,
|
extern ssize_t st_write(st_netfd_t fd, const void *buf, size_t nbyte,
|
||||||
st_utime_t timeout);
|
st_utime_t timeout);
|
||||||
extern int st_write_resid(st_netfd_t fd, const void *buf, size_t *resid,
|
extern int st_write_resid(st_netfd_t fd, const void *buf, size_t *resid,
|
||||||
st_utime_t timeout);
|
st_utime_t timeout);
|
||||||
extern ssize_t st_writev(st_netfd_t fd, const struct iovec *iov, int iov_size,
|
extern ssize_t st_writev(st_netfd_t fd, const struct iovec *iov, int iov_size,
|
||||||
st_utime_t timeout);
|
st_utime_t timeout);
|
||||||
extern int st_writev_resid(st_netfd_t fd, struct iovec **iov, int *iov_size,
|
extern int st_writev_resid(st_netfd_t fd, struct iovec **iov, int *iov_size,
|
||||||
st_utime_t timeout);
|
st_utime_t timeout);
|
||||||
extern int st_recvfrom(st_netfd_t fd, void *buf, int len,
|
extern int st_recvfrom(st_netfd_t fd, void *buf, int len,
|
||||||
struct sockaddr *from, int *fromlen,
|
struct sockaddr *from, int *fromlen,
|
||||||
st_utime_t timeout);
|
st_utime_t timeout);
|
||||||
extern int st_sendto(st_netfd_t fd, const void *msg, int len,
|
extern int st_sendto(st_netfd_t fd, const void *msg, int len,
|
||||||
const struct sockaddr *to, int tolen, st_utime_t timeout);
|
const struct sockaddr *to, int tolen, st_utime_t timeout);
|
||||||
extern int st_recvmsg(st_netfd_t fd, struct msghdr *msg, int flags,
|
extern int st_recvmsg(st_netfd_t fd, struct msghdr *msg, int flags,
|
||||||
st_utime_t timeout);
|
st_utime_t timeout);
|
||||||
extern int st_sendmsg(st_netfd_t fd, const struct msghdr *msg, int flags,
|
extern int st_sendmsg(st_netfd_t fd, const struct msghdr *msg, int flags,
|
||||||
st_utime_t timeout);
|
st_utime_t timeout);
|
||||||
extern st_netfd_t st_open(const char *path, int oflags, mode_t mode);
|
extern st_netfd_t st_open(const char *path, int oflags, mode_t mode);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
|
@ -94,7 +94,7 @@ int st_poll(struct pollfd *pds, int npds, st_utime_t timeout)
|
||||||
/* Count the number of ready descriptors */
|
/* Count the number of ready descriptors */
|
||||||
for (pd = pds; pd < epd; pd++) {
|
for (pd = pds; pd < epd; pd++) {
|
||||||
if (pd->revents)
|
if (pd->revents)
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ int st_init(void)
|
||||||
* Create idle thread
|
* Create idle thread
|
||||||
*/
|
*/
|
||||||
_st_this_vp.idle_thread = st_thread_create(_st_idle_thread_start,
|
_st_this_vp.idle_thread = st_thread_create(_st_idle_thread_start,
|
||||||
NULL, 0, 0);
|
NULL, 0, 0);
|
||||||
if (!_st_this_vp.idle_thread)
|
if (!_st_this_vp.idle_thread)
|
||||||
return -1;
|
return -1;
|
||||||
_st_this_vp.idle_thread->flags = _ST_FL_IDLE_THREAD;
|
_st_this_vp.idle_thread->flags = _ST_FL_IDLE_THREAD;
|
||||||
|
@ -176,7 +176,7 @@ int st_init(void)
|
||||||
* Initialize primordial thread
|
* Initialize primordial thread
|
||||||
*/
|
*/
|
||||||
thread = (_st_thread_t *) calloc(1, sizeof(_st_thread_t) +
|
thread = (_st_thread_t *) calloc(1, sizeof(_st_thread_t) +
|
||||||
(ST_KEYS_MAX * sizeof(void *)));
|
(ST_KEYS_MAX * sizeof(void *)));
|
||||||
if (!thread)
|
if (!thread)
|
||||||
return -1;
|
return -1;
|
||||||
thread->private_data = (void **) (thread + 1);
|
thread->private_data = (void **) (thread + 1);
|
||||||
|
@ -414,33 +414,33 @@ static void heap_delete(_st_thread_t *thread) {
|
||||||
_st_thread_t *y; /* The younger child */
|
_st_thread_t *y; /* The younger child */
|
||||||
int index_tmp;
|
int index_tmp;
|
||||||
if (t->left == NULL)
|
if (t->left == NULL)
|
||||||
break;
|
break;
|
||||||
else if (t->right == NULL)
|
else if (t->right == NULL)
|
||||||
y = t->left;
|
y = t->left;
|
||||||
else if (t->left->due < t->right->due)
|
else if (t->left->due < t->right->due)
|
||||||
y = t->left;
|
y = t->left;
|
||||||
else
|
else
|
||||||
y = t->right;
|
y = t->right;
|
||||||
if (t->due > y->due) {
|
if (t->due > y->due) {
|
||||||
_st_thread_t *tl = y->left;
|
_st_thread_t *tl = y->left;
|
||||||
_st_thread_t *tr = y->right;
|
_st_thread_t *tr = y->right;
|
||||||
*p = y;
|
*p = y;
|
||||||
if (y == t->left) {
|
if (y == t->left) {
|
||||||
y->left = t;
|
y->left = t;
|
||||||
y->right = t->right;
|
y->right = t->right;
|
||||||
p = &y->left;
|
p = &y->left;
|
||||||
} else {
|
} else {
|
||||||
y->left = t->left;
|
y->left = t->left;
|
||||||
y->right = t;
|
y->right = t;
|
||||||
p = &y->right;
|
p = &y->right;
|
||||||
}
|
}
|
||||||
t->left = tl;
|
t->left = tl;
|
||||||
t->right = tr;
|
t->right = tr;
|
||||||
index_tmp = t->heap_index;
|
index_tmp = t->heap_index;
|
||||||
t->heap_index = y->heap_index;
|
t->heap_index = y->heap_index;
|
||||||
y->heap_index = index_tmp;
|
y->heap_index = index_tmp;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -518,7 +518,7 @@ void st_thread_interrupt(_st_thread_t *thread)
|
||||||
|
|
||||||
|
|
||||||
_st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg,
|
_st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg,
|
||||||
int joinable, int stk_size)
|
int joinable, int stk_size)
|
||||||
{
|
{
|
||||||
_st_thread_t *thread;
|
_st_thread_t *thread;
|
||||||
_st_stack_t *stack;
|
_st_stack_t *stack;
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
|
|
||||||
|
|
||||||
/* 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);
|
_st_clist_t _st_free_stacks = ST_INIT_STATIC_CLIST(&_st_free_stacks);
|
||||||
int _st_num_free_stacks = 0;
|
int _st_num_free_stacks = 0;
|
||||||
|
|
|
@ -143,7 +143,7 @@ int st_usleep(st_utime_t usecs)
|
||||||
int st_sleep(int secs)
|
int st_sleep(int secs)
|
||||||
{
|
{
|
||||||
return st_usleep((secs >= 0) ? secs * (st_utime_t) 1000000LL :
|
return st_usleep((secs >= 0) ? secs * (st_utime_t) 1000000LL :
|
||||||
ST_UTIME_NO_TIMEOUT);
|
ST_UTIME_NO_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -230,13 +230,13 @@ static int _st_cond_signal(_st_cond_t *cvar, int broadcast)
|
||||||
thread = _ST_THREAD_WAITQ_PTR(q);
|
thread = _ST_THREAD_WAITQ_PTR(q);
|
||||||
if (thread->state == _ST_ST_COND_WAIT) {
|
if (thread->state == _ST_ST_COND_WAIT) {
|
||||||
if (thread->flags & _ST_FL_ON_SLEEPQ)
|
if (thread->flags & _ST_FL_ON_SLEEPQ)
|
||||||
_ST_DEL_SLEEPQ(thread);
|
_ST_DEL_SLEEPQ(thread);
|
||||||
|
|
||||||
/* Make thread runnable */
|
/* Make thread runnable */
|
||||||
thread->state = _ST_ST_RUNNABLE;
|
thread->state = _ST_ST_RUNNABLE;
|
||||||
_ST_ADD_RUNQ(thread);
|
_ST_ADD_RUNQ(thread);
|
||||||
if (!broadcast)
|
if (!broadcast)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue