try to poll for blocks on separate thread.

This commit is contained in:
Christopher Jeffrey 2014-09-19 17:43:38 -07:00
parent 494f539f4e
commit da33403683

View File

@ -177,10 +177,14 @@ async_get_block(uv_work_t *req);
static void
async_get_block_after(uv_work_t *req);
static void
poll_blocks(void);
extern "C" void
init(Handle<Object>);
static volatile bool shutdownComplete = false;
static volatile CBlockIndex *lastindex = NULL;
// bool (*AcceptBlock_original)(CBlock& block, CValidationState& state, CDiskBlockPos* dbp) = &AcceptBlock;
// bool AcceptBlock(CBlock& block, CValidationState& state, CDiskBlockPos* dbp) {
@ -188,11 +192,11 @@ static volatile bool shutdownComplete = false;
// return AcceptBlock_original(block, state, dbp);
// }
bool __real_AcceptBlock(CBlock& block, CValidationState& state, CDiskBlockPos* dbp);
bool __wrap_AcceptBlock(CBlock& block, CValidationState& state, CDiskBlockPos* dbp) {
printf("AcceptBlock called\n");
return __real_AcceptBlock(block, state, dbp);
}
// bool __real_AcceptBlock(CBlock& block, CValidationState& state, CDiskBlockPos* dbp);
// bool __wrap_AcceptBlock(CBlock& block, CValidationState& state, CDiskBlockPos* dbp) {
// printf("AcceptBlock called\n");
// return __real_AcceptBlock(block, state, dbp);
// }
/**
* async_block_data
@ -385,6 +389,8 @@ start_node(void) {
(boost::thread *)new boost::thread(boost::bind(&start_node_thread));
// (boost::thread *)new boost::thread(boost::bind(&poll_blocks));
// horrible fix for a race condition
sleep(2);
signal(SIGINT, SIG_DFL);
@ -882,6 +888,28 @@ async_get_block_after(uv_work_t *req) {
delete req;
}
static void
poll_blocks(void) {
if (!lastindex) {
lastindex = chainActive.Tip();
}
CBlockIndex *pnext = chainActive.Next((const CBlockIndex *)lastindex);
CBlockIndex *pcur = pnext;
if (pnext) {
// execute callback
printf("Found block\n");
while ((pcur = chainActive.Next(pcur))) {
// execute callback
printf("Found block\n");
pnext = pcur;
}
}
if (pnext) {
lastindex = pnext;
}
sleep(1);
}
/**
* Init
*/