2015-10-22 17:36:03 +02:00
|
|
|
#pragma once
|
|
|
|
#ifndef MESSMER_CPPUTILS_RANDOM_PSEUDORANDOMPOOL_H
|
|
|
|
#define MESSMER_CPPUTILS_RANDOM_PSEUDORANDOMPOOL_H
|
|
|
|
|
|
|
|
#include <boost/thread.hpp>
|
|
|
|
#include "RandomGenerator.h"
|
|
|
|
#include "ThreadsafeRandomDataBuffer.h"
|
|
|
|
#include "RandomGeneratorThread.h"
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
namespace cpputils {
|
|
|
|
//TODO Test
|
|
|
|
class PseudoRandomPool final : public RandomGenerator {
|
|
|
|
public:
|
|
|
|
PseudoRandomPool();
|
|
|
|
|
|
|
|
protected:
|
2015-10-23 20:21:17 +02:00
|
|
|
void _get(void *target, size_t bytes) override;
|
2015-10-22 17:36:03 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
static constexpr size_t MIN_BUFFER_SIZE = 1*1024*1024; // 1MB
|
|
|
|
static constexpr size_t MAX_BUFFER_SIZE = 2*1024*1024; // 2MB
|
|
|
|
|
|
|
|
ThreadsafeRandomDataBuffer _buffer;
|
|
|
|
RandomGeneratorThread _refillThread;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(PseudoRandomPool);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-10-23 20:21:17 +02:00
|
|
|
inline void PseudoRandomPool::_get(void *target, size_t bytes) {
|
2015-10-22 17:36:03 +02:00
|
|
|
_buffer.get(target, bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline PseudoRandomPool::PseudoRandomPool(): _buffer(), _refillThread(&_buffer, MIN_BUFFER_SIZE, MAX_BUFFER_SIZE) {
|
|
|
|
_refillThread.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|