00001 /* oslConfig.h 00002 */ 00003 #ifndef OSL_OSLCONFIG_H 00004 #define OSL_OSLCONFIG_H 00005 00006 #include "osl/config.h" 00007 #include <stdexcept> 00008 #include <string> 00009 #include <utility> 00010 #include <mutex> 00011 #include <functional> 00012 #include <cassert> 00013 #include <vector> 00014 00015 namespace osl 00016 { 00018 struct OslConfig 00019 { 00020 static const int MaxThreads=64; 00022 static const std::string& home(const std::string& initialize_if_first_invocation=""); 00023 static const char * home_c_str(); 00024 static const std::string gpsusiConf(); 00025 00027 static const std::string testPrivate(); 00028 static const std::string testPublic(); 00029 static const char *testPrivateFile(const std::string& filename); 00030 static const char *testPublicFile(const std::string& filename); 00031 static const char *testCsaFile(const std::string& filename); 00032 00037 static const char *openingBook(const std::string& filenamme=""); 00038 00039 static void setVerbose(bool verbose); 00040 static bool verbose(); 00041 00042 static void showOslHome(); 00043 static void setNumCPUs(int ncpu); 00044 static int concurrency(); 00045 00046 static int dfpnMaxDepth(); 00047 static void setDfpnMaxDepth(int); 00048 00049 enum UsiMode { NoUSI, PortableUSI, ExtendedUSI }; 00050 static UsiMode usiMode(); 00051 static void setUsiMode(UsiMode new_mode=PortableUSI); 00052 static bool usiModeInSilent(); 00053 static void setUsiSilent(bool silent=true); 00054 00055 static bool searchExactValueInOneReply(); 00056 static void setSearchExactValueInOneReply(bool new_value); 00057 00058 static size_t residentMemoryUse(); 00059 static size_t memoryUseLimit() 00060 { 00061 return static_cast<size_t>(memory_use_limit * memory_use_percent / 100.0); 00062 } 00063 static void setMemoryUseLimit(size_t limit) { memory_use_limit = limit; } 00064 static double memoryUseRatio() 00065 { 00066 return residentMemoryUse() * 1.0 / memoryUseLimit(); 00067 } 00068 static bool isMemoryLimitEffective() 00069 { 00070 return memory_use_limit != memory_use_limit_system_max 00071 && residentMemoryUse() > 0; 00072 } 00073 static void setMemoryUsePercent(double limit) 00074 { 00075 assert(limit > 0.0 && limit <= 100.0); 00076 limit = std::max(0.01, limit); 00077 limit = std::min(100.0, limit); 00078 memory_use_percent = limit; 00079 } 00081 static unsigned int evalRandom() { return eval_random; } 00082 static void setEvalRandom(unsigned int sigma) { eval_random = sigma; } 00083 00084 static void setUsiOutputPawnValue(int new_value) { usi_output_pawn_value = new_value; } 00085 static int usiOutputPawnValue() { return usi_output_pawn_value; } 00087 static int inUnitTest() { return in_unit_test; } 00088 static bool inUnitTestShort() { return in_unit_test == 1; } 00089 static bool inUnitTestLong() { return in_unit_test == 2; } 00090 static void setInUnitTest(int new_value) { in_unit_test = new_value; } 00091 00093 static void setUp(); 00094 static bool hasByoyomi(); 00095 static void setHasByoyomi(bool); 00096 00097 static bool healthCheck(); 00098 static int resignThreshold(); 00099 static std::string configuration(); 00100 private: 00101 static const std::string makeHome(const std::string& first_try=""); 00102 static const std::string makeTest(); 00103 static const std::string makeTestPublic(); 00104 static bool isGoodDir(const std::string&); 00105 static void trySetDir(std::string&, const std::string&); 00106 static void showOslHome(const std::string&); 00107 static size_t memory_use_limit; 00108 static double memory_use_percent; 00109 static const size_t memory_use_limit_system_max; 00110 static unsigned int eval_random; 00111 static bool is_verbose; 00112 static const int default_ncpus; 00113 static int num_cpu; 00114 static volatile UsiMode usi_mode; 00115 static volatile bool usi_mode_silent; 00116 static int usi_output_pawn_value; 00117 static bool search_exact_value_in_one_reply, has_byoyomi; 00118 static volatile bool force_root_window; 00119 static volatile int root_window_alpha, root_window_beta; 00120 static volatile int in_unit_test; 00121 static int dfpn_max_depth; 00122 public: 00123 static std::mutex lock_io; 00124 // designed to be called before main 00125 static void registerInitializer(std::function<void()>); 00126 }; 00127 struct SetUpRegister 00128 { 00129 SetUpRegister(std::function<void()> f) { 00130 OslConfig::registerInitializer(f); 00131 } 00132 }; 00133 struct NoMoreMemory : std::runtime_error 00134 { 00135 NoMoreMemory() : std::runtime_error("memory exhausted") 00136 { 00137 } 00138 }; 00139 } 00140 00141 #endif /* OSL_OSLCONFIG_H */ 00142 // ;;; Local Variables: 00143 // ;;; mode:c++ 00144 // ;;; c-basic-offset:2 00145 // ;;; End: