mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Start to hook this stuff up.
This commit is contained in:
@@ -8,26 +8,31 @@
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
#include "../json/value.h"
|
||||
|
||||
#include "types.h"
|
||||
#include "LoadMonitor.h"
|
||||
|
||||
// Note that this queue should only be used for CPU-bound jobs
|
||||
// It is primarily intended for signature checking
|
||||
|
||||
enum JobType
|
||||
{ // must be in priority order, low to high
|
||||
jtINVALID,
|
||||
jtVALIDATION_ut, // A validation from an untrusted source
|
||||
jtCLIENTOP_ut, // A client operation from a non-local/untrusted source
|
||||
jtTRANSACTION, // A transaction received from the network
|
||||
jtPROPOSAL_ut, // A proposal from an untrusted source
|
||||
jtCLIENTOP_t, // A client operation from a trusted source
|
||||
jtVALIDATION_t, // A validation from a trusted source
|
||||
jtTRANSACTION_l, // A local transaction
|
||||
jtPROPOSAL_t, // A proposal from a trusted source
|
||||
jtADMIN, // An administrative operation
|
||||
jtDEATH, // job of death, used internally
|
||||
jtINVALID = -1,
|
||||
jtVALIDATION_ut = 0, // A validation from an untrusted source
|
||||
jtCLIENTOP_ut = 1, // A client operation from a non-local/untrusted source
|
||||
jtTRANSACTION = 2, // A transaction received from the network
|
||||
jtPROPOSAL_ut = 3, // A proposal from an untrusted source
|
||||
jtCLIENTOP_t = 4, // A client operation from a trusted source
|
||||
jtVALIDATION_t = 5, // A validation from a trusted source
|
||||
jtTRANSACTION_l = 6, // A local transaction
|
||||
jtPROPOSAL_t = 7, // A proposal from a trusted source
|
||||
jtADMIN = 8, // An administrative operation
|
||||
jtDEATH = 9, // job of death, used internally
|
||||
};
|
||||
#define NUM_JOB_TYPES 10
|
||||
|
||||
class Job
|
||||
{
|
||||
@@ -35,13 +40,18 @@ protected:
|
||||
JobType mType;
|
||||
uint64 mJobIndex;
|
||||
boost::function<void(Job&)> mJob;
|
||||
LoadEvent::pointer mLoadMonitor;
|
||||
|
||||
public:
|
||||
Job() : mType(jtINVALID), mJobIndex(0) { ; }
|
||||
Job(JobType type, uint64 index) : mType(type), mJobIndex(index) { ; }
|
||||
|
||||
Job(JobType type, uint64 index, const boost::function<void(Job&)>& job)
|
||||
: mType(type), mJobIndex(index), mJob(job) { ; }
|
||||
Job() : mType(jtINVALID), mJobIndex(0) { ; }
|
||||
|
||||
Job(JobType type, uint64 index) : mType(type), mJobIndex(index)
|
||||
{ ; }
|
||||
|
||||
Job(JobType type, uint64 index, LoadMonitor& lm, const boost::function<void(Job&)>& job)
|
||||
: mType(type), mJobIndex(index), mJob(job)
|
||||
{ mLoadMonitor = boost::make_shared<LoadEvent>(boost::ref(lm), true, 1); }
|
||||
|
||||
JobType getType() const { return mType; }
|
||||
void doJob(void) { mJob(*this); }
|
||||
@@ -57,14 +67,15 @@ public:
|
||||
class JobQueue
|
||||
{
|
||||
protected:
|
||||
boost::mutex mJobLock;
|
||||
boost::condition_variable mJobCond;
|
||||
boost::mutex mJobLock;
|
||||
boost::condition_variable mJobCond;
|
||||
|
||||
uint64 mLastJob;
|
||||
std::set<Job> mJobSet;
|
||||
std::map<JobType, int> mJobCounts;
|
||||
int mThreadCount;
|
||||
bool mShuttingDown;
|
||||
uint64 mLastJob;
|
||||
std::set<Job> mJobSet;
|
||||
std::map<JobType, int> mJobCounts;
|
||||
LoadMonitor mJobLoads[NUM_JOB_TYPES];
|
||||
int mThreadCount;
|
||||
bool mShuttingDown;
|
||||
|
||||
|
||||
void threadEntry(void);
|
||||
@@ -81,6 +92,8 @@ public:
|
||||
|
||||
void shutdown();
|
||||
void setThreadCount(int c = 0);
|
||||
|
||||
Json::Value getJson(int c = 0);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user