summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix von Leitner <felix-libowfat@fefe.de>2018-04-11 14:12:50 +0000
committerFelix von Leitner <felix-libowfat@fefe.de>2018-04-11 14:12:50 +0000
commit7bfadf4dea67e8862bc7aedeea62197b028ac1fa (patch)
treef279b50135ef4eae2382f40a485bfba00e6ea5c0
parentc4f30cc2c387c30572c8edf7f9b175e970e113bb (diff)
downloadlibowfat-7bfadf4dea67e8862bc7aedeea62197b028ac1fa.tar.gz
libowfat-7bfadf4dea67e8862bc7aedeea62197b028ac1fa.zip
add stralloc_APPEND
use atomic updates for iom->working
-rw-r--r--io/iom_wait.c6
-rw-r--r--io_internal.h4
-rw-r--r--stralloc.h16
3 files changed, 23 insertions, 3 deletions
diff --git a/io/iom_wait.c b/io/iom_wait.c
index e9187b0..33c956c 100644
--- a/io/iom_wait.c
+++ b/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
diff --git a/io_internal.h b/io_internal.h
index 2d7c1bf..6d37c11 100644
--- a/io_internal.h
+++ b/io_internal.h
@@ -133,3 +133,7 @@ struct eventpacket {
};
#define debug_printf(x)
+
+struct iom_entry {
+ void* cookie;
+};
diff --git a/stralloc.h b/stralloc.h
index a96bf2c..b328667 100644
--- a/stralloc.h
+++ b/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. */