00001 /* ///////////////////////////////////////////////////////////////////////// 00002 * File: winstl/system/system_info.hpp 00003 * 00004 * Purpose: Contains the basic_system_info class, which provides information 00005 * regarding the host system, such as number of processors and 00006 * page size. 00007 * 00008 * Created: 7th February 2002 00009 * Updated: 10th August 2009 00010 * 00011 * Home: http://stlsoft.org/ 00012 * 00013 * Copyright (c) 2002-2009, Matthew Wilson and Synesis Software 00014 * All rights reserved. 00015 * 00016 * Redistribution and use in source and binary forms, with or without 00017 * modification, are permitted provided that the following conditions are met: 00018 * 00019 * - Redistributions of source code must retain the above copyright notice, this 00020 * list of conditions and the following disclaimer. 00021 * - Redistributions in binary form must reproduce the above copyright notice, 00022 * this list of conditions and the following disclaimer in the documentation 00023 * and/or other materials provided with the distribution. 00024 * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of 00025 * any contributors may be used to endorse or promote products derived from 00026 * this software without specific prior written permission. 00027 * 00028 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00029 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00030 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00031 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00032 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00033 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00034 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00035 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00036 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00037 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00038 * POSSIBILITY OF SUCH DAMAGE. 00039 * 00040 * ////////////////////////////////////////////////////////////////////// */ 00041 00042 00050 #ifndef WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_INFO 00051 #define WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_INFO 00052 00053 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION 00054 # define WINSTL_VER_WINSTL_SYSTEM_HPP_SYSTEM_INFO_MAJOR 4 00055 # define WINSTL_VER_WINSTL_SYSTEM_HPP_SYSTEM_INFO_MINOR 0 00056 # define WINSTL_VER_WINSTL_SYSTEM_HPP_SYSTEM_INFO_REVISION 2 00057 # define WINSTL_VER_WINSTL_SYSTEM_HPP_SYSTEM_INFO_EDIT 57 00058 #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */ 00059 00060 /* ///////////////////////////////////////////////////////////////////////// 00061 * Includes 00062 */ 00063 00064 #ifndef WINSTL_INCL_WINSTL_H_WINSTL 00065 # include <winstl/winstl.h> 00066 #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */ 00067 00068 /* ///////////////////////////////////////////////////////////////////////// 00069 * Namespace 00070 */ 00071 00072 #ifndef _WINSTL_NO_NAMESPACE 00073 # if defined(_STLSOFT_NO_NAMESPACE) || \ 00074 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION) 00075 /* There is no stlsoft namespace, so must define ::winstl */ 00076 namespace winstl 00077 { 00078 # else 00079 /* Define stlsoft::winstl_project */ 00080 00081 namespace stlsoft 00082 { 00083 00084 namespace winstl_project 00085 { 00086 00087 # endif /* _STLSOFT_NO_NAMESPACE */ 00088 #endif /* !_WINSTL_NO_NAMESPACE */ 00089 00090 /* ///////////////////////////////////////////////////////////////////////// 00091 * Classes 00092 */ 00093 00104 class system_info 00105 { 00106 public: 00108 typedef system_info class_type; 00109 00110 // Construction 00111 private: 00112 system_info(); 00113 ~system_info() stlsoft_throw_0(); 00114 00115 // Operations 00116 public: 00118 static ws_uint32_t number_of_processors() 00119 { 00120 return get_systeminfo_().dwNumberOfProcessors; 00121 } 00122 00124 static ws_size_t page_size() 00125 { 00126 return get_systeminfo_().dwPageSize; 00127 } 00128 00130 static ws_size_t allocation_granularity() 00131 { 00132 return get_systeminfo_().dwAllocationGranularity; 00133 } 00134 00136 static SYSTEM_INFO const& get_systeminfo() 00137 { 00138 return get_systeminfo_(); 00139 } 00140 00141 // Implementation 00142 private: 00146 static SYSTEM_INFO const& get_systeminfo_() 00147 { 00148 #if defined(STLSOFT_COMPILER_IS_MSVC) && \ 00149 _MSC_VER >= 1310 00150 // Safe to suppress these warnings, because race-conditions are benign here 00151 # pragma warning(push) 00152 # pragma warning(disable : 4640) 00153 #endif /* compiler */ 00154 00155 static SYSTEM_INFO s_systeminfo; 00156 #ifdef STLSOFT_COMPILER_IS_BORLAND 00157 /* WSCB: Borland has an internal compiler error if use ws_bool_t */ 00158 static ws_int_t s_init = (::GetSystemInfo(&s_systeminfo), ws_true_v); 00159 #else /* ? compiler */ 00160 static ws_bool_t s_init = (::GetSystemInfo(&s_systeminfo), ws_true_v); 00161 #endif /* compiler */ 00162 00163 STLSOFT_SUPPRESS_UNUSED(s_init); 00164 00165 return s_systeminfo; 00166 00167 #if defined(STLSOFT_COMPILER_IS_MSVC) && \ 00168 _MSC_VER >= 1310 00169 # pragma warning(pop) 00170 #endif /* compiler */ 00171 } 00172 }; 00173 00175 // Unit-testing 00176 00177 #ifdef STLSOFT_UNITTEST 00178 # include "./unittest/system_info_unittest_.h" 00179 #endif /* STLSOFT_UNITTEST */ 00180 00181 /* ////////////////////////////////////////////////////////////////////// */ 00182 00183 #ifndef _WINSTL_NO_NAMESPACE 00184 # if defined(_STLSOFT_NO_NAMESPACE) || \ 00185 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION) 00186 } // namespace winstl 00187 # else 00188 } // namespace winstl_project 00189 } // namespace stlsoft 00190 # endif /* _STLSOFT_NO_NAMESPACE */ 00191 #endif /* !_WINSTL_NO_NAMESPACE */ 00192 00193 /* ////////////////////////////////////////////////////////////////////// */ 00194 00195 #endif /* WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_INFO */ 00196 00197 /* ///////////////////////////// end of file //////////////////////////// */