]> git.kaiwu.me - klib.git/commitdiff
test C++ spawn-final
authorHeng Li <lh3@me.com>
Thu, 10 Oct 2013 04:18:59 +0000 (00:18 -0400)
committerHeng Li <lh3@me.com>
Thu, 10 Oct 2013 04:18:59 +0000 (00:18 -0400)
kthread.c
kthread.h

index 40fb353b0d72106dfc7b6c04813485c87c2609e9..789ad6994ba798ffaed6890d5a9d1b1fc00e4d6e 100644 (file)
--- a/kthread.c
+++ b/kthread.c
@@ -122,7 +122,6 @@ static void *slave(void *data)
                        w->type = 0; // wait
                        while (w->type == 0) pthread_cond_wait(&w->cv, &w->lock);
                        pthread_mutex_unlock(&w->lock);
-                       if (w->type == 2) break;
                } else do_task(w->t, sid);
        }
        return 0;
index bc2e5c731d143bde45418bd6f55777932f6c6bf1..83f4249c37da5cf91a4dc731c6a9d9bb684a7490 100644 (file)
--- a/kthread.h
+++ b/kthread.h
@@ -4,8 +4,24 @@
 struct kthread_t;
 typedef struct kthread_t kthread_t;
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 kthread_t *kt_init(int n_threads);
 void kt_spawn(kthread_t *t, int (*func)(void*,int,void*), void *shared, int n_items, int item_size, void *items);
 void kt_sync(kthread_t *t);
 
+#ifdef __cplusplus
+}
+#endif
+
+static inline void kt_for(int n_threads, int (*func)(void*,int,void*), void *shared, int n_items, int item_size, void *items)
+{
+       kthread_t *t;
+       t = kt_init(n_threads);
+       kt_spawn(t, func, shared, n_items, item_size, items);
+       kt_sync(t);
+}
+
 #endif