Browse Source

Merge commit '2fe415f' into cg_merges_20130513

Conflicts:
	miner.c
Luke Dashjr 12 years ago
parent
commit
371e900d45
4 changed files with 27 additions and 27 deletions
  1. 9 9
      api.c
  2. 2 2
      deviceapi.c
  3. 14 14
      miner.c
  4. 2 2
      miner.h

+ 9 - 9
api.c

@@ -1172,7 +1172,7 @@ static int numpgas()
 	int count = 0;
 	int count = 0;
 	int i;
 	int i;
 
 
-	mutex_lock(&devices_lock);
+	rd_lock(&devices_lock);
 	for (i = 0; i < total_devices; i++) {
 	for (i = 0; i < total_devices; i++) {
 #ifdef HAVE_OPENCL
 #ifdef HAVE_OPENCL
 		if (devices[i]->drv == &opencl_api)
 		if (devices[i]->drv == &opencl_api)
@@ -1184,7 +1184,7 @@ static int numpgas()
 #endif
 #endif
 		++count;
 		++count;
 	}
 	}
-	mutex_unlock(&devices_lock);
+	rd_unlock(&devices_lock);
 	return count;
 	return count;
 }
 }
 
 
@@ -1193,7 +1193,7 @@ static int pgadevice(int pgaid)
 	int count = 0;
 	int count = 0;
 	int i;
 	int i;
 
 
-	mutex_lock(&devices_lock);
+	rd_lock(&devices_lock);
 	for (i = 0; i < total_devices; i++) {
 	for (i = 0; i < total_devices; i++) {
 #ifdef HAVE_OPENCL
 #ifdef HAVE_OPENCL
 		if (devices[i]->drv == &opencl_api)
 		if (devices[i]->drv == &opencl_api)
@@ -1208,12 +1208,12 @@ static int pgadevice(int pgaid)
 			goto foundit;
 			goto foundit;
 	}
 	}
 
 
-	mutex_unlock(&devices_lock);
+	rd_unlock(&devices_lock);
 	return -1;
 	return -1;
 
 
 foundit:
 foundit:
 
 
-	mutex_unlock(&devices_lock);
+	rd_unlock(&devices_lock);
 	return i;
 	return i;
 }
 }
 #endif
 #endif
@@ -1487,14 +1487,14 @@ static void devdetail_an(struct io_data *io_data, struct cgpu_info *cgpu, bool i
 
 
 	cgpu->utility = cgpu->accepted / ( total_secs ? total_secs : 1 ) * 60;
 	cgpu->utility = cgpu->accepted / ( total_secs ? total_secs : 1 ) * 60;
 
 
-	mutex_lock(&devices_lock);
+	rd_lock(&devices_lock);
 	for (i = 0; i < total_devices; ++i) {
 	for (i = 0; i < total_devices; ++i) {
 		if (devices[i] == cgpu)
 		if (devices[i] == cgpu)
 			break;
 			break;
 		if (cgpu->devtype == devices[i]->devtype)
 		if (cgpu->devtype == devices[i]->devtype)
 			++n;
 			++n;
 	}
 	}
-	mutex_unlock(&devices_lock);
+	rd_unlock(&devices_lock);
 
 
 	root = api_add_int(root, (char*)cgpu->devtype, &n, true);
 	root = api_add_int(root, (char*)cgpu->devtype, &n, true);
 	root = api_add_device_identifier(root, cgpu);
 	root = api_add_device_identifier(root, cgpu);
@@ -1521,14 +1521,14 @@ static void devstatus_an(struct io_data *io_data, struct cgpu_info *cgpu, bool i
 
 
 	cgpu->utility = cgpu->accepted / ( total_secs ? total_secs : 1 ) * 60;
 	cgpu->utility = cgpu->accepted / ( total_secs ? total_secs : 1 ) * 60;
 
 
-	mutex_lock(&devices_lock);
+	rd_lock(&devices_lock);
 	for (i = 0; i < total_devices; ++i) {
 	for (i = 0; i < total_devices; ++i) {
 		if (devices[i] == cgpu)
 		if (devices[i] == cgpu)
 			break;
 			break;
 		if (cgpu->devtype == devices[i]->devtype)
 		if (cgpu->devtype == devices[i]->devtype)
 			++n;
 			++n;
 	}
 	}
-	mutex_unlock(&devices_lock);
+	rd_unlock(&devices_lock);
 
 
 	root = api_add_int(root, (char*)cgpu->devtype, &n, true);
 	root = api_add_int(root, (char*)cgpu->devtype, &n, true);
 	root = api_add_device_identifier(root, cgpu);
 	root = api_add_device_identifier(root, cgpu);

+ 2 - 2
deviceapi.c

@@ -597,7 +597,7 @@ bool add_cgpu(struct cgpu_info*cgpu)
 	strcpy(cgpu->proc_repr, cgpu->dev_repr);
 	strcpy(cgpu->proc_repr, cgpu->dev_repr);
 	sprintf(cgpu->proc_repr_ns, "%s%u", cgpu->drv->name, cgpu->device_id);
 	sprintf(cgpu->proc_repr_ns, "%s%u", cgpu->drv->name, cgpu->device_id);
 	
 	
-	mutex_lock(&devices_lock);
+	wr_lock(&devices_lock);
 	
 	
 	devices = realloc(devices, sizeof(struct cgpu_info *) * (total_devices + lpcount + 1));
 	devices = realloc(devices, sizeof(struct cgpu_info *) * (total_devices + lpcount + 1));
 	devices[total_devices++] = cgpu;
 	devices[total_devices++] = cgpu;
@@ -631,7 +631,7 @@ bool add_cgpu(struct cgpu_info*cgpu)
 		cgpu->threads -= (tpp * (lpcount - 1));
 		cgpu->threads -= (tpp * (lpcount - 1));
 	}
 	}
 	
 	
