Commit 1d8b477d96d16d5e191223f25dd97a47489a45ef

ckolivas 2014-06-28T00:17:59

Create a hashtable of work by uid as it's accepted by BMA

diff --git a/driver-bflsc.c b/driver-bflsc.c
index 81692a5..cef7dde 100644
--- a/driver-bflsc.c
+++ b/driver-bflsc.c
@@ -27,6 +27,7 @@
 #include "compat.h"
 #include "miner.h"
 #include "usbutils.h"
+#include "uthash.h"
 #include "driver-bflsc.h"
 
 int opt_bflsc_overheat = BFLSC_TEMP_OVERHEAT;
@@ -1679,6 +1680,7 @@ out:
 
 static bool bflsc28_queue_full(struct cgpu_info *bflsc)
 {
+	struct bflsc_info *sc_info = bflsc->device_data;
 	int created, queued = 0, create, i, offset;
 	struct work *base_work, *work, *works[10];
 	char *buf, *field, *ptr;
@@ -1765,6 +1767,7 @@ static bool bflsc28_queue_full(struct cgpu_info *bflsc)
 		goto out;
 	}
 	for (i = 0; i < queued; i++) {
+		struct bflsc_work *bwork, *oldbwork;
 		unsigned int uid;
 
 		work = works[i];
@@ -1776,9 +1779,19 @@ static bool bflsc28_queue_full(struct cgpu_info *bflsc)
 			goto out;
 		}
 		sscanf(field, "%04x", &uid);
-		/* FIXME: Do something useful with this uid */
-		applog(LOG_WARNING, "%s%d: Got work uid %u",
-		       bflsc->drv->name, bflsc->device_id, uid);
+		bwork = malloc(sizeof(struct bflsc_work));
+		bwork->id = uid;
+		bwork->work = work;
+
+		wr_lock(&bflsc->qlock);
+		HASH_REPLACE_INT(sc_info->bworks, id, bwork, oldbwork);
+		if (oldbwork) {
+			__work_completed(bflsc, oldbwork->work);
+			free(oldbwork);
+		}
+		if (i > 0)
+			__add_queued(bflsc, work);
+		wr_unlock(&bflsc->qlock);
 	}
 	if (queued < created)
 		ret = true;
diff --git a/driver-bflsc.h b/driver-bflsc.h
index 402314a..f1b4105 100644
--- a/driver-bflsc.h
+++ b/driver-bflsc.h
@@ -116,6 +116,12 @@ struct bflsc_dev {
 
 #define QUE_MAX_RESULTS 8
 
+struct bflsc_work {
+	UT_hash_handle hh;
+	int id;
+	struct work *work;
+};
+
 struct bflsc_info {
 	enum driver_version driver_version;
 	pthread_rwlock_t stat_lock;
@@ -144,6 +150,8 @@ struct bflsc_info {
 	int flush_size;
 	// count of given size, [+2] is for any > QUE_MAX_RESULTS
 	uint64_t result_size[QUE_MAX_RESULTS+2];
+
+	struct bflsc_work *bworks;
 };
 
 #define BFLSC_XLINKHDR '@'