add stralloc_APPEND
use atomic updates for iom->working
This commit is contained in:
parent
a8fa432152
commit
3873bab74b
@ -39,7 +39,7 @@ int iom_wait(iomux_t* c,int64* s,unsigned int* revents,unsigned long timeout) {
|
|||||||
r=epoll_wait(c->ctx, ee, freeslots, timeout);
|
r=epoll_wait(c->ctx, ee, freeslots, timeout);
|
||||||
if (r<=0) {
|
if (r<=0) {
|
||||||
/* we ran into a timeout, so let someone else take over */
|
/* we ran into a timeout, so let someone else take over */
|
||||||
c->working=0;
|
if (__sync_val_compare_and_swap(&c->working,1,0)==-2) return -2;
|
||||||
#ifdef __dietlibc__
|
#ifdef __dietlibc__
|
||||||
cnd_broadcast(&c->sem);
|
cnd_broadcast(&c->sem);
|
||||||
#else
|
#else
|
||||||
@ -68,7 +68,7 @@ int iom_wait(iomux_t* c,int64* s,unsigned int* revents,unsigned long timeout) {
|
|||||||
int r=kevent(c->ctx, 0, 0, &kev, freeslots, &ts);
|
int r=kevent(c->ctx, 0, 0, &kev, freeslots, &ts);
|
||||||
if (r<=0) {
|
if (r<=0) {
|
||||||
/* we ran into a timeout, so let someone else take over */
|
/* we ran into a timeout, so let someone else take over */
|
||||||
c->working=0;
|
if (__sync_val_compare_and_swap(&c->working,1,0)==-2) return -2;
|
||||||
#ifdef __dietlibc__
|
#ifdef __dietlibc__
|
||||||
cnd_broadcast(&c->sem);
|
cnd_broadcast(&c->sem);
|
||||||
#else
|
#else
|
||||||
@ -97,7 +97,7 @@ int iom_wait(iomux_t* c,int64* s,unsigned int* revents,unsigned long timeout) {
|
|||||||
Either there are other events left, or we need one of them to
|
Either there are other events left, or we need one of them to
|
||||||
wake up and call epoll_wait/kevent next, because we aren't
|
wake up and call epoll_wait/kevent next, because we aren't
|
||||||
doing it anymore */
|
doing it anymore */
|
||||||
c->working=0;
|
if (__sync_val_compare_and_swap(&c->working,1,0)==-2) return -2;
|
||||||
#ifdef __dietlibc__
|
#ifdef __dietlibc__
|
||||||
cnd_signal(&c->sem);
|
cnd_signal(&c->sem);
|
||||||
#else
|
#else
|
||||||
|
@ -133,3 +133,7 @@ struct eventpacket {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define debug_printf(x)
|
#define debug_printf(x)
|
||||||
|
|
||||||
|
struct iom_entry {
|
||||||
|
void* cookie;
|
||||||
|
};
|
||||||
|
16
stralloc.h
16
stralloc.h
@ -82,6 +82,22 @@ int stralloc_cat(stralloc* sa,const stralloc* in);
|
|||||||
* in sa. It is the same as stralloc_catb(&sa,in,1). */
|
* in sa. It is the same as stralloc_catb(&sa,in,1). */
|
||||||
int stralloc_append(stralloc* sa,const char* in); /* beware: this takes a pointer to 1 char */
|
int stralloc_append(stralloc* sa,const char* in); /* beware: this takes a pointer to 1 char */
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#define stralloc_APPEND(sa,in) \
|
||||||
|
( ((sa)->len != (sa)->a) \
|
||||||
|
? ( (sa)->s[(sa)->len++] = (*in), 1 ) \
|
||||||
|
: buffer_put((s),&(c),1) \
|
||||||
|
)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static inline int stralloc_APPEND(stralloc* sa,const char* in) {
|
||||||
|
if (sa->len<sa->a) {
|
||||||
|
sa->s[sa->len++]=*in;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return stralloc_append(sa,in);
|
||||||
|
}
|
||||||
|
|
||||||
/* stralloc_starts returns 1 if the \0-terminated string in "in", without
|
/* stralloc_starts returns 1 if the \0-terminated string in "in", without
|
||||||
* the terminating \0, is a prefix of the string stored in sa. Otherwise
|
* the terminating \0, is a prefix of the string stored in sa. Otherwise
|
||||||
* it returns 0. sa must already be allocated. */
|
* it returns 0. sa must already be allocated. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user