-	mutex_unlock(&devices_lock);
+	wr_unlock(&devices_lock);
 	
 	
 	return true;
 	return true;
 }
 }

+ 14 - 14
miner.c

@@ -218,8 +218,8 @@ static pthread_rwlock_t blk_lock;
 static pthread_mutex_t sshare_lock;
 static pthread_mutex_t sshare_lock;
 
 
 pthread_rwlock_t netacc_lock;
 pthread_rwlock_t netacc_lock;
-pthread_mutex_t mining_thr_lock;
-pthread_mutex_t devices_lock;
+pthread_rwlock_t mining_thr_lock;
+pthread_rwlock_t devices_lock;
 
 
 static pthread_mutex_t lp_lock;
 static pthread_mutex_t lp_lock;
 static pthread_cond_t lp_cond;
 static pthread_cond_t lp_cond;
@@ -418,9 +418,9 @@ struct thr_info *get_thread(int thr_id)
 {
 {
 	struct thr_info *thr;
 	struct thr_info *thr;
 
 
-	mutex_lock(&mining_thr_lock);
+	rd_lock(&mining_thr_lock);
 	thr = mining_thr[thr_id];
 	thr = mining_thr[thr_id];
-	mutex_unlock(&mining_thr_lock);
+	rd_unlock(&mining_thr_lock);
 	return thr;
 	return thr;
 }
 }
 
 
@@ -435,9 +435,9 @@ struct cgpu_info *get_devices(int id)
 {
 {
 	struct cgpu_info *cgpu;
 	struct cgpu_info *cgpu;
 
 
-	mutex_lock(&devices_lock);
+	rd_lock(&devices_lock);
 	cgpu = devices[id];
 	cgpu = devices[id];
-	mutex_unlock(&devices_lock);
+	rd_unlock(&devices_lock);
 	return cgpu;
 	return cgpu;
 }
 }
 
 
@@ -4541,7 +4541,7 @@ static void restart_threads(void)
 	/* Discard staged work that is now stale */
 	/* Discard staged work that is now stale */
 	discard_stale();
 	discard_stale();
 
 
-	mutex_lock(&mining_thr_lock);
+	rd_lock(&mining_thr_lock);
 	
 	
 	for (i = 0; i < mining_threads; i++)
 	for (i = 0; i < mining_threads; i++)
 	{
 	{
@@ -4555,7 +4555,7 @@ static void restart_threads(void)
 		notifier_wake(thr->work_restart_notifier);
 		notifier_wake(thr->work_restart_notifier);
 	}
 	}
 	
 	
