mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-14 16:58:05 +00:00
Sort the blocks database in reverse order, allowing us to remove the first block without iterating over them. Output the block number to debug.
This commit is contained in:
parent
b34f36b700
commit
57c3b12f64
26
cgminer.c
26
cgminer.c
@ -2814,7 +2814,7 @@ static inline bool from_existing_block(struct work *work)
|
|||||||
|
|
||||||
static int block_sort(struct block *blocka, struct block *blockb)
|
static int block_sort(struct block *blocka, struct block *blockb)
|
||||||
{
|
{
|
||||||
return blockb->block_no - blocka->block_no;
|
return blocka->block_no - blockb->block_no;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_work_current(struct work *work)
|
static void test_work_current(struct work *work)
|
||||||
@ -2834,29 +2834,29 @@ static void test_work_current(struct work *work)
|
|||||||
* new block and set the current block details to this one */
|
* new block and set the current block details to this one */
|
||||||
if (!block_exists(hexstr)) {
|
if (!block_exists(hexstr)) {
|
||||||
struct block *s = calloc(sizeof(struct block), 1);
|
struct block *s = calloc(sizeof(struct block), 1);
|
||||||
|
int deleted_block = 0;
|
||||||
|
|
||||||
if (unlikely(!s))
|
if (unlikely(!s))
|
||||||
quit (1, "test_work_current OOM");
|
quit (1, "test_work_current OOM");
|
||||||
strcpy(s->hash, hexstr);
|
strcpy(s->hash, hexstr);
|
||||||
s->block_no = new_blocks++;
|
s->block_no = new_blocks++;
|
||||||
wr_lock(&blk_lock);
|
wr_lock(&blk_lock);
|
||||||
/* Only keep the last 6 blocks in memory since work from blocks
|
/* Only keep the last hour's worth of blocks in memory since
|
||||||
* before this is virtually impossible and we want to prevent
|
* work from blocks before this is virtually impossible and we
|
||||||
* memory usage from continually rising */
|
* want to prevent memory usage from continually rising */
|
||||||
if (HASH_COUNT(blocks) > 5) {
|
if (HASH_COUNT(blocks) > 6) {
|
||||||
struct block *blocka, *blockb;
|
struct block *oldblock;
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
HASH_SORT(blocks, block_sort);
|
HASH_SORT(blocks, block_sort);
|
||||||
HASH_ITER(hh, blocks, blocka, blockb) {
|
oldblock = blocks;
|
||||||
if (count++ < 6)
|
deleted_block = oldblock->block_no;
|
||||||
continue;
|
HASH_DEL(blocks, oldblock);
|
||||||
HASH_DEL(blocks, blocka);
|
free(oldblock);
|
||||||
free(blocka);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
HASH_ADD_STR(blocks, hash, s);
|
HASH_ADD_STR(blocks, hash, s);
|
||||||
wr_unlock(&blk_lock);
|
wr_unlock(&blk_lock);
|
||||||
|
if (deleted_block)
|
||||||
|
applog(LOG_DEBUG, "Deleted block %d from database", deleted_block);
|
||||||
set_curblock(hexstr, work->data);
|
set_curblock(hexstr, work->data);
|
||||||
if (unlikely(new_blocks == 1))
|
if (unlikely(new_blocks == 1))
|
||||||
goto out_free;
|
goto out_free;
|
||||||
|
Loading…
Reference in New Issue
Block a user