- 1355AD6CE93816FFFC1BEFD7A68A5FBDF034AE24AE99C64A60269CA9DB589363D6531F441CD2393630E3128C2762DDCB8101DD6C305551B70CF24E102E59CFD0
+ 1E2275FEA3780708AED4D4C7DE351B23A9379354DF29DDA39B8BF2CCC72DF95713514B2B7837DC2230D42CF8234744E804BFD608FB4442FF62871257F8D80C12
bitcoin/src/util.h
(7 . 11)(7 . 10)
796
797 #include "uint256.h"
798
799 #ifndef WIN32
800
801 #include <sys/types.h>
802 #include <sys/time.h>
803 #include <sys/resource.h>
804 #endif
805 #include <map>
806 #include <vector>
807 #include <string>
(25 . 19)(24 . 10)
809 #include <openssl/ripemd.h>
810
811
812 #if defined(_MSC_VER) || defined(__BORLANDC__)
813 typedef __int64 int64;
814 typedef unsigned __int64 uint64;
815 #else
816 typedef long long int64;
817 typedef unsigned long long uint64;
818 #endif
819 #if defined(_MSC_VER) && _MSC_VER < 1300
820 #define for if (false) ; else for
821 #endif
822 #ifndef _MSC_VER
823
824 #define __forceinline inline
825 #endif
826
827 #define loop for (;;)
828 #define BEGIN(a) ((char*)&(a))
(53 . 16)(43 . 10)
830 #define snprintf my_snprintf
831
832 #ifndef PRI64d
833 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MSVCRT__)
834 #define PRI64d "I64d"
835 #define PRI64u "I64u"
836 #define PRI64x "I64x"
837 #else
838 #define PRI64d "lld"
839 #define PRI64u "llu"
840 #define PRI64x "llx"
841 #endif
842 #endif
843
844 // This is needed because the foreach macro can't get over the comma in pair<t1, t2>
845 #define PAIRTYPE(t1, t2) std::pair<t1, t2>
(81 . 21)(65 . 6)
847 return u.ptr;
848 }
849
850 #ifdef WIN32
851 #define MSG_NOSIGNAL 0
852 #define MSG_DONTWAIT 0
853 #ifndef UINT64_MAX
854 #define UINT64_MAX _UI64_MAX
855 #define INT64_MAX _I64_MAX
856 #define INT64_MIN _I64_MIN
857 #endif
858 #ifndef S_IRUSR
859 #define S_IRUSR 0400
860 #define S_IWUSR 0200
861 #endif
862 #define unlink _unlink
863 typedef int socklen_t;
864 #else
865 #define WSAGetLastError() errno
866 #define WSAEINVAL EINVAL
867 #define WSAEALREADY EALREADY
(119 . 17)(88 . 13)
869 So we clamp our sleeps here to 10 years and hope that boost is fixed by 2028.*/
870 boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(n>315576000000LL?315576000000LL:n));
871 }
872 #endif
873
874
875 inline int myclosesocket(SOCKET& hSocket)
876 {
877 if (hSocket == INVALID_SOCKET)
878 return WSAENOTSOCK;
879 #ifdef WIN32
880 int ret = closesocket(hSocket);
881 #else
882 int ret = close(hSocket);
883 #endif
884 hSocket = INVALID_SOCKET;
885 return ret;
886 }
(140 . 14)(105 . 6)
888 }
889
890
891
892
893
894
895
896
897
898
899 extern std::map<std::string, std::string> mapArgs;
900 extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
901 extern bool fDebug;
(193 . 9)(150 . 6)
903 std::string GetPidFile();
904 void CreatePidFile(std::string pidFile, pid_t pid);
905 void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet, std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet);
906 #ifdef WIN32
907 std::string MyGetSpecialFolderPath(int nFolder, bool fCreate);
908 #endif
909 std::string GetDefaultDataDir();
910 std::string GetDataDir();
911 void ShrinkDebugFile();
(323 . 20)(277 . 12)
913
914 inline int64 atoi64(const char* psz)
915 {
916 #ifdef _MSC_VER
917 return _atoi64(psz);
918 #else
919 return strtoll(psz, NULL, 10);
920 #endif
921 }
922
923 inline int64 atoi64(const std::string& str)
924 {
925 #ifdef _MSC_VER
926 return _atoi64(str.c_str());
927 #else
928 return strtoll(str.c_str(), NULL, 10);
929 #endif
930 }
931
932 inline int atoi(const std::string& str)
(411 . 13)(357 . 9)
934 inline int64 GetPerformanceCounter()
935 {
936 int64 nCounter = 0;
937 #ifdef WIN32
938 QueryPerformanceCounter((LARGE_INTEGER*)&nCounter);
939 #else
940 timeval t;
941 gettimeofday(&t, NULL);
942 nCounter = t.tv_sec * 1000000 + t.tv_usec;
943 #endif
944 return nCounter;
945 }
946
(445 . 11)(387 . 7)
948
949 inline bool IsSwitchChar(char c)
950 {
951 #ifdef WIN32
952 return c == '-' || c == '/';
953 #else
954 return c == '-';
955 #endif
956 }
957
958 inline std::string GetArg(const std::string& strArg, const std::string& strDefault)
(505 . 11)(443 . 6)
960
961 inline void heapchk()
962 {
963 #ifdef WIN32
964 /// for debugging
965 //if (_heapchk() != _HEAPOK)
966 // DebugBreak();
967 #endif
968 }
969
970 // Randomize the stack to help protect against buffer overrun exploits
(664 . 38)(597 . 6)
972
973 // Note: It turns out we might have been able to use boost::thread
974 // by using TerminateThread(boost::thread.native_handle(), 0);
975 #ifdef WIN32
976 typedef HANDLE pthread_t;
977
978 inline pthread_t CreateThread(void(*pfn)(void*), void* parg, bool fWantHandle=false)
979 {
980 DWORD nUnused = 0;
981 HANDLE hthread =
982 CreateThread(
983 NULL, // default security
984 0, // inherit stack size from parent
985 (LPTHREAD_START_ROUTINE)pfn, // function pointer
986 parg, // argument
987 0, // creation option, start immediately
988 &nUnused); // thread identifier
989 if (hthread == NULL)
990 {
991 printf("Error: CreateThread() returned %d\n", GetLastError());
992 return (pthread_t)0;
993 }
994 if (!fWantHandle)
995 {
996 CloseHandle(hthread);
997 return (pthread_t)-1;
998 }
999 return hthread;
1000 }
1001
1002 inline void SetThreadPriority(int nPriority)
1003 {
1004 SetThreadPriority(GetCurrentThread(), nPriority);
1005 }
1006 #else
1007 inline pthread_t CreateThread(void(*pfn)(void*), void* parg, bool fWantHandle=false)
1008 {
1009 pthread_t hthread = 0;
(738 . 29)(639 . 11)
1011 {
1012 pthread_exit((void*)nExitCode);
1013 }
1014 #endif
1015
1016
1017
1018
1019
1020 inline bool AffinityBugWorkaround(void(*pfn)(void*))
1021 {
1022 #ifdef WIN32
1023 // Sometimes after a few hours affinity gets stuck on one processor
1024 DWORD_PTR dwProcessAffinityMask = -1;
1025 DWORD_PTR dwSystemAffinityMask = -1;
1026 GetProcessAffinityMask(GetCurrentProcess(), &dwProcessAffinityMask, &dwSystemAffinityMask);
1027 DWORD dwPrev1 = SetThreadAffinityMask(GetCurrentThread(), dwProcessAffinityMask);
1028 DWORD dwPrev2 = SetThreadAffinityMask(GetCurrentThread(), dwProcessAffinityMask);
1029 if (dwPrev2 != dwProcessAffinityMask)
1030 {
1031 printf("AffinityBugWorkaround() : SetThreadAffinityMask=%d, ProcessAffinityMask=%d, restarting thread\n", dwPrev2, dwProcessAffinityMask);
1032 if (!CreateThread(pfn, NULL))
1033 printf("Error: CreateThread() failed\n");
1034 return true;
1035 }
1036 #endif
1037 return false;
1038 }
1039