summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-02-12 12:05:55 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-02-12 12:05:55 +0000
commitcc24f7cdf816a4e127efeaf9b74146e1296467c9 (patch)
tree76c9a568554c801d9f0db6514fd731b8b6c2889b /src
parentaa1730d1f3516e5c0cbb153e2ab7d73bd1af0d01 (diff)
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()
Diffstat (limited to 'src')
-rw-r--r--src/BitfieldManFactory.cc4
-rw-r--r--src/BitfieldManFactory.h14
-rw-r--r--src/DefaultPieceStorage.cc2
-rw-r--r--src/Peer.cc2
-rw-r--r--src/Piece.cc2
-rw-r--r--src/SegmentMan.cc2
6 files changed, 15 insertions, 11 deletions
diff --git a/src/BitfieldManFactory.cc b/src/BitfieldManFactory.cc
index 2ee68222..20db54e8 100644
--- a/src/BitfieldManFactory.cc
+++ b/src/BitfieldManFactory.cc
@@ -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) {}
diff --git a/src/BitfieldManFactory.h b/src/BitfieldManFactory.h
index 34377a09..8b7d9ca8 100644
--- a/src/BitfieldManFactory.h
+++ b/src/BitfieldManFactory.h
@@ -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) {
diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc
index 20e4ffe0..c9f43299 100644
--- a/src/DefaultPieceStorage.cc
+++ b/src/DefaultPieceStorage.cc
@@ -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();
diff --git a/src/Peer.cc b/src/Peer.cc
index b9591d23..7da4120d 100644
--- a/src/Peer.cc
+++ b/src/Peer.cc
@@ -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);
diff --git a/src/Piece.cc b/src/Piece.cc
index 1bba051b..f73cf83c 100644
--- a/src/Piece.cc
+++ b/src/Piece.cc
@@ -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) {
diff --git a/src/SegmentMan.cc b/src/SegmentMan.cc
index 12edb358..a09859de 100644
--- a/src/SegmentMan.cc
+++ b/src/SegmentMan.cc
@@ -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) {