| 1172 | } |
| 1173 | |
| 1174 | void SetupEnvironment() |
| 1175 | { |
| 1176 | #ifdef HAVE_MALLOPT_ARENA_MAX |
| 1177 | // glibc-specific: On 32-bit systems set the number of arenas to 1. |
| 1178 | // By default, since glibc 2.10, the C library will create up to two heap |
| 1179 | // arenas per core. This is known to cause excessive virtual address space |
| 1180 | // usage in our usage. Work around it by setting the maximum number of |
| 1181 | // arenas to 1. |
| 1182 | if (sizeof(void*) == 4) { |
| 1183 | mallopt(M_ARENA_MAX, 1); |
| 1184 | } |
| 1185 | #endif |
| 1186 | // On most POSIX systems (e.g. Linux, but not BSD) the environment's locale |
| 1187 | // may be invalid, in which case the "C" locale is used as fallback. |
| 1188 | #if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__) |
| 1189 | try { |
| 1190 | std::locale(""); // Raises a runtime error if current locale is invalid |
| 1191 | } catch (const std::runtime_error&) { |
| 1192 | setenv("LC_ALL", "C", 1); |
| 1193 | } |
| 1194 | #endif |
| 1195 | // The path locale is lazy initialized and to avoid deinitialization errors |
| 1196 | // in multithreading environments, it is set explicitly by the main thread. |
| 1197 | // A dummy locale is used to extract the internal default locale, used by |
| 1198 | // fs::path, which is then used to explicitly imbue the path. |
| 1199 | std::locale loc = fs::path::imbue(std::locale::classic()); |
| 1200 | fs::path::imbue(loc); |
| 1201 | } |
| 1202 | |
| 1203 | bool SetupNetworking() |
| 1204 | { |