find_work() to find work in devices work queue
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
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, ...);