1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-11 07:17:58 +00:00

functions for handling work queues

This commit is contained in:
Kano 2013-04-01 00:35:50 +11:00
parent 8dd1ed2454
commit 131e20042a
2 changed files with 41 additions and 4 deletions

View File

@ -5786,12 +5786,32 @@ struct work *get_queued(struct cgpu_info *cgpu)
return ret; return ret;
} }
struct work *find_work(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen) /* This function is for including work in the given que hashtable.
* The calling function must lock access to the que if it is required. */
struct work *add_to_work_que(struct work *que, struct work *work)
{
HASH_ADD_INT(que, id, work);
return que;
}
/* This function is for removing work from the given que hashtable.
* The calling function must lock access to the que if it is required. */
struct work *del_from_work_que(struct work *que, struct work *work)
{
HASH_DEL(que, work);
return que;
}
/* This function is for finding an already queued work item in the
* given que hashtable. Code using this function must be able
* to handle NULL as a return which implies there is no matching work.
* The calling function must lock access to the que if it is required.
* The common values for midstatelen, offset, datalen are 32, 64, 12 */
struct work *find_work_bymidstate(struct work *que, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen)
{ {
struct work *work, *tmp, *ret = NULL; struct work *work, *tmp, *ret = NULL;
rd_lock(&cgpu->qlock); HASH_ITER(hh, que, work, tmp) {
HASH_ITER(hh, cgpu->queued_work, work, tmp) {
if (work->queued && if (work->queued &&
memcmp(work->midstate, midstate, midstatelen) == 0 && memcmp(work->midstate, midstate, midstatelen) == 0 &&
memcmp(work->data + offset, data, datalen) == 0) { memcmp(work->data + offset, data, datalen) == 0) {
@ -5799,6 +5819,20 @@ struct work *find_work(struct cgpu_info *cgpu, char *midstate, size_t midstatele
break; break;
} }
} }
return ret;
}
/* This function is for finding an already queued work item in the
* device's queued_work hashtable. Code using this function must be able
* to handle NULL as a return which implies there is no matching work.
* The common values for midstatelen, offset, datalen are 32, 64, 12 */
struct work *find_queued_work_bymidstate(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen)
{
struct work *ret;
rd_lock(&cgpu->qlock);
ret = find_work_bymidstate(cgpu->queued_work, midstate, midstatelen, data, offset, datalen);
rd_unlock(&cgpu->qlock); rd_unlock(&cgpu->qlock);
return ret; return ret;

View File

@ -1183,7 +1183,10 @@ struct modminer_fpga_state {
extern void get_datestamp(char *, struct timeval *); extern void get_datestamp(char *, struct timeval *);
extern void submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce); 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 *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 struct work *add_to_work_que(struct work *que, struct work *work);
extern struct work *del_from_work_que(struct work *que, struct work *work);
extern struct work *find_work_bymidstate(struct work *que, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
struct work *find_queued_work_bymidstate(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 work_completed(struct cgpu_info *cgpu, struct work *work);
extern void hash_queued_work(struct thr_info *mythr); extern void hash_queued_work(struct thr_info *mythr);
extern void tailsprintf(char *f, const char *fmt, ...); extern void tailsprintf(char *f, const char *fmt, ...);