Minor cleanups
This commit is contained in:
parent
c96b468d1c
commit
40fc3d06f9
3 changed files with 54 additions and 63 deletions
|
@ -18,7 +18,7 @@
|
|||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#if defined(WIN32) || defined(WIN64)
|
||||
#if defined(WIN32)
|
||||
#include <windows.h>
|
||||
#elif defined(sun) || defined(__sun)
|
||||
#include <sys/resource.h>
|
||||
|
@ -175,8 +175,7 @@ static struct option const options[] = {
|
|||
{ "user", 1, NULL, 'u' },
|
||||
{ "userpass", 1, NULL, 'O' },
|
||||
{ "version", 0, NULL, 'V' },
|
||||
|
||||
{ }
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
struct work {
|
||||
|
@ -906,7 +905,7 @@ int main(int argc, char *argv[])
|
|||
pthread_mutex_init(&stats_lock, NULL);
|
||||
pthread_mutex_init(&g_work_lock, NULL);
|
||||
|
||||
#if defined(WIN32) || defined(WIN64)
|
||||
#if defined(WIN32)
|
||||
SYSTEM_INFO sysinfo;
|
||||
GetSystemInfo(&sysinfo);
|
||||
num_processors = sysinfo.dwNumberOfProcessors;
|
||||
|
|
49
miner.h
49
miner.h
|
@ -89,12 +89,6 @@ enum {
|
|||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#endif
|
||||
|
||||
struct thr_info {
|
||||
int id;
|
||||
pthread_t pth;
|
||||
struct thread_q *q;
|
||||
};
|
||||
|
||||
static inline uint32_t swab32(uint32_t v)
|
||||
{
|
||||
#ifdef WANT_BUILTIN_BSWAP
|
||||
|
@ -136,43 +130,46 @@ static inline void le32enc(void *pp, uint32_t x)
|
|||
p[3] = (x >> 24) & 0xff;
|
||||
}
|
||||
|
||||
extern bool opt_debug;
|
||||
extern bool opt_protocol;
|
||||
|
||||
extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
|
||||
const char *rpc_req, bool, bool, int *);
|
||||
extern char *bin2hex(const unsigned char *p, size_t len);
|
||||
extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
|
||||
|
||||
extern unsigned char *scrypt_buffer_alloc();
|
||||
extern int scanhash_scrypt(int thr_id, uint32_t *pdata,
|
||||
unsigned char *scratchbuf, const uint32_t *ptarget,
|
||||
uint32_t max_nonce, unsigned long *hashes_done);
|
||||
|
||||
extern int
|
||||
timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y);
|
||||
|
||||
extern bool fulltest(const uint32_t *hash, const uint32_t *target);
|
||||
|
||||
extern int opt_timeout;
|
||||
extern bool want_longpoll;
|
||||
extern bool have_longpoll;
|
||||
extern char *opt_proxy;
|
||||
extern long opt_proxy_type;
|
||||
struct thread_q;
|
||||
struct thr_info {
|
||||
int id;
|
||||
pthread_t pth;
|
||||
struct thread_q *q;
|
||||
};
|
||||
|
||||
struct work_restart {
|
||||
volatile unsigned long restart;
|
||||
char padding[128 - sizeof(unsigned long)];
|
||||
};
|
||||
|
||||
extern pthread_mutex_t time_lock;
|
||||
extern bool opt_debug;
|
||||
extern bool opt_protocol;
|
||||
extern int opt_timeout;
|
||||
extern bool want_longpoll;
|
||||
extern bool have_longpoll;
|
||||
extern char *opt_proxy;
|
||||
extern long opt_proxy_type;
|
||||
extern bool use_syslog;
|
||||
extern pthread_mutex_t time_lock;
|
||||
extern struct thr_info *thr_info;
|
||||
extern int longpoll_thr_id;
|
||||
extern struct work_restart *work_restart;
|
||||
|
||||
extern void applog(int prio, const char *fmt, ...);
|
||||
extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
|
||||
const char *rpc_req, bool, bool, int *);
|
||||
extern char *bin2hex(const unsigned char *p, size_t len);
|
||||
extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
|
||||
extern int timeval_subtract(struct timeval *result, struct timeval *x,
|
||||
struct timeval *y);
|
||||
extern bool fulltest(const uint32_t *hash, const uint32_t *target);
|
||||
|
||||
struct thread_q;
|
||||
|
||||
extern struct thread_q *tq_new(void);
|
||||
extern void tq_free(struct thread_q *tq);
|
||||
extern bool tq_push(struct thread_q *tq, void *data);
|
||||
|
|
61
util.c
61
util.c
|
@ -33,12 +33,6 @@
|
|||
#include "miner.h"
|
||||
#include "elist.h"
|
||||
|
||||
#if JANSSON_MAJOR_VERSION >= 2
|
||||
#define JSON_LOADS(str, err_ptr) json_loads((str), 0, (err_ptr))
|
||||
#else
|
||||
#define JSON_LOADS(str, err_ptr) json_loads((str), (err_ptr))
|
||||
#endif
|
||||
|
||||
struct data_buffer {
|
||||
void *buf;
|
||||
size_t len;
|
||||
|
@ -262,14 +256,14 @@ json_t *json_rpc_call(CURL *curl, const char *url,
|
|||
{
|
||||
json_t *val, *err_val, *res_val;
|
||||
int rc;
|
||||
struct data_buffer all_data = { };
|
||||
struct data_buffer all_data = {0};
|
||||
struct upload_buffer upload_data;
|
||||
json_error_t err = { };
|
||||
json_error_t err;
|
||||
struct curl_slist *headers = NULL;
|
||||
char len_hdr[64];
|
||||
char curl_err_str[CURL_ERROR_SIZE];
|
||||
long timeout = opt_timeout;
|
||||
struct header_info hi = { };
|
||||
struct header_info hi = {0};
|
||||
bool lp_scanning = longpoll_scan && !have_longpoll;
|
||||
|
||||
/* it is assumed that 'curl' is freshly [re]initialized at this pt */
|
||||
|
@ -347,7 +341,11 @@ json_t *json_rpc_call(CURL *curl, const char *url,
|
|||
goto err_out;
|
||||
}
|
||||
|
||||
val = JSON_LOADS(all_data.buf, &err);
|
||||
#if JANSSON_VERSION_HEX >= 0x020000
|
||||
val = json_loads(all_data.buf, 0, &err);
|
||||
#else
|
||||
val = json_loads(all_data.buf, &err);
|
||||
#endif
|
||||
if (!val) {
|
||||
applog(LOG_ERR, "JSON decode failed(%d): %s", err.line, err.text);
|
||||
goto err_out;
|
||||
|
@ -360,8 +358,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
|
|||
}
|
||||
|
||||
/* JSON-RPC valid response returns a non-null 'result',
|
||||
* and a null 'error'.
|
||||
*/
|
||||
* and a null 'error'. */
|
||||
res_val = json_object_get(val, "result");
|
||||
err_val = json_object_get(val, "error");
|
||||
|
||||
|
@ -439,30 +436,28 @@ bool hex2bin(unsigned char *p, const char *hexstr, size_t len)
|
|||
/* Subtract the `struct timeval' values X and Y,
|
||||
storing the result in RESULT.
|
||||
Return 1 if the difference is negative, otherwise 0. */
|
||||
|
||||
int
|
||||
timeval_subtract (
|
||||
struct timeval *result, struct timeval *x, struct timeval *y)
|
||||
int timeval_subtract(struct timeval *result, struct timeval *x,
|
||||
struct timeval *y)
|
||||
{
|
||||
/* Perform the carry for the later subtraction by updating Y. */
|
||||
if (x->tv_usec < y->tv_usec) {
|
||||
int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
|
||||
y->tv_usec -= 1000000 * nsec;
|
||||
y->tv_sec += nsec;
|
||||
}
|
||||
if (x->tv_usec - y->tv_usec > 1000000) {
|
||||
int nsec = (x->tv_usec - y->tv_usec) / 1000000;
|
||||
y->tv_usec += 1000000 * nsec;
|
||||
y->tv_sec -= nsec;
|
||||
}
|
||||
/* Perform the carry for the later subtraction by updating Y. */
|
||||
if (x->tv_usec < y->tv_usec) {
|
||||
int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
|
||||
y->tv_usec -= 1000000 * nsec;
|
||||
y->tv_sec += nsec;
|
||||
}
|
||||
if (x->tv_usec - y->tv_usec > 1000000) {
|
||||
int nsec = (x->tv_usec - y->tv_usec) / 1000000;
|
||||
y->tv_usec += 1000000 * nsec;
|
||||
y->tv_sec -= nsec;
|
||||
}
|
||||
|
||||
/* Compute the time remaining to wait.
|
||||
`tv_usec' is certainly positive. */
|
||||
result->tv_sec = x->tv_sec - y->tv_sec;
|
||||
result->tv_usec = x->tv_usec - y->tv_usec;
|
||||
/* Compute the time remaining to wait.
|
||||
* `tv_usec' is certainly positive. */
|
||||
result->tv_sec = x->tv_sec - y->tv_sec;
|
||||
result->tv_usec = x->tv_usec - y->tv_usec;
|
||||
|
||||
/* Return 1 if result is negative. */
|
||||
return x->tv_sec < y->tv_sec;
|
||||
/* Return 1 if result is negative. */
|
||||
return x->tv_sec < y->tv_sec;
|
||||
}
|
||||
|
||||
bool fulltest(const uint32_t *hash, const uint32_t *target)
|
||||
|
|
Loading…
Reference in a new issue