Browse Source

Use has_pth flag instead of trying to mess with pthread internals

Luke Dashjr 12 years ago
parent
commit
9fb8b34e4e
4 changed files with 8 additions and 7 deletions
  1. 0 3
      compat.h
  2. 1 1
      miner.c
  3. 1 0
      miner.h
  4. 6 3
      util.c

+ 0 - 3
compat.h

@@ -140,9 +140,6 @@ typedef unsigned int uint;
 typedef long suseconds_t;
 #endif
 
-#define PTH(thr) ((thr)->pth.p)
-#else
-#define PTH(thr) ((thr)->pth)
 #endif /* WIN32 */
 
 #ifndef HAVE_PTHREAD_CANCEL

+ 1 - 1
miner.c

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

+ 1 - 0
miner.h

@@ -549,6 +549,7 @@ struct thr_info {
 	int		device_thread;
 	bool		primary_thread;
 
+	bool		has_pth;
 	pthread_t	pth;
 	struct thread_q	*q;
 	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)
 {
-	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)
@@ -938,9 +941,9 @@ void thr_info_cancel(struct thr_info *thr)
 	if (!thr)
 		return;
 
-	if (PTH(thr) != 0L) {
+	if (thr->has_pth) {
 		pthread_cancel(thr->pth);
-		PTH(thr) = 0L;
+		thr->has_pth = false;
 	}
 }