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