summaryrefslogtreecommitdiff
path: root/integer.cpp
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2003-07-29 01:18:33 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2003-07-29 01:18:33 +0000
commit483c74aaab7c20d82a48621f1dd8b300292d3404 (patch)
tree7a78ed3becd2c14f449d1cc66a58edd414256d94 /integer.cpp
parenta01d216aab60849e4581efd41820f18562085687 (diff)
downloadcryptopp-483c74aaab7c20d82a48621f1dd8b300292d3404.tar.gz
fix potential threading problem with initialization of static objects
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@118 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'integer.cpp')
-rw-r--r--integer.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/integer.cpp b/integer.cpp
index dd667f9..f5b5fc4 100644
--- a/integer.cpp
+++ b/integer.cpp
@@ -2834,22 +2834,28 @@ Integer Integer::Power2(unsigned int e)
return r;
}
+template <long i>
+struct NewInteger
+{
+ Integer * operator()() const
+ {
+ return new Integer(i);
+ }
+};
+
const Integer &Integer::Zero()
{
- static const Integer zero;
- return zero;
+ return Singleton<Integer>().Ref();
}
const Integer &Integer::One()
{
- static const Integer one(1,2);
- return one;
+ return Singleton<Integer, NewInteger<1> >().Ref();
}
const Integer &Integer::Two()
{
- static const Integer two(2,2);
- return two;
+ return Singleton<Integer, NewInteger<2> >().Ref();
}
bool Integer::operator!() const