-	mutex_unlock(&mining_thr_lock);
+	rd_unlock(&mining_thr_lock);
 }
 }
 
 
 static char *blkhashstr(unsigned char *hash)
 static char *blkhashstr(unsigned char *hash)
@@ -7559,10 +7559,10 @@ static void *watchdog_thread(void __maybe_unused *userdata)
 			applog(LOG_WARNING, "Will restart execution as scheduled at %02d:%02d",
 			applog(LOG_WARNING, "Will restart execution as scheduled at %02d:%02d",
 			       schedstart.tm.tm_hour, schedstart.tm.tm_min);
 			       schedstart.tm.tm_hour, schedstart.tm.tm_min);
 			sched_paused = true;
 			sched_paused = true;
-			mutex_lock(&mining_thr_lock);
+			rd_lock(&mining_thr_lock);
 			for (i = 0; i < mining_threads; i++)
 			for (i = 0; i < mining_threads; i++)
 				mining_thr[i]->pause = true;
 				mining_thr[i]->pause = true;
-			mutex_unlock(&mining_thr_lock);
+			rd_unlock(&mining_thr_lock);
 		} else if (sched_paused && should_run()) {
 		} else if (sched_paused && should_run()) {
 			applog(LOG_WARNING, "Restarting execution as per start time %02d:%02d scheduled",
 			applog(LOG_WARNING, "Restarting execution as per start time %02d:%02d scheduled",
 				schedstart.tm.tm_hour, schedstart.tm.tm_min);
 				schedstart.tm.tm_hour, schedstart.tm.tm_min);
@@ -8110,9 +8110,9 @@ static int device_line_id_count;
 void register_device(struct cgpu_info *cgpu)
 void register_device(struct cgpu_info *cgpu)
 {
 {
 	cgpu->deven = DEV_ENABLED;
 	cgpu->deven = DEV_ENABLED;
-	mutex_lock(&devices_lock);
+	wr_lock(&devices_lock);
 	devices[cgpu->cgminer_id = cgminer_id_count++] = cgpu;
 	devices[cgpu->cgminer_id = cgminer_id_count++] = cgpu;
-	mutex_unlock(&devices_lock);
+	wr_unlock(&devices_lock);
 	if (!cgpu->proc_id)
 	if (!cgpu->proc_id)
 		cgpu->device_line_id = device_line_id_count++;
 		cgpu->device_line_id = device_line_id_count++;
 	mining_threads += cgpu->threads ?: 1;
 	mining_threads += cgpu->threads ?: 1;
@@ -8207,8 +8207,8 @@ int main(int argc, char *argv[])
 	mutex_init(&sshare_lock);
 	mutex_init(&sshare_lock);
 	rwlock_init(&blk_lock);
 	rwlock_init(&blk_lock);
 	rwlock_init(&netacc_lock);
 	rwlock_init(&netacc_lock);
-	mutex_init(&mining_thr_lock);
-	mutex_init(&devices_lock);
+	rwlock_init(&mining_thr_lock);
+	rwlock_init(&devices_lock);
 
 
 	mutex_init(&lp_lock);
 	mutex_init(&lp_lock);
 	if (unlikely(pthread_cond_init(&lp_cond, NULL)))
 	if (unlikely(pthread_cond_init(&lp_cond, NULL)))

+ 2 - 2
miner.h

@@ -812,8 +812,8 @@ extern int opt_expiry;
 extern pthread_mutex_t hash_lock;
 extern pthread_mutex_t hash_lock;
 extern pthread_mutex_t console_lock;
 extern pthread_mutex_t console_lock;
 extern pthread_mutex_t ch_lock;
 extern pthread_mutex_t ch_lock;
-extern pthread_mutex_t mining_thr_lock;
-extern pthread_mutex_t devices_lock;
+extern pthread_rwlock_t mining_thr_lock;
+extern pthread_rwlock_t devices_lock;
 
 
 extern void thread_reportin(struct thr_info *thr);
 extern void thread_reportin(struct thr_info *thr);
 extern void thread_reportout(struct thr_info *);
 extern void thread_reportout(struct thr_info *);