From ef05b2681502aa8b4bdca1350feecc2c11136aac Mon Sep 17 00:00:00 2001 From: Heng Li Date: Thu, 10 Oct 2013 00:18:59 -0400 Subject: [PATCH] test C++ --- kthread.c | 1 - kthread.h | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/kthread.c b/kthread.c index 40fb353..789ad69 100644 --- 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; diff --git a/kthread.h b/kthread.h index bc2e5c7..83f4249 100644 --- 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 -- 2.47.3