mirror of https://github.com/aria2/aria2
To fix static initialization order problem:
* src/BitfieldManFactory.h (defaultRandomizer): Removed. (factory): New variable. (getNewFactory): Removed. (getFactoryInstance): New function. (setDefaultRandomizer): Rewritten. (getDefaultRandomizer): Rewritten. * src/BitfieldManFactory.cc (defaultRandomizer): Removed. (factory): Initialized to 0. (BitfieldManFactory): Initialized randomizer to 0. * src/DefaultPieceStorage.cc (DefaultPieceStorage): getNewFactory() -> getFactoryInstance() * src/Peer.cc (Peer): getNewFactory() -> getFactoryInstance() * src/SegmentMan.cc (initBitfield): getNewFactory() -> getFactoryInstance() * src/Piece.cc (Piece): getNewFactory() -> getFactoryInstance()pull/1/head
parent
aa1730d1f3
commit
cc24f7cdf8
|
@ -35,6 +35,6 @@
|
|||
#include "BitfieldManFactory.h"
|
||||
#include "SimpleRandomizer.h"
|
||||
|
||||
RandomizerHandle BitfieldManFactory::defaultRandomizer = SimpleRandomizer::getInstance();
|
||||
BitfieldManFactoryHandle BitfieldManFactory::factory = 0;
|
||||
|
||||
BitfieldManFactory::BitfieldManFactory():randomizer(defaultRandomizer) {}
|
||||
BitfieldManFactory::BitfieldManFactory():randomizer(0) {}
|
||||
|
|
|
@ -45,15 +45,18 @@ typedef SharedHandle<BitfieldManFactory> BitfieldManFactoryHandle;
|
|||
|
||||
class BitfieldManFactory {
|
||||
private:
|
||||
static RandomizerHandle defaultRandomizer;
|
||||
static BitfieldManFactoryHandle factory;
|
||||
|
||||
RandomizerHandle randomizer;
|
||||
|
||||
BitfieldManFactory();
|
||||
public:
|
||||
~BitfieldManFactory() {}
|
||||
|
||||
static BitfieldManFactoryHandle getNewFactory() {
|
||||
BitfieldManFactoryHandle factory = new BitfieldManFactory();
|
||||
static BitfieldManFactoryHandle getFactoryInstance() {
|
||||
if(factory.isNull()) {
|
||||
factory = new BitfieldManFactory();
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
@ -64,11 +67,12 @@ public:
|
|||
}
|
||||
|
||||
static void setDefaultRandomizer(const RandomizerHandle& randomizer) {
|
||||
defaultRandomizer = randomizer;
|
||||
BitfieldManFactoryHandle factory = getFactoryInstance();
|
||||
factory->setRandomizer(randomizer);
|
||||
}
|
||||
|
||||
static RandomizerHandle getDefaultRandomizer() {
|
||||
return defaultRandomizer;
|
||||
return getFactoryInstance()->getRandomizer();
|
||||
}
|
||||
|
||||
void setRandomizer(const RandomizerHandle& randomizer) {
|
||||
|
|
|
@ -52,7 +52,7 @@ DefaultPieceStorage::DefaultPieceStorage(BtContextHandle btContext, const Option
|
|||
option(option)
|
||||
{
|
||||
bitfieldMan =
|
||||
BitfieldManFactory::getNewFactory()->
|
||||
BitfieldManFactory::getFactoryInstance()->
|
||||
createBitfieldMan(btContext->getPieceLength(),
|
||||
btContext->getTotalLength());
|
||||
logger = LogFactory::getInstance();
|
||||
|
|
|
@ -46,7 +46,7 @@ Peer::Peer(string ipaddr, int port, int pieceLength, long long int totalLength):
|
|||
active(false)
|
||||
{
|
||||
resetStatus();
|
||||
this->bitfield = BitfieldManFactory::getNewFactory()->
|
||||
this->bitfield = BitfieldManFactory::getFactoryInstance()->
|
||||
createBitfieldMan(pieceLength, totalLength);
|
||||
string idSeed = ipaddr+":"+Util::itos(port);
|
||||
id = Util::simpleMessageDigest(idSeed);
|
||||
|
|
|
@ -40,7 +40,7 @@ Piece::Piece():index(0), length(0), bitfield(0) {}
|
|||
|
||||
Piece::Piece(int index, int length):index(index), length(length) {
|
||||
bitfield =
|
||||
BitfieldManFactory::getNewFactory()->createBitfieldMan(BLOCK_LENGTH, length);
|
||||
BitfieldManFactory::getFactoryInstance()->createBitfieldMan(BLOCK_LENGTH, length);
|
||||
}
|
||||
|
||||
Piece::Piece(const Piece& piece) {
|
||||
|
|
|
@ -238,7 +238,7 @@ void SegmentMan::init() {
|
|||
|
||||
void SegmentMan::initBitfield(int segmentLength, long long int totalLength) {
|
||||
delete bitfield;
|
||||
this->bitfield = BitfieldManFactory::getNewFactory()->createBitfieldMan(segmentLength, totalLength);
|
||||
this->bitfield = BitfieldManFactory::getFactoryInstance()->createBitfieldMan(segmentLength, totalLength);
|
||||
}
|
||||
|
||||
Segment SegmentMan::checkoutSegment(int cuid, int index) {
|
||||
|
|
Loading…
Reference in New Issue