Commit b3ae0f168e10c4ee0371e22788a014f387e51b67

Kano 2013-03-31T21:54:32

find_work() to find work in devices work queue

diff --git a/cgminer.c b/cgminer.c
index f48082a..5a4d45b 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -5786,6 +5786,24 @@ struct work *get_queued(struct cgpu_info *cgpu)
 	return ret;
 }
 
+struct work *find_work(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen)
+{
+	struct work *work, *tmp, *ret = NULL;
+
+	rd_lock(&cgpu->qlock);
+	HASH_ITER(hh, cgpu->queued_work, work, tmp) {
+		if (work->queued &&
+		    memcmp(work->midstate, midstate, midstatelen) == 0 &&
+		    memcmp(work->data + offset, data, datalen) == 0) {
+			ret = work;
+			break;
+		}
+	}
+	rd_unlock(&cgpu->qlock);
+
+	return ret;
+}
+
 /* This function should be used by queued device drivers when they're sure
  * the work struct is no longer in use. */
 void work_completed(struct cgpu_info *cgpu, struct work *work)
diff --git a/miner.h b/miner.h
index b3ac3ae..ca38cc8 100644
--- a/miner.h
+++ b/miner.h
@@ -1183,6 +1183,7 @@ struct modminer_fpga_state {
 extern void get_datestamp(char *, struct timeval *);
 extern void submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
 extern struct work *get_queued(struct cgpu_info *cgpu);
+extern struct work *find_work(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
 extern void work_completed(struct cgpu_info *cgpu, struct work *work);
 extern void hash_queued_work(struct thr_info *mythr);
 extern void tailsprintf(char *f, const char *fmt, ...);