Home ⌂Doc Index ◂Up ▴
Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb_environment.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2018-2020 Intel Corporation
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 #ifndef __TBB_tbb_environment_H
18 #define __TBB_tbb_environment_H
19 
20 #include <cstdlib>
21 #include <cstring>
22 #include <cerrno>
23 #include <cctype>
24 
25 namespace tbb {
26 
27 namespace internal {
28 
29 #if __TBB_WIN8UI_SUPPORT
30 static inline bool GetBoolEnvironmentVariable( const char * ) {
31  return false;
32 }
33 
34 static inline long GetIntegralEnvironmentVariable( const char * ) {
35  return -1;
36 }
37 #else /* __TBB_WIN8UI_SUPPORT */
38 static inline bool GetBoolEnvironmentVariable( const char * name ) {
39  if( const char* s = std::getenv(name) )
40  {
41  // The result is defined as true only if the environment variable contains
42  // no characters except one '1' character and an arbitrary number of spaces
43  // (including the absence of spaces).
44  size_t index = std::strspn(s, " ");
45  if (s[index] != '1') return false;
46  index++;
47  // Memory access after incrementing is safe, since the getenv() returns a
48  // NULL terminated string, and even if the character getting by index is '1',
49  // and this character is the end of string, after incrementing we will get
50  // an index of character, that contains '\0'
51  index += std::strspn(&s[index], " ");
52  return !s[index];
53  }
54  return false;
55 }
56 
57 static inline long GetIntegralEnvironmentVariable( const char * name ) {
58  if( const char* s = std::getenv(name) )
59  {
60  char* end = NULL;
61  errno = 0;
62  long value = std::strtol(s, &end, 10);
63 
64  // We have exceeded the range, value is negative or string is incovertable
65  if ( errno == ERANGE || value < 0 || end==s )
66  {
67  return -1;
68  }
69 
70  for ( ; *end != '\0'; end++ )
71  {
72  if ( !std::isspace(*end) )
73  return -1;
74  }
75 
76  return value;
77  }
78  return -1;
79 }
80 #endif /* __TBB_WIN8UI_SUPPORT */
81 
82 } // namespace internal
83 } // namespace tbb
84 
85 #endif // __TBB_tbb_environment_H
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp end
static long GetIntegralEnvironmentVariable(const char *name)
static bool GetBoolEnvironmentVariable(const char *name)
void const char const char int ITT_FORMAT __itt_group_sync x void const char * name
void const char const char int ITT_FORMAT __itt_group_sync s
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value
The graph class.

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.