From: Victor Grishchenko Date: Tue, 26 Jan 2010 17:15:05 +0000 (+0100) Subject: Merged git://github.com/the-zett/swift X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=9316d91a75380d2568df14438eb6dbe83b9975f8;p=swift-upb.git Merged git://github.com/the-zett/swift Conflicts: compat/hirestimeofday.cpp compat/hirestimeofday.h compat/util.cpp compat/util.h --- 9316d91a75380d2568df14438eb6dbe83b9975f8 diff --cc bins.cpp index 1c20dd4,80c531d..ffc98c6 --- a/bins.cpp +++ b/bins.cpp @@@ -6,10 -6,17 +6,17 @@@ * Copyright 2009 Delft University of Technology. All rights reserved. * */ - #include "bins.h" - #include - #include + #include + #include + #include + #include + #include + #include + -#include "binmap.h" ++#include "bins.h" + + #undef max // make it work piece by piece diff --cc compat/hirestimeofday.cpp index 29595be,2f5ef33..8aa7b1e --- a/compat/hirestimeofday.cpp +++ b/compat/hirestimeofday.cpp @@@ -1,157 -1,157 +1,157 @@@ - /* - * Inspired by - * - http://msdn.microsoft.com/en-us/library/ms644904%28VS.85%29.aspx - * - Python-2.6.3/Modules/timemodule.c - */ - - #include - #include "hirestimeofday.h" - - #ifndef _WIN32 - #include - #endif - - namespace swift { - - HiResTimeOfDay* HiResTimeOfDay::_instance = 0; - - HiResTimeOfDay* HiResTimeOfDay::Instance() - { - if (_instance == 0) - _instance = new HiResTimeOfDay(); - return _instance; - } - - - #ifdef _WIN32 - #include - #include - - - HiResTimeOfDay::HiResTimeOfDay(void) - { - frequency = getFrequency(); - epochstart = getFTime(); - epochcounter = getCounter(); - } - - - tint HiResTimeOfDay::getTimeUSec(void) - { - LARGE_INTEGER currentcounter; - tint currentstart; - - currentstart = getFTime(); - currentcounter = getCounter(); - - if (currentcounter.QuadPart < epochcounter.QuadPart) - { - - // Wrap around detected, reestablish baseline - epochstart = currentstart; - epochcounter = currentcounter; - } - return epochstart + (1000000*(currentcounter.QuadPart-epochcounter.QuadPart))/frequency.QuadPart; - } - - - // Private - tint HiResTimeOfDay::getFTime() - { - struct timeb t; - ftime(&t); - tint usec; - usec = t.time * 1000000; - usec += t.millitm * 1000; - return usec; - } - - - - LARGE_INTEGER HiResTimeOfDay::getFrequency(void) - { - LARGE_INTEGER proc_freq; - - if (!::QueryPerformanceFrequency(&proc_freq)) - std::cerr << "HiResTimeOfDay: QueryPerformanceFrequency() failed"; - - return proc_freq; - } - - LARGE_INTEGER HiResTimeOfDay::getCounter() - { - LARGE_INTEGER counter; - - DWORD_PTR oldmask = ::SetThreadAffinityMask(::GetCurrentThread(), 0); - if (!::QueryPerformanceCounter(&counter)) - std::cerr << "HiResTimeOfDay: QueryPerformanceCounter() failed"; - ::SetThreadAffinityMask(::GetCurrentThread(), oldmask); - - return counter; - } - - #else - - HiResTimeOfDay::HiResTimeOfDay(void) - { - } - - - tint HiResTimeOfDay::getTimeUSec(void) - { - struct timeval t; - gettimeofday(&t,NULL); - tint ret; - ret = t.tv_sec; - ret *= 1000000; - ret += t.tv_usec; - return ret; - } - #endif - - - - - // ARNOTODO: move to swift.cpp - - #ifdef _WIN32 - static WSADATA _WSAData; - #endif - - void LibraryInit(void) - { - #ifdef _WIN32 - // win32 requires you to initialize the Winsock DLL with the desired - // specification version - WORD wVersionRequested; - wVersionRequested = MAKEWORD(2, 2); - WSAStartup(wVersionRequested, &_WSAData); - #endif - } - - - } // end of namespace - - - - - #ifdef TEST - #include - - using namespace swift; - - int main() - { - HiResTimeOfDay *t = HiResTimeOfDay::Instance(); - for (int i=0; i<100; i++) - { - tint st = t->getTimeUSec(); - Sleep(1000); - tint et = t->getTimeUSec(); - tint diff = et - st; - std::cout << "diffxTime is " << diff << "\n"; - } - return 0; - } - #endif - + /* + * Inspired by + * - http://msdn.microsoft.com/en-us/library/ms644904%28VS.85%29.aspx + * - Python-2.6.3/Modules/timemodule.c + */ + + #include + #include "hirestimeofday.h" + + #ifndef _WIN32 + #include + #endif + -namespace p2tp { ++namespace swift { + + HiResTimeOfDay* HiResTimeOfDay::_instance = 0; + + HiResTimeOfDay* HiResTimeOfDay::Instance() + { + if (_instance == 0) + _instance = new HiResTimeOfDay(); + return _instance; + } + + + #ifdef _WIN32 + #include + #include + + + HiResTimeOfDay::HiResTimeOfDay(void) + { + frequency = getFrequency(); + epochstart = getFTime(); + epochcounter = getCounter(); + } + + + tint HiResTimeOfDay::getTimeUSec(void) + { + LARGE_INTEGER currentcounter; + tint currentstart; + + currentstart = getFTime(); + currentcounter = getCounter(); + + if (currentcounter.QuadPart < epochcounter.QuadPart) + { + + // Wrap around detected, reestablish baseline + epochstart = currentstart; + epochcounter = currentcounter; + } + return epochstart + (1000000*(currentcounter.QuadPart-epochcounter.QuadPart))/frequency.QuadPart; + } + + + // Private + tint HiResTimeOfDay::getFTime() + { + struct timeb t; + ftime(&t); + tint usec; + usec = t.time * 1000000; + usec += t.millitm * 1000; + return usec; + } + + + + LARGE_INTEGER HiResTimeOfDay::getFrequency(void) + { + LARGE_INTEGER proc_freq; + + if (!::QueryPerformanceFrequency(&proc_freq)) + std::cerr << "HiResTimeOfDay: QueryPerformanceFrequency() failed"; + + return proc_freq; + } + + LARGE_INTEGER HiResTimeOfDay::getCounter() + { + LARGE_INTEGER counter; + + DWORD_PTR oldmask = ::SetThreadAffinityMask(::GetCurrentThread(), 0); + if (!::QueryPerformanceCounter(&counter)) + std::cerr << "HiResTimeOfDay: QueryPerformanceCounter() failed"; + ::SetThreadAffinityMask(::GetCurrentThread(), oldmask); + + return counter; + } + + #else + + HiResTimeOfDay::HiResTimeOfDay(void) + { + } + + + tint HiResTimeOfDay::getTimeUSec(void) + { + struct timeval t; + gettimeofday(&t,NULL); + tint ret; + ret = t.tv_sec; + ret *= 1000000; + ret += t.tv_usec; + return ret; + } + #endif + + + + -// ARNOTODO: move to p2tp.cpp ++// ARNOTODO: move to swift.cpp + + #ifdef _WIN32 + static WSADATA _WSAData; + #endif + + void LibraryInit(void) + { + #ifdef _WIN32 + // win32 requires you to initialize the Winsock DLL with the desired + // specification version + WORD wVersionRequested; + wVersionRequested = MAKEWORD(2, 2); + WSAStartup(wVersionRequested, &_WSAData); + #endif + } + + + } // end of namespace + + + + + #ifdef TEST + #include + -using namespace p2tp; ++using namespace swift; + + int main() + { + HiResTimeOfDay *t = HiResTimeOfDay::Instance(); + for (int i=0; i<100; i++) + { + tint st = t->getTimeUSec(); + Sleep(1000); + tint et = t->getTimeUSec(); + tint diff = et - st; + std::cout << "diffxTime is " << diff << "\n"; + } + return 0; + } + #endif + diff --cc compat/hirestimeofday.h index 362dd96,be2e60c..bb88e9c --- a/compat/hirestimeofday.h +++ b/compat/hirestimeofday.h @@@ -1,52 -1,52 +1,52 @@@ - /* - * Written by Arno Bakker - * see LICENSE.txt for license information - * - * Singleton class to retrieve a time-of-day in UTC in usec in a platform- - * independent manner. - */ - #ifndef HIRESTIMEOFDAY_H - #define HIRESTIMEOFDAY_H - - #ifdef _MSC_VER - #include "compat/stdint.h" - #else - #include - #endif - #ifdef _WIN32 - #include - #endif - - namespace swift { - - typedef int64_t tint; - #define TINT_SEC ((tint)1000000) - #define TINT_MSEC ((tint)1000) - #define TINT_uSEC ((tint)1) - #define TINT_NEVER ((tint)0x7fffffffffffffffLL) - - - class HiResTimeOfDay - { - public: - HiResTimeOfDay(void); - tint getTimeUSec(void); - static HiResTimeOfDay* Instance(); - - private: - #ifdef _WIN32 - tint epochstart; // in usec - LARGE_INTEGER epochcounter; - LARGE_INTEGER last; - LARGE_INTEGER frequency; - - tint HiResTimeOfDay::getFTime(); - LARGE_INTEGER getFrequency(void); - LARGE_INTEGER getCounter(void); - #endif - - static HiResTimeOfDay* _instance; - }; - - }; - #endif + /* + * Written by Arno Bakker + * see LICENSE.txt for license information + * + * Singleton class to retrieve a time-of-day in UTC in usec in a platform- + * independent manner. + */ + #ifndef HIRESTIMEOFDAY_H + #define HIRESTIMEOFDAY_H + + #ifdef _MSC_VER + #include "compat/stdint.h" + #else + #include + #endif + #ifdef _WIN32 + #include + #endif + -namespace p2tp { ++namespace swift { + + typedef int64_t tint; + #define TINT_SEC ((tint)1000000) + #define TINT_MSEC ((tint)1000) + #define TINT_uSEC ((tint)1) + #define TINT_NEVER ((tint)0x7fffffffffffffffLL) + + + class HiResTimeOfDay + { + public: + HiResTimeOfDay(void); + tint getTimeUSec(void); + static HiResTimeOfDay* Instance(); + + private: + #ifdef _WIN32 + tint epochstart; // in usec + LARGE_INTEGER epochcounter; + LARGE_INTEGER last; + LARGE_INTEGER frequency; + + tint HiResTimeOfDay::getFTime(); + LARGE_INTEGER getFrequency(void); + LARGE_INTEGER getCounter(void); + #endif + + static HiResTimeOfDay* _instance; + }; + + }; + #endif diff --cc compat/util.cpp index 579ef84,6493ecc..7469c4a --- a/compat/util.cpp +++ b/compat/util.cpp @@@ -1,39 -1,39 +1,39 @@@ - /* - * Written by Arno Bakker - * see LICENSE.txt for license information - */ - - #include "util.h" - #include - - #ifdef _WIN32 - #include - #include - #endif - - namespace swift - { - - std::string gettmpdir(void) - { - #ifdef _WIN32 - DWORD result = ::GetTempPath(0, _T("")); - if (result == 0) - throw std::runtime_error("Could not get system temp path"); - - std::vector tempPath(result + 1); - result = ::GetTempPath(static_cast(tempPath.size()), &tempPath[0]); - if((result == 0) || (result >= tempPath.size())) - throw std::runtime_error("Could not get system temp path"); - - return std::string(tempPath.begin(), tempPath.begin() + static_cast(result)); - #else - return std::string("/tmp/"); - #endif - } - - - - - }; // namespace - + /* + * Written by Arno Bakker + * see LICENSE.txt for license information + */ + + #include "util.h" + #include + + #ifdef _WIN32 + #include + #include + #endif + -namespace p2tp ++namespace swift + { + + std::string gettmpdir(void) + { + #ifdef _WIN32 + DWORD result = ::GetTempPath(0, _T("")); + if (result == 0) + throw std::runtime_error("Could not get system temp path"); + + std::vector tempPath(result + 1); + result = ::GetTempPath(static_cast(tempPath.size()), &tempPath[0]); + if((result == 0) || (result >= tempPath.size())) + throw std::runtime_error("Could not get system temp path"); + + return std::string(tempPath.begin(), tempPath.begin() + static_cast(result)); + #else + return std::string("/tmp/"); + #endif + } + + + + + }; // namespace + diff --cc compat/util.h index dd9256b,265bc75..42f7de4 --- a/compat/util.h +++ b/compat/util.h @@@ -1,28 -1,28 +1,28 @@@ - /* - * util.h - * - * Created on: 20-Oct-2009 - * Author: arno - */ - - #ifndef UTIL_H_ - #define UTIL_H_ - - #include - - namespace swift - { - /** - * Return path of temporary directory. - * - * From http://msdn.microsoft.com/en-us/library/aa364992%28VS.85%29.aspx - * - * TODO: Unicode... (gets hairy with open() call on Linux. Win32 has _wopen) - */ - std::string gettmpdir(void); - - void print_error(const char* msg); - - }; - - #endif /* UTIL_H_ */ + /* + * util.h + * + * Created on: 20-Oct-2009 + * Author: arno + */ + + #ifndef UTIL_H_ + #define UTIL_H_ + + #include + -namespace p2tp ++namespace swift + { + /** + * Return path of temporary directory. + * + * From http://msdn.microsoft.com/en-us/library/aa364992%28VS.85%29.aspx + * + * TODO: Unicode... (gets hairy with open() call on Linux. Win32 has _wopen) + */ + std::string gettmpdir(void); + + void print_error(const char* msg); + + }; + + #endif /* UTIL_H_ */