Browse Source

add stralloc_APPEND

use atomic updates for iom->working
master
Felix von Leitner 4 years ago
parent
commit
7bfadf4dea
  1. 6
      io/iom_wait.c
  2. 4
      io_internal.h
  3. 16
      stralloc.h

6
io/iom_wait.c

@ -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);
if (r<=0) {
/* 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__
cnd_broadcast(&c->sem);
#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);
if (r<=0) {
/* 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__
cnd_broadcast(&c->sem);
#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
wake up and call epoll_wait/kevent next, because we aren't
doing it anymore */
c->working=0;
if (__sync_val_compare_and_swap(&c->working,1,0)==-2) return -2;
#ifdef __dietlibc__
cnd_signal(&c->sem);
#else

4
io_internal.h

@ -133,3 +133,7 @@ struct eventpacket {
};
#define debug_printf(x)
struct iom_entry {
void* cookie;
};

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). */
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
* the terminating \0, is a prefix of the string stored in sa. Otherwise
* it returns 0. sa must already be allocated. */

Loading…
Cancel
Save