Bladeren bron

and now make check runs on win32

Samuel Thibault 15 jaren geleden
bovenliggende
commit
a1c5981efa

+ 4 - 0
configure.ac

@@ -30,6 +30,7 @@ AC_PROG_SED
 AC_PROG_LN_S
 AC_PROG_F77
 
+AC_LIBTOOL_WIN32_DLL
 AC_PROG_LIBTOOL
 
 AC_PROG_INSTALL
@@ -40,6 +41,9 @@ AC_HEADER_STDC
 
 AC_C_RESTRICT
 
+AC_PATH_PROGS([STARPU_MS_LIB], [lib])
+AC_ARG_VAR([STARPU_MS_LIB], [Path to Microsoft's Visual Studio `lib' tool])
+
 # on Darwin, GCC targets i386 by default, so we don't have atomic ops
 case "$target" in
 i386-*darwin*) CFLAGS+=" -march=i686 " ;;

+ 31 - 10
include/pthread-win32/pthread.h

@@ -24,7 +24,6 @@
 
 /* TODO:
  * pthread_rwlock_*
- * pthread_mutex_trylock
  */
 
 #ifdef __cplusplus
@@ -40,10 +39,18 @@ extern "C" {
 #include <sys/cygwin.h>
 #define setSystemErrno() errno = cygwin_internal(CW_GET_ERRNO_FROM_WINERROR, (GetLastError())
 #else
+#if 0
+#define setSystemErrno() do { fprintf(stderr,"%s:%d: win %d\n", __FILE__, __LINE__, GetLastError()); errno = EIO; } while (0)
+#else
 #define setSystemErrno() errno = EIO
 #endif
+#endif
 #define winPthreadAssertWindows(expr) do { if (!(expr)) { setSystemErrno(); return -1; } } while (0)
+#if 0
+#define winPthreadAssert(expr) do { if (!(expr)) { fprintf(stderr,"%s:%d: %d\n", __FILE__, __LINE__, errno); return -1; } } while (0)
+#else
 #define winPthreadAssert(expr) do { if (!(expr)) return -1; } while (0)
+#endif
 
 /***********
  * threads *
@@ -175,7 +182,7 @@ static inline int __pthread_mutex_alloc_concurrently (pthread_mutex_t *mutex) {
   winPthreadAssert(!pthread_mutex_lock(&mutex_init_mutex));
   /* Now we are the one that can initialize it */
   if (!*mutex)
-    winPthreadAssert(!pthread_mutex_init((pthread_mutex_t *) mutex,NULL));
+    winPthreadAssert(!pthread_mutex_init(mutex,NULL));
   winPthreadAssert(!pthread_mutex_unlock(&mutex_init_mutex));
   winPthreadAssertWindows(CloseHandle(mutex_init_mutex));
   return 0;
@@ -216,6 +223,7 @@ static inline int pthread_mutex_trylock (pthread_mutex_t *mutex) {
 
 static inline int pthread_mutex_destroy (pthread_mutex_t *mutex) {
   winPthreadAssertWindows(CloseHandle(*mutex));
+  *mutex = INVALID_HANDLE_VALUE;
   return 0;
 }
 
@@ -254,19 +262,22 @@ static inline int pthread_cond_init (pthread_cond_t *cond, const pthread_condatt
     errno = EINVAL;
     return -1;
   }
-  winPthreadAssertWindows(cond->sem = CreateSemaphore(NULL, 1, 1, NULL));
+  winPthreadAssertWindows(cond->sem = CreateSemaphore(NULL, 0, MAXLONG, NULL));
   cond->nbwait = 0;
   return 0;
 }
 
 static inline int pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *time) {
+  if (!cond->sem)
+    winPthreadAssert(!pthread_cond_init(cond,NULL));
   cond->nbwait++;
-  winPthreadAssert(pthread_mutex_unlock(mutex));
+  winPthreadAssert(!pthread_mutex_unlock(mutex));
 again:
   switch (WaitForSingleObject(cond->sem, time->tv_sec*1000+time->tv_nsec/1000)) {
     default:
     case WAIT_FAILED:
       setSystemErrno();
+      winPthreadAssert(!pthread_mutex_lock(mutex));
       return -1;
     case WAIT_TIMEOUT:
       goto again;
@@ -274,18 +285,21 @@ again:
     case WAIT_OBJECT_0:
       break;
   }
-  winPthreadAssert(pthread_mutex_lock(mutex));
+  winPthreadAssert(!pthread_mutex_lock(mutex));
   cond->nbwait--;
   return 0;
 }
 
 static inline int pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) {
+  if (!cond->sem)
+    winPthreadAssert(!pthread_cond_init(cond,NULL));
   cond->nbwait++;
-  winPthreadAssert(pthread_mutex_unlock(mutex));
+  winPthreadAssert(!pthread_mutex_unlock(mutex));
 again:
   switch (WaitForSingleObject(cond->sem, INFINITE)) {
     case WAIT_FAILED:
       setSystemErrno();
+      winPthreadAssert(!pthread_mutex_lock(mutex));
       return -1;
     case WAIT_TIMEOUT:
       goto again;
@@ -293,24 +307,31 @@ again:
     case WAIT_OBJECT_0:
       break;
   }
-  winPthreadAssert(pthread_mutex_lock(mutex));
+  winPthreadAssert(!pthread_mutex_lock(mutex));
   cond->nbwait--;
   return 0;
 }
 
 static inline int pthread_cond_signal (pthread_cond_t *cond) {
+  if (!cond->sem)
+    winPthreadAssert(!pthread_cond_init(cond,NULL));
   if (cond->nbwait)
     ReleaseSemaphore(cond->sem, 1, NULL);
   return 0;
 }
 
 static inline int pthread_cond_broadcast (pthread_cond_t *cond) {
+  if (!cond->sem)
+    winPthreadAssert(!pthread_cond_init(cond,NULL));
   ReleaseSemaphore(cond->sem, cond->nbwait, NULL);
   return 0;
 }
 
 static inline int pthread_cond_destroy (pthread_cond_t *cond) {
-  winPthreadAssertWindows(CloseHandle(cond->sem));
+  if (cond->sem) {
+    winPthreadAssertWindows(CloseHandle(cond->sem));
+    cond->sem = NULL;
+  }
   return 0;
 }
 
@@ -326,12 +347,12 @@ typedef struct {
 } pthread_once_t;
 
 static inline int pthread_once (pthread_once_t *once, void (*oncefun)(void)) {
-  pthread_mutex_lock(&once->mutex);
+  winPthreadAssert(pthread_mutex_lock(&once->mutex));
   if (!once->done) {
     oncefun();
     once->done = 1;
   }
-  pthread_mutex_unlock(&once->mutex);
+  winPthreadAssert(!pthread_mutex_unlock(&once->mutex));
   return 0;
 }
 

+ 1 - 1
include/pthread-win32/semaphore.h

@@ -54,7 +54,7 @@ static inline int do_sem_wait(sem_t *sem, DWORD timeout) {
 #define sem_trywait(sem) do_sem_wait(sem, 0)
 
 static inline int sem_post(sem_t *sem) {
-  winPthreadAssertWindows(ReleaseSemaphore(*sem, 0, NULL));
+  winPthreadAssertWindows(ReleaseSemaphore(*sem, 1, NULL));
   return 0;
 }
 

+ 5 - 6
include/starpu-util.h

@@ -51,10 +51,9 @@ extern "C" {
 #define STARPU_LIKELY(expr)            (__builtin_expect(!!(expr),1))
 
 #if defined(__i386__) || defined(__x86_64__)
-static inline unsigned starpu_cmpxchg(unsigned *ptr, unsigned next) {
-	unsigned tmp = *ptr;
-	__asm__ __volatile__("lock cmpxchgl %2,%1": "+a" (tmp), "+m" (*ptr) : "q" (next) : "memory");
-	return tmp;
+static inline unsigned starpu_cmpxchg(unsigned *ptr, unsigned old, unsigned next) {
+	__asm__ __volatile__("lock cmpxchgl %2,%1": "+a" (old), "+m" (*ptr) : "q" (next) : "memory");
+	return old;
 }
 static inline unsigned starpu_xchg(unsigned *ptr, unsigned next) {
 	/* Note: xchg is always locked already */
@@ -70,7 +69,7 @@ static inline unsigned starpu_atomic_##name(unsigned *ptr, unsigned value) { \
 	while (1) { \
 		old = *ptr; \
 		next = expr; \
-		if (starpu_cmpxchg(ptr, next) == old) \
+		if (starpu_cmpxchg(ptr, old, next) == old) \
 			break; \
 	}; \
 	return expr; \
@@ -97,7 +96,7 @@ STARPU_ATOMIC_SOMETHING(or, old | value)
 #ifdef STARPU_HAVE_SYNC_BOOL_COMPARE_AND_SWAP
 #define STARPU_BOOL_COMPARE_AND_SWAP(ptr, old, value)  (__sync_bool_compare_and_swap ((ptr), (old), (value)))
 #elif defined(STARPU_HAVE_XCHG)
-#define STARPU_BOOL_COMPARE_AND_SWAP(ptr, old, value) (starpu_cmpxchg((ptr), (value)) == (old))
+#define STARPU_BOOL_COMPARE_AND_SWAP(ptr, old, value) (starpu_cmpxchg((ptr), (old), (value)) == (old))
 #else
 #error __sync_bool_compare_and_swap is not available
 #endif

+ 1 - 1
include/starpu_config.h.in

@@ -21,7 +21,7 @@
 
 #undef HAVE_MALLOC_H
 
-#undef STARPU_HAVE_SYNC_BUILTINS
+#undef STARPU_HAVE_SYNC_BOOL_COMPARE_AND_SWAP
 #undef STARPU_HAVE_SYNC_FETCH_AND_ADD
 #undef STARPU_HAVE_SYNC_FETCH_AND_OR
 #undef STARPU_HAVE_SYNC_LOCK_TEST_AND_SET

+ 1 - 0
src/Makefile.am

@@ -24,6 +24,7 @@ libstarpu_la_CPPFLAGS = -I$(top_srcdir)/include/
 
 libstarpu_la_CFLAGS = -W -Wall -Wextra $(HWLOC_CFLAGS)
 libstarpu_la_LIBADD = -lm $(HWLOC_LIBS)
+libstarpu_la_LDFLAGS = --no-undefined
 
 noinst_HEADERS = 						\
 	core/dependencies/data-concurrency.h			\

+ 5 - 1
src/common/utils.c

@@ -33,7 +33,11 @@ int starpu_mkpath(const char *s, mode_t mode)
 	int rv;
 
 	rv = -1;
-	if (strcmp(s, ".") == 0 || strcmp(s, "/") == 0)
+	if (strcmp(s, ".") == 0 || strcmp(s, "/") == 0
+#ifdef __MINGW32__
+		|| (s[0] && s[1] == ':' && s[2] == '/' && !s[3])
+#endif
+		)
 		return 0;
 
 	if ((path = strdup(s)) == NULL)

+ 6 - 0
src/core/perfmodel/perfmodel.c

@@ -153,6 +153,12 @@ void _starpu_get_perf_model_dir(char *path, size_t maxlen)
 #else
 	/* by default, we use $HOME/.starpu/sampling */
 	const char *home_path = getenv("HOME");
+	if (!home_path)
+		home_path = getenv("USERPROFILE");
+	if (!home_path) {
+		fprintf(stderr,"couldn't find a home place to put starpu data\n");
+		STARPU_ABORT();
+	}
 	snprintf(path, maxlen, "%s/.starpu/sampling/", home_path);
 #endif
 }

+ 9 - 0
src/core/workers.c

@@ -20,6 +20,10 @@
 #include <core/workers.h>
 #include <core/debug.h>
 
+#ifdef __MINGW32__
+#include <windows.h>
+#endif
+
 static pthread_key_t worker_key;
 
 static struct machine_config_s config;
@@ -212,6 +216,11 @@ int starpu_init(struct starpu_conf *user_conf)
 {
 	int ret;
 
+#ifdef __MINGW32__
+	WSADATA wsadata;
+	WSAStartup(MAKEWORD(1,0), &wsadata);
+#endif
+
 	srand(2008);
 	
 #ifdef USE_FXT