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 bool usiMode(); 00044 static void setUsiMode(bool enable=true); 00045 static bool usiModeInSilent(); 00046 static void setUsiSilent(bool silent=true); 00047 00048 static bool searchExactValueInOneReply(); 00049 static void setSearchExactValueInOneReply(bool new_value); 00050 00051 static size_t residentMemoryUse(); 00052 static size_t memoryUseLimit() 00053 { 00054 return static_cast<size_t>(memory_use_limit * memory_use_percent / 100.0); 00055 } 00056 static void setMemoryUseLimit(size_t limit) { memory_use_limit = limit; } 00057 static double memoryUseRatio() 00058 { 00059 return residentMemoryUse() * 1.0 / memoryUseLimit(); 00060 } 00061 static bool isMemoryLimitEffective() 00062 { 00063 return memory_use_limit != memory_use_limit_system_max 00064 && residentMemoryUse() > 0; 00065 } 00066 static void setMemoryUsePercent(double limit) 00067 { 00068 assert(limit > 0.0 && limit <= 100.0); 00069 limit = std::max(0.01, limit); 00070 limit = std::min(100.0, limit); 00071 memory_use_percent = limit; 00072 } 00074 static unsigned int evalRandom() { return eval_random; } 00075 static void setEvalRandom(unsigned int sigma) { eval_random = sigma; } 00076 00077 static void setUsiOutputPawnValue(int new_value) { usi_output_pawn_value = new_value; } 00078 static int usiOutputPawnValue() { return usi_output_pawn_value; } 00079 static bool forceRootWindow() { return force_root_window; } 00080 static std::pair<int,int> rootWindow() 00081 { 00082 return std::make_pair(root_window_alpha, root_window_beta); 00083 } 00084 static void setRootWindow(int alpha, int beta) 00085 { 00086 root_window_alpha = alpha; 00087 root_window_beta = beta; 00088 force_root_window = true; 00089 } 00090 static void resetRootWindow() { force_root_window = false; } 00092 static int inUnitTest() { return in_unit_test; } 00093 static bool inUnitTestShort() { return in_unit_test == 1; } 00094 static bool inUnitTestLong() { return in_unit_test == 2; } 00095 static void setInUnitTest(int new_value) { in_unit_test = new_value; } 00096 00098 static void setUp(); 00099 static bool hasByoyomi(); 00100 static void setHasByoyomi(bool); 00101 private: 00102 static const std::string makeHome(); 00103 static const std::string makeTest(); 00104 static const std::string makeTestPublic(); 00105 static bool isGoodDir(const std::string&); 00106 static void trySetDir(std::string&, const std::string&); 00107 static void showOslHome(const std::string&); 00108 static size_t memory_use_limit; 00109 static double memory_use_percent; 00110 static const size_t memory_use_limit_system_max; 00111 static unsigned int eval_random; 00112 static bool is_verbose; 00113 static const int default_ncpus; 00114 static int num_cpu; 00115 static volatile bool usi_mode, 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 public: 00122 static boost::mutex lock_io; 00123 }; 00124 00125 struct NoMoreMemory : std::runtime_error 00126 { 00127 NoMoreMemory() : std::runtime_error("memory exhausted") 00128 { 00129 } 00130 }; 00131 } 00132 00133 #endif /* OSL_OSLCONFIG_H */ 00134 // ;;; Local Variables: 00135 // ;;; mode:c++ 00136 // ;;; c-basic-offset:2 00137 // ;;; End: