Browse Source

Merge branch 'winpthread' into cg_merges_20130523a

Luke Dashjr 12 years ago
parent
commit
19294f1238
5 changed files with 18 additions and 10 deletions
  1. 4 3
      compat.h
  2. 6 3
      configure.ac
  3. 1 1
      miner.c
  4. 1 0
      miner.h
  5. 6 3
      util.c

+ 4 - 3
compat.h

@@ -76,7 +76,9 @@ struct tm *localtime_convert(time_t t)
 {
 {
 	return localtime(&t);
 	return localtime(&t);
 }
 }
+#endif
 
 
+#ifndef HAVE_NANOSLEEP
 static inline int nanosleep(const struct timespec *req, struct timespec *rem)
 static inline int nanosleep(const struct timespec *req, struct timespec *rem)
 {
 {
 	struct timeval tstart;
 	struct timeval tstart;
@@ -108,7 +110,9 @@ static inline int nanosleep(const struct timespec *req, struct timespec *rem)
 	}
 	}
 	return 0;
 	return 0;
 }
 }
+#endif
 
 
+#ifdef WIN32
 static inline int sleep(unsigned int secs)
 static inline int sleep(unsigned int secs)
 {
 {
 	struct timespec req, rem;
 	struct timespec req, rem;
@@ -136,9 +140,6 @@ typedef unsigned int uint;
 typedef long suseconds_t;
 typedef long suseconds_t;
 #endif
 #endif
 
 
-#define PTH(thr) ((thr)->pth.p)
-#else
-#define PTH(thr) ((thr)->pth)
 #endif /* WIN32 */
 #endif /* WIN32 */
 
 
 #ifndef HAVE_PTHREAD_CANCEL
 #ifndef HAVE_PTHREAD_CANCEL

+ 6 - 3
configure.ac

@@ -150,7 +150,7 @@ AM_CONDITIONAL([HAVE_OPENCL], [test x$opencl = xyes])
 m4_define([BFG_PTHREAD_FLAG_CHECK],
 m4_define([BFG_PTHREAD_FLAG_CHECK],
 	AC_MSG_CHECKING([for $1])
 	AC_MSG_CHECKING([for $1])
 	for cflag in ' -pthread' ''; do
 	for cflag in ' -pthread' ''; do
-		for lib in ' -lpthread' ''; do
+		for lib in ' -lpthread' ' -lwinpthread' ''; do
 			CFLAGS="${save_CFLAGS}${cflag}"
 			CFLAGS="${save_CFLAGS}${cflag}"
 			LIBS="${save_LIBS}${lib}"
 			LIBS="${save_LIBS}${lib}"
 			AC_LINK_IFELSE([
 			AC_LINK_IFELSE([
@@ -173,6 +173,9 @@ m4_define([BFG_PTHREAD_FLAG_CHECK],
 			],[])
 			],[])
 		done
 		done
 	done
 	done
+	if test "x${found_pthread}" = "xfalse"; then
+		AC_MSG_RESULT([no])
+	fi
 )
 )
 
 
 save_CFLAGS="${CFLAGS}"
 save_CFLAGS="${CFLAGS}"
@@ -182,13 +185,13 @@ BFG_PTHREAD_FLAG_CHECK([pthread_cancel],[
 	AC_DEFINE([HAVE_PTHREAD_CANCEL], [1], [Define if you have a native pthread_cancel])
 	AC_DEFINE([HAVE_PTHREAD_CANCEL], [1], [Define if you have a native pthread_cancel])
 ])
 ])
 if test "x${found_pthread}" = "xfalse"; then
 if test "x${found_pthread}" = "xfalse"; then
-	AC_MSG_RESULT([no])
 	BFG_PTHREAD_FLAG_CHECK([pthread_create])
 	BFG_PTHREAD_FLAG_CHECK([pthread_create])
 	if test "x${found_pthread}" = "xfalse"; then
 	if test "x${found_pthread}" = "xfalse"; then
-		AC_MSG_RESULT([no])
 		AC_MSG_ERROR([Could not find pthread library - please install libpthread])
 		AC_MSG_ERROR([Could not find pthread library - please install libpthread])
 	fi
 	fi
 fi
 fi
+# check for nanosleep here, since it is provided by winpthread
+AC_CHECK_FUNCS([nanosleep])
 CFLAGS="${save_CFLAGS}"
 CFLAGS="${save_CFLAGS}"
 LIBS="${save_LIBS}"
 LIBS="${save_LIBS}"
 
 

+ 1 - 1
miner.c

@@ -5764,7 +5764,7 @@ static void *api_thread(void *userdata)
 
 
 	api(api_thr_id);
 	api(api_thr_id);
 
 
-	PTH(mythr) = 0L;
+	mythr->has_pth = false;
 
 
 	return NULL;
 	return NULL;
 }
 }

+ 1 - 0
miner.h

@@ -560,6 +560,7 @@ struct thr_info {
 	int		device_thread;
 	int		device_thread;
 	bool		primary_thread;
 	bool		primary_thread;
 
 
+	bool		has_pth;
 	pthread_t	pth;
 	pthread_t	pth;
 	struct thread_q	*q;
 	struct thread_q	*q;
 	struct cgpu_info *cgpu;
 	struct cgpu_info *cgpu;

+ 6 - 3
util.c

@@ -909,7 +909,10 @@ out:
 
 
 int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg)
 int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg)
 {
 {
-	return pthread_create(&thr->pth, attr, start, arg);
+	int rv = pthread_create(&thr->pth, attr, start, arg);
+	if (likely(!rv))
+		thr->has_pth = true;
+	return rv;
 }
 }
 
 
 void thr_info_freeze(struct thr_info *thr)
 void thr_info_freeze(struct thr_info *thr)
@@ -938,9 +941,9 @@ void thr_info_cancel(struct thr_info *thr)
 	if (!thr)
 	if (!thr)
 		return;
 		return;
 
 
-	if (PTH(thr) != 0L) {
+	if (thr->has_pth) {
 		pthread_cancel(thr->pth);
 		pthread_cancel(thr->pth);
-		PTH(thr) = 0L;
+		thr->has_pth = false;
 	}
 	}
 }
 }