瀏覽代碼

define a default implementation for pthread barrier functions for systems which do not provide it, such as Cygwin

Nathalie Furmento 14 年之前
父節點
當前提交
234a8432b7
共有 4 個文件被更改,包括 92 次插入0 次删除
  1. 1 0
      src/Makefile.am
  2. 50 0
      src/common/barrier.c
  3. 40 0
      src/common/barrier.h
  4. 1 0
      src/common/utils.h

+ 1 - 0
src/Makefile.am

@@ -102,6 +102,7 @@ noinst_HEADERS = 						\
 	profiling/profiling.h
 
 libstarpu_la_SOURCES = 						\
+	common/barrier.c					\
 	common/hash.c 						\
 	common/htable32.c					\
 	common/rwlock.c						\

+ 50 - 0
src/common/barrier.c

@@ -0,0 +1,50 @@
+/*
+ * StarPU
+ * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <common/barrier.h>
+
+int _starpu_barrier_init(_starpu_barrier_t *barrier, int count)
+{
+	barrier->count = count;
+	barrier->reached = 0;
+	pthread_mutex_init(&barrier->mutex,NULL);
+	pthread_cond_init(&barrier->cond,NULL);
+	return 0;
+}
+
+int _starpu_barrier_destroy(_starpu_barrier_t *barrier)
+{
+	pthread_mutex_destroy(&barrier->mutex);
+	pthread_cond_destroy(&barrier->cond);
+	return 0;
+}
+
+int _starpu_barrier_wait(_starpu_barrier_t *barrier)
+{
+	pthread_mutex_lock(&barrier->mutex);
+	barrier->reached++;
+	if (barrier->reached == barrier->count)
+	{
+		barrier->reached = 0;
+		pthread_cond_broadcast(&barrier->cond);
+	}
+	else
+	{
+		pthread_cond_wait(&barrier->cond,&barrier->mutex);
+	}
+	pthread_mutex_unlock(&barrier->mutex);
+	return 0;
+}

+ 40 - 0
src/common/barrier.h

@@ -0,0 +1,40 @@
+/*
+ * StarPU
+ * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#ifndef __COMMON_BARRIER_H__
+#define __COMMON_BARRIER_H__
+
+typedef struct {
+	int count;
+	int reached;
+	pthread_mutex_t mutex;
+	pthread_cond_t cond;
+} _starpu_barrier_t;
+
+int _starpu_barrier_init(_starpu_barrier_t *barrier, int count);
+
+int _starpu_barrier_destroy(_starpu_barrier_t *barrier);
+
+int _starpu_barrier_wait(_starpu_barrier_t *barrier);
+
+#if defined(__CYGWIN__)
+#define pthread_barrier_t _starpu_barrier_t
+#define pthread_barrier_init(b,a,c) _starpu_barrier_init(b, c)
+#define pthread_barrier_destroy(b) _starpu_barrier_destroy(b)
+#define pthread_barrier_wait(b) _starpu_barrier_wait(b)
+#endif /* __CYGWIN__ */
+
+#endif // __COMMON_BARRIER_H__

+ 1 - 0
src/common/utils.h

@@ -22,6 +22,7 @@
 #include <sys/stat.h>
 #include <string.h>
 #include <pthread.h>
+#include <common/barrier.h>
 
 #ifdef STARPU_VERBOSE
 #  define _STARPU_DEBUG(fmt, args ...) fprintf(stderr, "[starpu][%s] " fmt ,__func__ ,##args)