Small cleanups and comment additions. Don't sleep after proof of work found.
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
diff --git a/cpu-miner.c b/cpu-miner.c
index d88e7bb..38a9149 100644
--- a/cpu-miner.c
+++ b/cpu-miner.c
@@ -29,7 +29,6 @@
enum {
STAT_SLEEP_INTERVAL = 10,
- POW_SLEEP_INTERVAL = 1,
STAT_CTR_INTERVAL = 10000000,
};
@@ -43,7 +42,7 @@ static uint64_t hash_ctr;
static struct argp_option options[] = {
{ "threads", 't', "N", 0,
- "Number of miner threads" },
+ "Number of miner threads (default: 1)" },
{ "debug", 'D', NULL, 0,
"Enable debug output" },
{ "protocol-dump", 'P', NULL, 0,
@@ -76,17 +75,6 @@ struct work {
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)
{
if (!db)
@@ -469,13 +457,9 @@ static void *miner_thread(void *dummy)
work->hash1, work->hash);
/* if nonce found, submit work */
- if (nonce) {
+ if (nonce)
submit_work(work);
- fprintf(stderr, "sleeping, after proof-of-work...\n");
- sleep(POW_SLEEP_INTERVAL);
- }
-
work_free(work);
}
@@ -537,15 +521,18 @@ int main (int argc, char *argv[])
error_t aprc;
int i;
+ /* parse command line */
aprc = argp_parse(&argp, argc, argv, 0, NULL, NULL);
if (aprc) {
fprintf(stderr, "argp_parse failed: %s\n", strerror(aprc));
return 1;
}
+ /* set our priority to the highest (aka "nicest, least intrusive") */
if (setpriority(PRIO_PROCESS, 0, 19))
perror("setpriority");
+ /* start mining threads */
for (i = 0; i < opt_n_threads; i++) {
pthread_t t;
@@ -554,11 +541,12 @@ int main (int argc, char *argv[])
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);
+ /* main loop */
while (program_running) {
sleep(STAT_SLEEP_INTERVAL);
calc_stats();