Small cleanups and comment additions. Don't sleep after proof of work found.
This commit is contained in:
parent
ea6c1126ec
commit
67d3c91317
1 changed files with 7 additions and 19 deletions
26
cpu-miner.c
26
cpu-miner.c
|
@ -29,7 +29,6 @@
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
STAT_SLEEP_INTERVAL = 10,
|
STAT_SLEEP_INTERVAL = 10,
|
||||||
POW_SLEEP_INTERVAL = 1,
|
|
||||||
STAT_CTR_INTERVAL = 10000000,
|
STAT_CTR_INTERVAL = 10000000,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,7 +42,7 @@ static uint64_t hash_ctr;
|
||||||
|
|
||||||
static struct argp_option options[] = {
|
static struct argp_option options[] = {
|
||||||
{ "threads", 't', "N", 0,
|
{ "threads", 't', "N", 0,
|
||||||
"Number of miner threads" },
|
"Number of miner threads (default: 1)" },
|
||||||
{ "debug", 'D', NULL, 0,
|
{ "debug", 'D', NULL, 0,
|
||||||
"Enable debug output" },
|
"Enable debug output" },
|
||||||
{ "protocol-dump", 'P', NULL, 0,
|
{ "protocol-dump", 'P', NULL, 0,
|
||||||
|
@ -76,17 +75,6 @@ struct work {
|
||||||
BIGNUM *target;
|
BIGNUM *target;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ___constant_swab32(x) ((u32)( \
|
|
||||||
(((u32)(x) & (u32)0x000000ffUL) << 24) | \
|
|
||||||
(((u32)(x) & (u32)0x0000ff00UL) << 8) | \
|
|
||||||
(((u32)(x) & (u32)0x00ff0000UL) >> 8) | \
|
|
||||||
(((u32)(x) & (u32)0xff000000UL) >> 24)))
|
|
||||||
|
|
||||||
static inline uint32_t swab32(uint32_t v)
|
|
||||||
{
|
|
||||||
return ___constant_swab32(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void databuf_free(struct data_buffer *db)
|
static void databuf_free(struct data_buffer *db)
|
||||||
{
|
{
|
||||||
if (!db)
|
if (!db)
|
||||||
|
@ -469,13 +457,9 @@ static void *miner_thread(void *dummy)
|
||||||
work->hash1, work->hash);
|
work->hash1, work->hash);
|
||||||
|
|
||||||
/* if nonce found, submit work */
|
/* if nonce found, submit work */
|
||||||
if (nonce) {
|
if (nonce)
|
||||||
submit_work(work);
|
submit_work(work);
|
||||||
|
|
||||||
fprintf(stderr, "sleeping, after proof-of-work...\n");
|
|
||||||
sleep(POW_SLEEP_INTERVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
work_free(work);
|
work_free(work);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -537,15 +521,18 @@ int main (int argc, char *argv[])
|
||||||
error_t aprc;
|
error_t aprc;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
/* parse command line */
|
||||||
aprc = argp_parse(&argp, argc, argv, 0, NULL, NULL);
|
aprc = argp_parse(&argp, argc, argv, 0, NULL, NULL);
|
||||||
if (aprc) {
|
if (aprc) {
|
||||||
fprintf(stderr, "argp_parse failed: %s\n", strerror(aprc));
|
fprintf(stderr, "argp_parse failed: %s\n", strerror(aprc));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set our priority to the highest (aka "nicest, least intrusive") */
|
||||||
if (setpriority(PRIO_PROCESS, 0, 19))
|
if (setpriority(PRIO_PROCESS, 0, 19))
|
||||||
perror("setpriority");
|
perror("setpriority");
|
||||||
|
|
||||||
|
/* start mining threads */
|
||||||
for (i = 0; i < opt_n_threads; i++) {
|
for (i = 0; i < opt_n_threads; i++) {
|
||||||
pthread_t t;
|
pthread_t t;
|
||||||
|
|
||||||
|
@ -554,11 +541,12 @@ int main (int argc, char *argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(1); /* don't pound server all at once */
|
sleep(1); /* don't pound RPC server all at once */
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "%d miner threads started.\n", opt_n_threads);
|
fprintf(stderr, "%d miner threads started.\n", opt_n_threads);
|
||||||
|
|
||||||
|
/* main loop */
|
||||||
while (program_running) {
|
while (program_running) {
|
||||||
sleep(STAT_SLEEP_INTERVAL);
|
sleep(STAT_SLEEP_INTERVAL);
|
||||||
calc_stats();
|
calc_stats();
|
||||||
|
|
Loading…
Add table
Reference in a new issue