aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared/Utilities/Util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/shared/Utilities/Util.cpp')
-rw-r--r--src/server/shared/Utilities/Util.cpp37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp
index fc01442adb3..c766cc3ca91 100644
--- a/src/server/shared/Utilities/Util.cpp
+++ b/src/server/shared/Utilities/Util.cpp
@@ -21,42 +21,54 @@
#include "utf8.h"
#include "SFMT.h"
#include "Errors.h" // for ASSERT
-#include <ace/TSS_T.h>
+#include <boost/thread/tss.hpp>
-typedef ACE_TSS<SFMTRand> SFMTRandTSS;
-static SFMTRandTSS sfmtRand;
+static boost::thread_specific_ptr<SFMTRand> sfmtRand;
+
+static SFMTRand* GetRng()
+{
+ SFMTRand* rand = sfmtRand.get();
+
+ if (!rand)
+ {
+ rand = new SFMTRand();
+ sfmtRand.reset(rand);
+ }
+
+ return rand;
+}
int32 irand(int32 min, int32 max)
{
ASSERT(max >= min);
- return int32(sfmtRand->IRandom(min, max));
+ return int32(GetRng()->IRandom(min, max));
}
uint32 urand(uint32 min, uint32 max)
{
ASSERT(max >= min);
- return sfmtRand->URandom(min, max);
+ return GetRng()->URandom(min, max);
}
float frand(float min, float max)
{
ASSERT(max >= min);
- return float(sfmtRand->Random() * (max - min) + min);
+ return float(GetRng()->Random() * (max - min) + min);
}
int32 rand32()
{
- return int32(sfmtRand->BRandom());
+ return int32(GetRng()->BRandom());
}
double rand_norm(void)
{
- return sfmtRand->Random();
+ return GetRng()->Random();
}
double rand_chance(void)
{
- return sfmtRand->Random() * 100.0;
+ return GetRng()->Random() * 100.0;
}
Tokenizer::Tokenizer(const std::string &src, const char sep, uint32 vectorReserve)
@@ -250,13 +262,6 @@ bool IsIPAddress(char const* ipaddress)
return inet_addr(ipaddress) != INADDR_NONE;
}
-std::string GetAddressString(ACE_INET_Addr const& addr)
-{
- char buf[ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 16];
- addr.addr_to_string(buf, ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 16);
- return buf;
-}
-
bool IsIPAddrInNetwork(ACE_INET_Addr const& net, ACE_INET_Addr const& addr, ACE_INET_Addr const& subnetMask)
{
uint32 mask = subnetMask.get_ip_address();