Browse Source

Abstract mutex_request code from X6500 driver into generic device API interface

Luke Dashjr 12 years ago
parent
commit
15813069fa
3 changed files with 28 additions and 10 deletions
  1. 20 0
      deviceapi.c
  2. 5 0
      deviceapi.h
  3. 3 10
      driver-x6500.c

+ 20 - 0
deviceapi.c

@@ -465,6 +465,26 @@ void do_notifier_select(struct thr_info *thr, struct timeval *tvp_timeout)
 		notifier_read(thr->work_restart_notifier);
 		notifier_read(thr->work_restart_notifier);
 }
 }
 
 
+void cgpu_setup_control_requests(struct cgpu_info * const cgpu)
+{
+	mutex_init(&cgpu->device_mutex);
+	notifier_init(cgpu->thr[0]->mutex_request);
+	pthread_cond_init(&cgpu->device_cond, NULL);
+}
+
+void cgpu_request_control(struct cgpu_info * const cgpu)
+{
+	mutex_lock(&cgpu->device_mutex);
+	notifier_wake(cgpu->thr[0]->mutex_request);
+	pthread_cond_wait(&cgpu->device_cond, &cgpu->device_mutex);
+}
+
+void cgpu_release_control(struct cgpu_info * const cgpu)
+{
+	pthread_cond_signal(&cgpu->device_cond);
+	mutex_unlock(&cgpu->device_mutex);
+}
+
 static
 static
 void _minerloop_setup(struct thr_info *mythr)
 void _minerloop_setup(struct thr_info *mythr)
 {
 {

+ 5 - 0
deviceapi.h

@@ -66,6 +66,11 @@ extern void minerloop_async(struct thr_info *);
 
 
 extern void minerloop_queue(struct thr_info *);
 extern void minerloop_queue(struct thr_info *);
 
 
+// Establishes a simple way for external threads to directly communicate with device
+extern void cgpu_setup_control_requests(struct cgpu_info *);
+extern void cgpu_request_control(struct cgpu_info *);
+extern void cgpu_release_control(struct cgpu_info *);
+
 extern void *miner_thread(void *);
 extern void *miner_thread(void *);
 
 
 extern void add_cgpu_live(void*);
 extern void add_cgpu_live(void*);

+ 3 - 10
driver-x6500.c

@@ -150,7 +150,6 @@ bool x6500_lowl_probe(const struct lowlevel_device_info * const info)
 	struct cgpu_info *x6500;
 	struct cgpu_info *x6500;
 	x6500 = calloc(1, sizeof(*x6500));
 	x6500 = calloc(1, sizeof(*x6500));
 	x6500->drv = &x6500_api;
 	x6500->drv = &x6500_api;
-	mutex_init(&x6500->device_mutex);
 	x6500->device_path = strdup(serial);
 	x6500->device_path = strdup(serial);
 	x6500->deven = DEV_ENABLED;
 	x6500->deven = DEV_ENABLED;
 	x6500->threads = 1;
 	x6500->threads = 1;
@@ -345,9 +344,7 @@ static bool x6500_thread_init(struct thr_info *thr)
 	struct cgpu_info *x6500 = thr->cgpu;
 	struct cgpu_info *x6500 = thr->cgpu;
 	struct ft232r_device_handle *ftdi = x6500->device_ft232r;
 	struct ft232r_device_handle *ftdi = x6500->device_ft232r;
 
 
-	// Setup mutex request based on notifier and pthread cond
-	notifier_init(thr->mutex_request);
-	pthread_cond_init(&x6500->device_cond, NULL);
+	cgpu_setup_control_requests(x6500);
 	
 	
 	// This works because x6500_thread_init is only called for the first processor now that they're all using the same thread
 	// This works because x6500_thread_init is only called for the first processor now that they're all using the same thread
 	for ( ; x6500; x6500 = x6500->next_proc)
 	for ( ; x6500; x6500 = x6500->next_proc)
@@ -544,13 +541,9 @@ static bool x6500_get_stats(struct cgpu_info *x6500)
 	if (x6500_all_idle(x6500)) {
 	if (x6500_all_idle(x6500)) {
 		struct cgpu_info *cgpu = x6500->device;
 		struct cgpu_info *cgpu = x6500->device;
 		// Getting temperature more efficiently while running
 		// Getting temperature more efficiently while running
-		pthread_mutex_t *mutexp = &cgpu->device_mutex;
-		mutex_lock(mutexp);
-		notifier_wake(cgpu->thr[0]->mutex_request);
-		pthread_cond_wait(&cgpu->device_cond, mutexp);
+		cgpu_request_control(cgpu);
 		x6500_get_temperature(x6500);
 		x6500_get_temperature(x6500);
-		pthread_cond_signal(&cgpu->device_cond);
-		mutex_unlock(mutexp);
+		cgpu_release_control(cgpu);
 	}
 	}
 
 
 	return true;
 	return true;