summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix von Leitner <felix-libowfat@fefe.de>2018-03-27 02:48:47 +0000
committerFelix von Leitner <felix-libowfat@fefe.de>2018-03-27 02:48:47 +0000
commitc4f30cc2c387c30572c8edf7f9b175e970e113bb (patch)
tree76aaf1892ddb607c52b4e69ac59b35c4a845b2c2
parent22408afb0e2117b1e1742e36519f9d18d8bc9c82 (diff)
downloadlibowfat-c4f30cc2c387c30572c8edf7f9b175e970e113bb.tar.gz
libowfat-c4f30cc2c387c30572c8edf7f9b175e970e113bb.zip
minimal demonstrator program for iom api
-rw-r--r--test/iom.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/iom.c b/test/iom.c
new file mode 100644
index 0000000..c0f2748
--- /dev/null
+++ b/test/iom.c
@@ -0,0 +1,60 @@
+#include "io.h"
+#include <stdio.h>
+#include <threads.h>
+#include <unistd.h>
+
+iomux_t c;
+
+int worker(void* arg) {
+ uintptr_t i=(uintptr_t)arg;
+ char buf[100];
+ int64 s;
+ int events;
+
+ write(1,buf,sprintf(buf,"starting thread %ld\n",i));
+
+ switch (iom_wait(&c,&s,&events,1000)) {
+ case -1:
+ perror("iom_wait");
+ return -1;
+ case 0:
+ write(1,buf,sprintf(buf,"timeout in thread %ld\n",i));
+ return 0;
+ case 1:
+ write(1,buf,sprintf(buf,"input found by thread %8ld\n",i));
+ return 1;
+ }
+
+ return 0;
+}
+
+int main() {
+ iom_init(&c);
+ if (iom_add(&c,0,IOM_READ)==-1) {
+ perror("iom_add");
+ return 1;
+ }
+ thrd_t x[4];
+ int i;
+ puts("launching threads");
+ for (i=0; i<4; ++i)
+ if (thrd_create(&x[i],worker,(void*)(uintptr_t)i)==-1) {
+ perror("thrd_create");
+ return 111;
+ }
+
+// sleep(1);
+// iom_abort(&c);
+
+ puts("joining threads");
+ int r;
+ for (i=0; i<4; ++i) {
+ if (thrd_join(x[i],&r)==-1) {
+ perror("thrd_join");
+ return 111;
+ }
+ printf("thread %d returned %d\n",i,r);
+ }
+
+ return 0;
+}