Browse Source

Restructure includes to only have ckpool instance and proc instance in ckpool.h

master
Con Kolivas 11 years ago
parent
commit
fd2c51bed3
  1. 1
      src/ckpool.c
  2. 160
      src/ckpool.h
  3. 154
      src/libckpool.h
  4. 2
      src/stratifier.c

1
src/ckpool.c

@ -23,7 +23,6 @@
#include "stratifier.h" #include "stratifier.h"
#include "connector.h" #include "connector.h"
/* Only global variable, to be used only by sighandler */
ckpool_t *global_ckp; ckpool_t *global_ckp;
static void *listener(void *arg) static void *listener(void *arg)

160
src/ckpool.h

@ -12,113 +12,57 @@
#include "config.h" #include "config.h"
#include <stdint.h> #include "libckpool.h"
#if HAVE_BYTESWAP_H struct proc_instance;
# include <byteswap.h> typedef struct proc_instance proc_instance_t;
#endif struct ckpool_instance;
typedef struct ckpool_instance ckpool_t;
#if HAVE_ENDIAN_H
# include <endian.h> struct proc_instance {
#elif HAVE_SYS_ENDIAN_H ckpool_t *ckp;
# include <sys/endian.h> unixsock_t us;
#endif char *processname;
char *sockname;
#ifndef bswap_16 int pid;
#define bswap_16 __builtin_bswap16 int (*process)(proc_instance_t *);
#define bswap_32 __builtin_bswap32 };
#define bswap_64 __builtin_bswap64
#endif struct ckpool_instance {
/* Main process name */
/* This assumes htobe32 is a macro in endian.h, and if it doesn't exist, then char *name;
* htobe64 also won't exist */ /* Directory where sockets are created */
#ifndef htobe32 char *socket_dir;
# if __BYTE_ORDER == __LITTLE_ENDIAN /* Filename of config file */
# define htole16(x) (x) char *config;
# define le16toh(x) (x) /* Logging level */
# define htole32(x) (x) int loglevel;
# define htole64(x) (x)
# define le32toh(x) (x) /* Process instance data of parent/child processes */
# define le64toh(x) (x) proc_instance_t main;
# define be32toh(x) bswap_32(x) proc_instance_t generator;
# define be64toh(x) bswap_64(x) proc_instance_t stratifier;
# define htobe16(x) bswap_16(x) proc_instance_t connector;
# define htobe32(x) bswap_32(x)
# define htobe64(x) bswap_64(x) /* Threads of main process */
# elif __BYTE_ORDER == __BIG_ENDIAN pthread_t pth_listener;
# define htole16(x) bswap_16(x) pthread_t pth_watchdog;
# define le16toh(x) bswap_16(x)
# define htole32(x) bswap_32(x) /* Bitcoind data */
# define le32toh(x) bswap_32(x) char *btcdurl;
# define le64toh(x) bswap_64(x) char *btcdauth;
# define htole64(x) bswap_64(x) char *btcdpass;
# define be32toh(x) (x) int blockpoll; // How frequently in ms to poll bitcoind for block updates
# define be64toh(x) (x)
# define htobe16(x) (x) /* Coinbase data */
# define htobe32(x) (x) char *btcaddress; // Address to mine to
# define htobe64(x) (x) char *btcsig; // Optional signature to add to coinbase
# endif
#endif /* Stratum options */
int update_interval; // Seconds between stratum updates
#define unlikely(expr) (__builtin_expect(!!(expr), 0)) char *serverurl;
#define likely(expr) (__builtin_expect(!!(expr), 1)) };
#define __maybe_unused __attribute__((unused))
#define uninitialised_var(x) x = x ckpool_t *global_ckp;
/* Typedefs are evil but we use this one so often... */
typedef unsigned char uchar;
typedef struct timeval tv_t;
typedef struct timespec ts_t;
static inline void swap_256(void *dest_p, const void *src_p)
{
uint32_t *dest = dest_p;
const uint32_t *src = src_p;
dest[0] = src[7];
dest[1] = src[6];
dest[2] = src[5];
dest[3] = src[4];
dest[4] = src[3];
dest[5] = src[2];
dest[6] = src[1];
dest[7] = src[0];
}
static inline void bswap_256(void *dest_p, const void *src_p)
{
uint32_t *dest = dest_p;
const uint32_t *src = src_p;
dest[0] = bswap_32(src[7]);
dest[1] = bswap_32(src[6]);
dest[2] = bswap_32(src[5]);
dest[3] = bswap_32(src[4]);
dest[4] = bswap_32(src[3]);
dest[5] = bswap_32(src[2]);
dest[6] = bswap_32(src[1]);
dest[7] = bswap_32(src[0]);
}
static inline void flip_32(void *dest_p, const void *src_p)
{
uint32_t *dest = dest_p;
const uint32_t *src = src_p;
int i;
for (i = 0; i < 8; i++)
dest[i] = bswap_32(src[i]);
}
static inline void flip_80(void *dest_p, const void *src_p)
{
uint32_t *dest = dest_p;
const uint32_t *src = src_p;
int i;
for (i = 0; i < 20; i++)
dest[i] = bswap_32(src[i]);
}
#endif /* CKPOOL_H */ #endif /* CKPOOL_H */

154
src/libckpool.h

@ -17,9 +17,116 @@
#include <pthread.h> #include <pthread.h>
#include <signal.h> #include <signal.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <syslog.h> #include <syslog.h>
#if HAVE_BYTESWAP_H
# include <byteswap.h>
#endif
#if HAVE_ENDIAN_H
# include <endian.h>
#elif HAVE_SYS_ENDIAN_H
# include <sys/endian.h>
#endif
#ifndef bswap_16
#define bswap_16 __builtin_bswap16
#define bswap_32 __builtin_bswap32
#define bswap_64 __builtin_bswap64
#endif
/* This assumes htobe32 is a macro in endian.h, and if it doesn't exist, then
* htobe64 also won't exist */
#ifndef htobe32
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define htole16(x) (x)
# define le16toh(x) (x)
# define htole32(x) (x)
# define htole64(x) (x)
# define le32toh(x) (x)
# define le64toh(x) (x)
# define be32toh(x) bswap_32(x)
# define be64toh(x) bswap_64(x)
# define htobe16(x) bswap_16(x)
# define htobe32(x) bswap_32(x)
# define htobe64(x) bswap_64(x)
# elif __BYTE_ORDER == __BIG_ENDIAN
# define htole16(x) bswap_16(x)
# define le16toh(x) bswap_16(x)
# define htole32(x) bswap_32(x)
# define le32toh(x) bswap_32(x)
# define le64toh(x) bswap_64(x)
# define htole64(x) bswap_64(x)
# define be32toh(x) (x)
# define be64toh(x) (x)
# define htobe16(x) (x)
# define htobe32(x) (x)
# define htobe64(x) (x)
# endif
#endif
#define unlikely(expr) (__builtin_expect(!!(expr), 0))
#define likely(expr) (__builtin_expect(!!(expr), 1))
#define __maybe_unused __attribute__((unused))
#define uninitialised_var(x) x = x
typedef unsigned char uchar;
typedef struct timeval tv_t;
typedef struct timespec ts_t;
static inline void swap_256(void *dest_p, const void *src_p)
{
uint32_t *dest = dest_p;
const uint32_t *src = src_p;
dest[0] = src[7];
dest[1] = src[6];
dest[2] = src[5];
dest[3] = src[4];
dest[4] = src[3];
dest[5] = src[2];
dest[6] = src[1];
dest[7] = src[0];
}
static inline void bswap_256(void *dest_p, const void *src_p)
{
uint32_t *dest = dest_p;
const uint32_t *src = src_p;
dest[0] = bswap_32(src[7]);
dest[1] = bswap_32(src[6]);
dest[2] = bswap_32(src[5]);
dest[3] = bswap_32(src[4]);
dest[4] = bswap_32(src[3]);
dest[5] = bswap_32(src[2]);
dest[6] = bswap_32(src[1]);
dest[7] = bswap_32(src[0]);
}
static inline void flip_32(void *dest_p, const void *src_p)
{
uint32_t *dest = dest_p;
const uint32_t *src = src_p;
int i;
for (i = 0; i < 8; i++)
dest[i] = bswap_32(src[i]);
}
static inline void flip_80(void *dest_p, const void *src_p)
{
uint32_t *dest = dest_p;
const uint32_t *src = src_p;
int i;
for (i = 0; i < 20; i++)
dest[i] = bswap_32(src[i]);
}
#define mutex_lock(_lock) _mutex_lock(_lock, __FILE__, __func__, __LINE__) #define mutex_lock(_lock) _mutex_lock(_lock, __FILE__, __func__, __LINE__)
#define mutex_unlock_noyield(_lock) _mutex_unlock_noyield(_lock, __FILE__, __func__, __LINE__) #define mutex_unlock_noyield(_lock) _mutex_unlock_noyield(_lock, __FILE__, __func__, __LINE__)
#define mutex_unlock(_lock) _mutex_unlock(_lock, __FILE__, __func__, __LINE__) #define mutex_unlock(_lock) _mutex_unlock(_lock, __FILE__, __func__, __LINE__)
@ -141,54 +248,7 @@ struct unixsock {
typedef struct unixsock unixsock_t; typedef struct unixsock unixsock_t;
struct proc_instance;
typedef struct proc_instance proc_instance_t; typedef struct proc_instance proc_instance_t;
struct ckpool_instance;
typedef struct ckpool_instance ckpool_t;
struct proc_instance {
ckpool_t *ckp;
unixsock_t us;
char *processname;
char *sockname;
int pid;
int (*process)(proc_instance_t *);
};
struct ckpool_instance {
/* Main process name */
char *name;
/* Directory where sockets are created */
char *socket_dir;
/* Filename of config file */
char *config;
/* Logging level */
int loglevel;
/* Process instance data of parent/child processes */
proc_instance_t main;
proc_instance_t generator;
proc_instance_t stratifier;
proc_instance_t connector;
/* Threads of main process */
pthread_t pth_listener;
pthread_t pth_watchdog;
/* Bitcoind data */
char *btcdurl;
char *btcdauth;
char *btcdpass;
int blockpoll; // How frequently in ms to poll bitcoind for block updates
/* Coinbase data */
char *btcaddress; // Address to mine to
char *btcsig; // Optional signature to add to coinbase
/* Stratum options */
int update_interval; // Seconds between stratum updates
char *serverurl;
};
void rename_proc(const char *name); void rename_proc(const char *name);
void create_pthread(pthread_t *thread, void *(*start_routine)(void *), void *arg); void create_pthread(pthread_t *thread, void *(*start_routine)(void *), void *arg);

2
src/stratifier.c

@ -743,8 +743,6 @@ static void add_submit_fail(stratum_instance_t *client, int diff)
add_submit(client, diff); add_submit(client, diff);
} }
extern ckpool_t *global_ckp;
/* We should already be holding the workbase_lock */ /* We should already be holding the workbase_lock */
static void test_blocksolve(workbase_t *wb, const uchar *data, double diff, const char *coinbase, static void test_blocksolve(workbase_t *wb, const uchar *data, double diff, const char *coinbase,
int cblen) int cblen)

Loading…
Cancel
Save