grpc 1.26.0 → 1.27.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1654 -1519
  3. data/etc/roots.pem +44 -0
  4. data/include/grpc/grpc_security.h +37 -15
  5. data/include/grpc/grpc_security_constants.h +27 -0
  6. data/include/grpc/impl/codegen/grpc_types.h +14 -0
  7. data/include/grpc/impl/codegen/port_platform.h +1 -1
  8. data/src/core/ext/filters/client_channel/client_channel.cc +0 -20
  9. data/src/core/ext/filters/client_channel/http_proxy.cc +4 -4
  10. data/src/core/ext/filters/client_channel/lb_policy.cc +4 -3
  11. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +191 -201
  12. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +89 -0
  13. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +40 -0
  14. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +3 -2
  15. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +88 -121
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +28 -57
  17. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +0 -7
  18. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +8 -9
  19. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +53 -34
  20. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +18 -5
  21. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +24 -19
  22. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
  23. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +4 -2
  24. data/src/core/ext/filters/client_channel/server_address.cc +6 -9
  25. data/src/core/ext/filters/client_channel/server_address.h +3 -10
  26. data/src/core/ext/filters/client_channel/xds/xds_api.cc +394 -150
  27. data/src/core/ext/filters/client_channel/xds/xds_api.h +75 -35
  28. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +59 -22
  29. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +13 -9
  30. data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +8 -6
  31. data/src/core/ext/filters/client_channel/xds/xds_client.cc +456 -175
  32. data/src/core/ext/filters/client_channel/xds/xds_client.h +33 -21
  33. data/src/core/ext/filters/client_channel/xds/xds_client_stats.cc +5 -8
  34. data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +18 -24
  35. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -2
  36. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +13 -5
  37. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +34 -0
  38. data/src/core/lib/channel/channelz.h +11 -1
  39. data/src/core/lib/gpr/time_precise.cc +1 -1
  40. data/src/core/lib/gprpp/optional.h +26 -0
  41. data/src/core/lib/gprpp/string_view.h +14 -10
  42. data/src/core/lib/iomgr/executor.cc +1 -1
  43. data/src/core/lib/iomgr/fork_posix.cc +4 -0
  44. data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +87 -0
  45. data/src/core/lib/iomgr/poller/eventmanager_libuv.h +88 -0
  46. data/src/core/lib/iomgr/socket_utils_common_posix.cc +14 -0
  47. data/src/core/lib/iomgr/socket_utils_posix.h +12 -0
  48. data/src/core/lib/iomgr/tcp_custom.h +3 -0
  49. data/src/core/lib/iomgr/tcp_posix.cc +607 -56
  50. data/src/core/lib/iomgr/tcp_server_custom.cc +15 -2
  51. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +8 -0
  52. data/src/core/lib/json/json.h +11 -1
  53. data/src/core/lib/json/json_reader.cc +206 -28
  54. data/src/core/lib/json/json_writer.cc +111 -24
  55. data/src/core/lib/security/credentials/composite/composite_credentials.cc +7 -0
  56. data/src/core/lib/security/credentials/composite/composite_credentials.h +5 -1
  57. data/src/core/lib/security/credentials/credentials.h +10 -1
  58. data/src/core/lib/security/credentials/fake/fake_credentials.h +2 -1
  59. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
  60. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -4
  61. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -1
  62. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +20 -0
  63. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +8 -0
  64. data/src/core/lib/security/credentials/tls/{spiffe_credentials.cc → tls_credentials.cc} +23 -24
  65. data/src/core/lib/security/credentials/tls/{spiffe_credentials.h → tls_credentials.h} +9 -9
  66. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +13 -0
  67. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +22 -2
  68. data/src/core/lib/security/security_connector/load_system_roots_fallback.cc +2 -2
  69. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +2 -2
  70. data/src/core/lib/security/security_connector/local/local_security_connector.cc +30 -3
  71. data/src/core/lib/security/security_connector/ssl_utils.cc +45 -3
  72. data/src/core/lib/security/security_connector/ssl_utils.h +12 -0
  73. data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.cc → tls_security_connector.cc} +82 -69
  74. data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.h → tls_security_connector.h} +17 -18
  75. data/src/core/lib/security/transport/client_auth_filter.cc +33 -0
  76. data/src/core/lib/surface/completion_queue.cc +22 -1
  77. data/src/core/lib/surface/version.cc +1 -1
  78. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +11 -1
  79. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +1 -1
  80. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +3 -3
  81. data/src/core/tsi/fake_transport_security.cc +7 -3
  82. data/src/core/tsi/fake_transport_security.h +2 -0
  83. data/src/core/tsi/ssl_transport_security.cc +144 -8
  84. data/src/core/tsi/ssl_transport_security.h +15 -1
  85. data/src/core/tsi/transport_security.cc +13 -0
  86. data/src/core/tsi/transport_security_grpc.cc +2 -2
  87. data/src/core/tsi/transport_security_grpc.h +2 -2
  88. data/src/core/tsi/transport_security_interface.h +12 -0
  89. data/src/ruby/bin/math_pb.rb +5 -5
  90. data/src/ruby/ext/grpc/rb_call_credentials.c +4 -1
  91. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  92. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +4 -1
  93. data/src/ruby/lib/grpc/version.rb +1 -1
  94. data/src/ruby/pb/grpc/health/v1/health_pb.rb +3 -3
  95. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +1 -1
  96. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +23 -13
  97. data/third_party/abseil-cpp/absl/algorithm/algorithm.h +159 -0
  98. data/third_party/abseil-cpp/absl/base/attributes.h +609 -0
  99. data/third_party/abseil-cpp/absl/base/call_once.h +226 -0
  100. data/third_party/abseil-cpp/absl/base/casts.h +184 -0
  101. data/third_party/abseil-cpp/absl/base/config.h +622 -0
  102. data/third_party/abseil-cpp/absl/base/const_init.h +76 -0
  103. data/third_party/abseil-cpp/absl/base/dynamic_annotations.cc +129 -0
  104. data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +389 -0
  105. data/third_party/abseil-cpp/absl/base/internal/atomic_hook.h +179 -0
  106. data/third_party/abseil-cpp/absl/base/internal/bits.h +218 -0
  107. data/third_party/abseil-cpp/absl/base/internal/cycleclock.cc +107 -0
  108. data/third_party/abseil-cpp/absl/base/internal/cycleclock.h +94 -0
  109. data/third_party/abseil-cpp/absl/base/internal/endian.h +266 -0
  110. data/third_party/abseil-cpp/absl/base/internal/hide_ptr.h +51 -0
  111. data/third_party/abseil-cpp/absl/base/internal/identity.h +37 -0
  112. data/third_party/abseil-cpp/absl/base/internal/inline_variable.h +107 -0
  113. data/third_party/abseil-cpp/absl/base/internal/invoke.h +187 -0
  114. data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +107 -0
  115. data/third_party/abseil-cpp/absl/base/internal/per_thread_tls.h +52 -0
  116. data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +237 -0
  117. data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +179 -0
  118. data/third_party/abseil-cpp/absl/base/internal/scheduling_mode.h +58 -0
  119. data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +233 -0
  120. data/third_party/abseil-cpp/absl/base/internal/spinlock.h +243 -0
  121. data/third_party/abseil-cpp/absl/base/internal/spinlock_akaros.inc +35 -0
  122. data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +67 -0
  123. data/third_party/abseil-cpp/absl/base/internal/spinlock_posix.inc +46 -0
  124. data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.cc +81 -0
  125. data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.h +93 -0
  126. data/third_party/abseil-cpp/absl/base/internal/spinlock_win32.inc +37 -0
  127. data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +414 -0
  128. data/third_party/abseil-cpp/absl/base/internal/sysinfo.h +66 -0
  129. data/third_party/abseil-cpp/absl/base/internal/thread_annotations.h +271 -0
  130. data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +140 -0
  131. data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +250 -0
  132. data/third_party/abseil-cpp/absl/base/internal/throw_delegate.cc +108 -0
  133. data/third_party/abseil-cpp/absl/base/internal/throw_delegate.h +75 -0
  134. data/third_party/abseil-cpp/absl/base/internal/tsan_mutex_interface.h +66 -0
  135. data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +158 -0
  136. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +103 -0
  137. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +124 -0
  138. data/third_party/abseil-cpp/absl/base/log_severity.cc +27 -0
  139. data/third_party/abseil-cpp/absl/base/log_severity.h +121 -0
  140. data/third_party/abseil-cpp/absl/base/macros.h +220 -0
  141. data/third_party/abseil-cpp/absl/base/optimization.h +181 -0
  142. data/third_party/abseil-cpp/absl/base/options.h +214 -0
  143. data/third_party/abseil-cpp/absl/base/policy_checks.h +111 -0
  144. data/third_party/abseil-cpp/absl/base/port.h +26 -0
  145. data/third_party/abseil-cpp/absl/base/thread_annotations.h +280 -0
  146. data/third_party/abseil-cpp/absl/container/inlined_vector.h +848 -0
  147. data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +265 -0
  148. data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +892 -0
  149. data/third_party/abseil-cpp/absl/memory/memory.h +695 -0
  150. data/third_party/abseil-cpp/absl/meta/type_traits.h +759 -0
  151. data/third_party/abseil-cpp/absl/numeric/int128.cc +404 -0
  152. data/third_party/abseil-cpp/absl/numeric/int128.h +1091 -0
  153. data/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc +302 -0
  154. data/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc +308 -0
  155. data/third_party/abseil-cpp/absl/strings/ascii.cc +200 -0
  156. data/third_party/abseil-cpp/absl/strings/ascii.h +241 -0
  157. data/third_party/abseil-cpp/absl/strings/charconv.cc +985 -0
  158. data/third_party/abseil-cpp/absl/strings/charconv.h +119 -0
  159. data/third_party/abseil-cpp/absl/strings/escaping.cc +949 -0
  160. data/third_party/abseil-cpp/absl/strings/escaping.h +164 -0
  161. data/third_party/abseil-cpp/absl/strings/internal/char_map.h +156 -0
  162. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +359 -0
  163. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +421 -0
  164. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +504 -0
  165. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.h +99 -0
  166. data/third_party/abseil-cpp/absl/strings/internal/escaping.cc +180 -0
  167. data/third_party/abseil-cpp/absl/strings/internal/escaping.h +58 -0
  168. data/third_party/abseil-cpp/absl/strings/internal/memutil.cc +112 -0
  169. data/third_party/abseil-cpp/absl/strings/internal/memutil.h +148 -0
  170. data/third_party/abseil-cpp/absl/strings/internal/ostringstream.cc +36 -0
  171. data/third_party/abseil-cpp/absl/strings/internal/ostringstream.h +89 -0
  172. data/third_party/abseil-cpp/absl/strings/internal/resize_uninitialized.h +73 -0
  173. data/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h +248 -0
  174. data/third_party/abseil-cpp/absl/strings/internal/str_join_internal.h +314 -0
  175. data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +455 -0
  176. data/third_party/abseil-cpp/absl/strings/internal/utf8.cc +53 -0
  177. data/third_party/abseil-cpp/absl/strings/internal/utf8.h +50 -0
  178. data/third_party/abseil-cpp/absl/strings/match.cc +40 -0
  179. data/third_party/abseil-cpp/absl/strings/match.h +90 -0
  180. data/third_party/abseil-cpp/absl/strings/numbers.cc +916 -0
  181. data/third_party/abseil-cpp/absl/strings/numbers.h +263 -0
  182. data/third_party/abseil-cpp/absl/strings/str_cat.cc +246 -0
  183. data/third_party/abseil-cpp/absl/strings/str_cat.h +408 -0
  184. data/third_party/abseil-cpp/absl/strings/str_join.h +293 -0
  185. data/third_party/abseil-cpp/absl/strings/str_replace.cc +82 -0
  186. data/third_party/abseil-cpp/absl/strings/str_replace.h +219 -0
  187. data/third_party/abseil-cpp/absl/strings/str_split.cc +139 -0
  188. data/third_party/abseil-cpp/absl/strings/str_split.h +513 -0
  189. data/third_party/abseil-cpp/absl/strings/string_view.cc +235 -0
  190. data/third_party/abseil-cpp/absl/strings/string_view.h +615 -0
  191. data/third_party/abseil-cpp/absl/strings/strip.h +91 -0
  192. data/third_party/abseil-cpp/absl/strings/substitute.cc +171 -0
  193. data/third_party/abseil-cpp/absl/strings/substitute.h +693 -0
  194. data/third_party/abseil-cpp/absl/types/bad_optional_access.cc +48 -0
  195. data/third_party/abseil-cpp/absl/types/bad_optional_access.h +78 -0
  196. data/third_party/abseil-cpp/absl/types/internal/optional.h +396 -0
  197. data/third_party/abseil-cpp/absl/types/internal/span.h +128 -0
  198. data/third_party/abseil-cpp/absl/types/optional.h +776 -0
  199. data/third_party/abseil-cpp/absl/types/span.h +713 -0
  200. data/third_party/abseil-cpp/absl/utility/utility.h +350 -0
  201. data/third_party/upb/upb/decode.c +4 -0
  202. data/third_party/upb/upb/port.c +0 -1
  203. data/third_party/upb/upb/port_def.inc +1 -3
  204. data/third_party/upb/upb/table.c +2 -1
  205. metadata +147 -43
  206. data/src/core/lib/json/json_common.h +0 -34
  207. data/src/core/lib/json/json_reader.h +0 -146
  208. data/src/core/lib/json/json_string.cc +0 -367
  209. data/src/core/lib/json/json_writer.h +0 -84
@@ -0,0 +1,66 @@
1
+ // Copyright 2017 The Abseil Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // This file includes routines to find out characteristics
16
+ // of the machine a program is running on. It is undoubtedly
17
+ // system-dependent.
18
+
19
+ // Functions listed here that accept a pid_t as an argument act on the
20
+ // current process if the pid_t argument is 0
21
+ // All functions here are thread-hostile due to file caching unless
22
+ // commented otherwise.
23
+
24
+ #ifndef ABSL_BASE_INTERNAL_SYSINFO_H_
25
+ #define ABSL_BASE_INTERNAL_SYSINFO_H_
26
+
27
+ #ifndef _WIN32
28
+ #include <sys/types.h>
29
+ #endif
30
+
31
+ #include <cstdint>
32
+
33
+ #include "absl/base/port.h"
34
+
35
+ namespace absl {
36
+ ABSL_NAMESPACE_BEGIN
37
+ namespace base_internal {
38
+
39
+ // Nominal core processor cycles per second of each processor. This is _not_
40
+ // necessarily the frequency of the CycleClock counter (see cycleclock.h)
41
+ // Thread-safe.
42
+ double NominalCPUFrequency();
43
+
44
+ // Number of logical processors (hyperthreads) in system. Thread-safe.
45
+ int NumCPUs();
46
+
47
+ // Return the thread id of the current thread, as told by the system.
48
+ // No two currently-live threads implemented by the OS shall have the same ID.
49
+ // Thread ids of exited threads may be reused. Multiple user-level threads
50
+ // may have the same thread ID if multiplexed on the same OS thread.
51
+ //
52
+ // On Linux, you may send a signal to the resulting ID with kill(). However,
53
+ // it is recommended for portability that you use pthread_kill() instead.
54
+ #ifdef _WIN32
55
+ // On Windows, process id and thread id are of the same type according to the
56
+ // return types of GetProcessId() and GetThreadId() are both DWORD, an unsigned
57
+ // 32-bit type.
58
+ using pid_t = uint32_t;
59
+ #endif
60
+ pid_t GetTID();
61
+
62
+ } // namespace base_internal
63
+ ABSL_NAMESPACE_END
64
+ } // namespace absl
65
+
66
+ #endif // ABSL_BASE_INTERNAL_SYSINFO_H_
@@ -0,0 +1,271 @@
1
+ // Copyright 2019 The Abseil Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // -----------------------------------------------------------------------------
16
+ // File: thread_annotations.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // WARNING: This is a backwards compatible header and it will be removed after
20
+ // the migration to prefixed thread annotations is finished; please include
21
+ // "absl/base/thread_annotations.h".
22
+ //
23
+ // This header file contains macro definitions for thread safety annotations
24
+ // that allow developers to document the locking policies of multi-threaded
25
+ // code. The annotations can also help program analysis tools to identify
26
+ // potential thread safety issues.
27
+ //
28
+ // These annotations are implemented using compiler attributes. Using the macros
29
+ // defined here instead of raw attributes allow for portability and future
30
+ // compatibility.
31
+ //
32
+ // When referring to mutexes in the arguments of the attributes, you should
33
+ // use variable names or more complex expressions (e.g. my_object->mutex_)
34
+ // that evaluate to a concrete mutex object whenever possible. If the mutex
35
+ // you want to refer to is not in scope, you may use a member pointer
36
+ // (e.g. &MyClass::mutex_) to refer to a mutex in some (unknown) object.
37
+
38
+ #ifndef ABSL_BASE_INTERNAL_THREAD_ANNOTATIONS_H_
39
+ #define ABSL_BASE_INTERNAL_THREAD_ANNOTATIONS_H_
40
+
41
+ #if defined(__clang__)
42
+ #define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
43
+ #else
44
+ #define THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op
45
+ #endif
46
+
47
+ // GUARDED_BY()
48
+ //
49
+ // Documents if a shared field or global variable needs to be protected by a
50
+ // mutex. GUARDED_BY() allows the user to specify a particular mutex that
51
+ // should be held when accessing the annotated variable.
52
+ //
53
+ // Although this annotation (and PT_GUARDED_BY, below) cannot be applied to
54
+ // local variables, a local variable and its associated mutex can often be
55
+ // combined into a small class or struct, thereby allowing the annotation.
56
+ //
57
+ // Example:
58
+ //
59
+ // class Foo {
60
+ // Mutex mu_;
61
+ // int p1_ GUARDED_BY(mu_);
62
+ // ...
63
+ // };
64
+ #define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
65
+
66
+ // PT_GUARDED_BY()
67
+ //
68
+ // Documents if the memory location pointed to by a pointer should be guarded
69
+ // by a mutex when dereferencing the pointer.
70
+ //
71
+ // Example:
72
+ // class Foo {
73
+ // Mutex mu_;
74
+ // int *p1_ PT_GUARDED_BY(mu_);
75
+ // ...
76
+ // };
77
+ //
78
+ // Note that a pointer variable to a shared memory location could itself be a
79
+ // shared variable.
80
+ //
81
+ // Example:
82
+ //
83
+ // // `q_`, guarded by `mu1_`, points to a shared memory location that is
84
+ // // guarded by `mu2_`:
85
+ // int *q_ GUARDED_BY(mu1_) PT_GUARDED_BY(mu2_);
86
+ #define PT_GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))
87
+
88
+ // ACQUIRED_AFTER() / ACQUIRED_BEFORE()
89
+ //
90
+ // Documents the acquisition order between locks that can be held
91
+ // simultaneously by a thread. For any two locks that need to be annotated
92
+ // to establish an acquisition order, only one of them needs the annotation.
93
+ // (i.e. You don't have to annotate both locks with both ACQUIRED_AFTER
94
+ // and ACQUIRED_BEFORE.)
95
+ //
96
+ // As with GUARDED_BY, this is only applicable to mutexes that are shared
97
+ // fields or global variables.
98
+ //
99
+ // Example:
100
+ //
101
+ // Mutex m1_;
102
+ // Mutex m2_ ACQUIRED_AFTER(m1_);
103
+ #define ACQUIRED_AFTER(...) \
104
+ THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(__VA_ARGS__))
105
+
106
+ #define ACQUIRED_BEFORE(...) \
107
+ THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__))
108
+
109
+ // EXCLUSIVE_LOCKS_REQUIRED() / SHARED_LOCKS_REQUIRED()
110
+ //
111
+ // Documents a function that expects a mutex to be held prior to entry.
112
+ // The mutex is expected to be held both on entry to, and exit from, the
113
+ // function.
114
+ //
115
+ // An exclusive lock allows read-write access to the guarded data member(s), and
116
+ // only one thread can acquire a lock exclusively at any one time. A shared lock
117
+ // allows read-only access, and any number of threads can acquire a shared lock
118
+ // concurrently.
119
+ //
120
+ // Generally, non-const methods should be annotated with
121
+ // EXCLUSIVE_LOCKS_REQUIRED, while const methods should be annotated with
122
+ // SHARED_LOCKS_REQUIRED.
123
+ //
124
+ // Example:
125
+ //
126
+ // Mutex mu1, mu2;
127
+ // int a GUARDED_BY(mu1);
128
+ // int b GUARDED_BY(mu2);
129
+ //
130
+ // void foo() EXCLUSIVE_LOCKS_REQUIRED(mu1, mu2) { ... }
131
+ // void bar() const SHARED_LOCKS_REQUIRED(mu1, mu2) { ... }
132
+ #define EXCLUSIVE_LOCKS_REQUIRED(...) \
133
+ THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(__VA_ARGS__))
134
+
135
+ #define SHARED_LOCKS_REQUIRED(...) \
136
+ THREAD_ANNOTATION_ATTRIBUTE__(shared_locks_required(__VA_ARGS__))
137
+
138
+ // LOCKS_EXCLUDED()
139
+ //
140
+ // Documents the locks acquired in the body of the function. These locks
141
+ // cannot be held when calling this function (as Abseil's `Mutex` locks are
142
+ // non-reentrant).
143
+ #define LOCKS_EXCLUDED(...) \
144
+ THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__))
145
+
146
+ // LOCK_RETURNED()
147
+ //
148
+ // Documents a function that returns a mutex without acquiring it. For example,
149
+ // a public getter method that returns a pointer to a private mutex should
150
+ // be annotated with LOCK_RETURNED.
151
+ #define LOCK_RETURNED(x) \
152
+ THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
153
+
154
+ // LOCKABLE
155
+ //
156
+ // Documents if a class/type is a lockable type (such as the `Mutex` class).
157
+ #define LOCKABLE \
158
+ THREAD_ANNOTATION_ATTRIBUTE__(lockable)
159
+
160
+ // SCOPED_LOCKABLE
161
+ //
162
+ // Documents if a class does RAII locking (such as the `MutexLock` class).
163
+ // The constructor should use `LOCK_FUNCTION()` to specify the mutex that is
164
+ // acquired, and the destructor should use `UNLOCK_FUNCTION()` with no
165
+ // arguments; the analysis will assume that the destructor unlocks whatever the
166
+ // constructor locked.
167
+ #define SCOPED_LOCKABLE \
168
+ THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
169
+
170
+ // EXCLUSIVE_LOCK_FUNCTION()
171
+ //
172
+ // Documents functions that acquire a lock in the body of a function, and do
173
+ // not release it.
174
+ #define EXCLUSIVE_LOCK_FUNCTION(...) \
175
+ THREAD_ANNOTATION_ATTRIBUTE__(exclusive_lock_function(__VA_ARGS__))
176
+
177
+ // SHARED_LOCK_FUNCTION()
178
+ //
179
+ // Documents functions that acquire a shared (reader) lock in the body of a
180
+ // function, and do not release it.
181
+ #define SHARED_LOCK_FUNCTION(...) \
182
+ THREAD_ANNOTATION_ATTRIBUTE__(shared_lock_function(__VA_ARGS__))
183
+
184
+ // UNLOCK_FUNCTION()
185
+ //
186
+ // Documents functions that expect a lock to be held on entry to the function,
187
+ // and release it in the body of the function.
188
+ #define UNLOCK_FUNCTION(...) \
189
+ THREAD_ANNOTATION_ATTRIBUTE__(unlock_function(__VA_ARGS__))
190
+
191
+ // EXCLUSIVE_TRYLOCK_FUNCTION() / SHARED_TRYLOCK_FUNCTION()
192
+ //
193
+ // Documents functions that try to acquire a lock, and return success or failure
194
+ // (or a non-boolean value that can be interpreted as a boolean).
195
+ // The first argument should be `true` for functions that return `true` on
196
+ // success, or `false` for functions that return `false` on success. The second
197
+ // argument specifies the mutex that is locked on success. If unspecified, this
198
+ // mutex is assumed to be `this`.
199
+ #define EXCLUSIVE_TRYLOCK_FUNCTION(...) \
200
+ THREAD_ANNOTATION_ATTRIBUTE__(exclusive_trylock_function(__VA_ARGS__))
201
+
202
+ #define SHARED_TRYLOCK_FUNCTION(...) \
203
+ THREAD_ANNOTATION_ATTRIBUTE__(shared_trylock_function(__VA_ARGS__))
204
+
205
+ // ASSERT_EXCLUSIVE_LOCK() / ASSERT_SHARED_LOCK()
206
+ //
207
+ // Documents functions that dynamically check to see if a lock is held, and fail
208
+ // if it is not held.
209
+ #define ASSERT_EXCLUSIVE_LOCK(...) \
210
+ THREAD_ANNOTATION_ATTRIBUTE__(assert_exclusive_lock(__VA_ARGS__))
211
+
212
+ #define ASSERT_SHARED_LOCK(...) \
213
+ THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_lock(__VA_ARGS__))
214
+
215
+ // NO_THREAD_SAFETY_ANALYSIS
216
+ //
217
+ // Turns off thread safety checking within the body of a particular function.
218
+ // This annotation is used to mark functions that are known to be correct, but
219
+ // the locking behavior is more complicated than the analyzer can handle.
220
+ #define NO_THREAD_SAFETY_ANALYSIS \
221
+ THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
222
+
223
+ //------------------------------------------------------------------------------
224
+ // Tool-Supplied Annotations
225
+ //------------------------------------------------------------------------------
226
+
227
+ // TS_UNCHECKED should be placed around lock expressions that are not valid
228
+ // C++ syntax, but which are present for documentation purposes. These
229
+ // annotations will be ignored by the analysis.
230
+ #define TS_UNCHECKED(x) ""
231
+
232
+ // TS_FIXME is used to mark lock expressions that are not valid C++ syntax.
233
+ // It is used by automated tools to mark and disable invalid expressions.
234
+ // The annotation should either be fixed, or changed to TS_UNCHECKED.
235
+ #define TS_FIXME(x) ""
236
+
237
+ // Like NO_THREAD_SAFETY_ANALYSIS, this turns off checking within the body of
238
+ // a particular function. However, this attribute is used to mark functions
239
+ // that are incorrect and need to be fixed. It is used by automated tools to
240
+ // avoid breaking the build when the analysis is updated.
241
+ // Code owners are expected to eventually fix the routine.
242
+ #define NO_THREAD_SAFETY_ANALYSIS_FIXME NO_THREAD_SAFETY_ANALYSIS
243
+
244
+ // Similar to NO_THREAD_SAFETY_ANALYSIS_FIXME, this macro marks a GUARDED_BY
245
+ // annotation that needs to be fixed, because it is producing thread safety
246
+ // warning. It disables the GUARDED_BY.
247
+ #define GUARDED_BY_FIXME(x)
248
+
249
+ // Disables warnings for a single read operation. This can be used to avoid
250
+ // warnings when it is known that the read is not actually involved in a race,
251
+ // but the compiler cannot confirm that.
252
+ #define TS_UNCHECKED_READ(x) thread_safety_analysis::ts_unchecked_read(x)
253
+
254
+
255
+ namespace thread_safety_analysis {
256
+
257
+ // Takes a reference to a guarded data member, and returns an unguarded
258
+ // reference.
259
+ template <typename T>
260
+ inline const T& ts_unchecked_read(const T& v) NO_THREAD_SAFETY_ANALYSIS {
261
+ return v;
262
+ }
263
+
264
+ template <typename T>
265
+ inline T& ts_unchecked_read(T& v) NO_THREAD_SAFETY_ANALYSIS {
266
+ return v;
267
+ }
268
+
269
+ } // namespace thread_safety_analysis
270
+
271
+ #endif // ABSL_BASE_INTERNAL_THREAD_ANNOTATIONS_H_
@@ -0,0 +1,140 @@
1
+ // Copyright 2017 The Abseil Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include "absl/base/internal/thread_identity.h"
16
+
17
+ #ifndef _WIN32
18
+ #include <pthread.h>
19
+ #include <signal.h>
20
+ #endif
21
+
22
+ #include <atomic>
23
+ #include <cassert>
24
+ #include <memory>
25
+
26
+ #include "absl/base/call_once.h"
27
+ #include "absl/base/internal/raw_logging.h"
28
+ #include "absl/base/internal/spinlock.h"
29
+
30
+ namespace absl {
31
+ ABSL_NAMESPACE_BEGIN
32
+ namespace base_internal {
33
+
34
+ #if ABSL_THREAD_IDENTITY_MODE != ABSL_THREAD_IDENTITY_MODE_USE_CPP11
35
+ namespace {
36
+ // Used to co-ordinate one-time creation of our pthread_key
37
+ absl::once_flag init_thread_identity_key_once;
38
+ pthread_key_t thread_identity_pthread_key;
39
+ std::atomic<bool> pthread_key_initialized(false);
40
+
41
+ void AllocateThreadIdentityKey(ThreadIdentityReclaimerFunction reclaimer) {
42
+ pthread_key_create(&thread_identity_pthread_key, reclaimer);
43
+ pthread_key_initialized.store(true, std::memory_order_release);
44
+ }
45
+ } // namespace
46
+ #endif
47
+
48
+ #if ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_TLS || \
49
+ ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_CPP11
50
+ // The actual TLS storage for a thread's currently associated ThreadIdentity.
51
+ // This is referenced by inline accessors in the header.
52
+ // "protected" visibility ensures that if multiple instances of Abseil code
53
+ // exist within a process (via dlopen() or similar), references to
54
+ // thread_identity_ptr from each instance of the code will refer to
55
+ // *different* instances of this ptr.
56
+ #ifdef __GNUC__
57
+ __attribute__((visibility("protected")))
58
+ #endif // __GNUC__
59
+ #if ABSL_PER_THREAD_TLS
60
+ // Prefer __thread to thread_local as benchmarks indicate it is a bit faster.
61
+ ABSL_PER_THREAD_TLS_KEYWORD ThreadIdentity* thread_identity_ptr = nullptr;
62
+ #elif defined(ABSL_HAVE_THREAD_LOCAL)
63
+ thread_local ThreadIdentity* thread_identity_ptr = nullptr;
64
+ #endif // ABSL_PER_THREAD_TLS
65
+ #endif // TLS or CPP11
66
+
67
+ void SetCurrentThreadIdentity(
68
+ ThreadIdentity* identity, ThreadIdentityReclaimerFunction reclaimer) {
69
+ assert(CurrentThreadIdentityIfPresent() == nullptr);
70
+ // Associate our destructor.
71
+ // NOTE: This call to pthread_setspecific is currently the only immovable
72
+ // barrier to CurrentThreadIdentity() always being async signal safe.
73
+ #if ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC
74
+ // NOTE: Not async-safe. But can be open-coded.
75
+ absl::call_once(init_thread_identity_key_once, AllocateThreadIdentityKey,
76
+ reclaimer);
77
+
78
+ #if defined(__EMSCRIPTEN__) || defined(__MINGW32__)
79
+ // Emscripten and MinGW pthread implementations does not support signals.
80
+ // See https://kripken.github.io/emscripten-site/docs/porting/pthreads.html
81
+ // for more information.
82
+ pthread_setspecific(thread_identity_pthread_key,
83
+ reinterpret_cast<void*>(identity));
84
+ #else
85
+ // We must mask signals around the call to setspecific as with current glibc,
86
+ // a concurrent getspecific (needed for GetCurrentThreadIdentityIfPresent())
87
+ // may zero our value.
88
+ //
89
+ // While not officially async-signal safe, getspecific within a signal handler
90
+ // is otherwise OK.
91
+ sigset_t all_signals;
92
+ sigset_t curr_signals;
93
+ sigfillset(&all_signals);
94
+ pthread_sigmask(SIG_SETMASK, &all_signals, &curr_signals);
95
+ pthread_setspecific(thread_identity_pthread_key,
96
+ reinterpret_cast<void*>(identity));
97
+ pthread_sigmask(SIG_SETMASK, &curr_signals, nullptr);
98
+ #endif // !__EMSCRIPTEN__ && !__MINGW32__
99
+
100
+ #elif ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_TLS
101
+ // NOTE: Not async-safe. But can be open-coded.
102
+ absl::call_once(init_thread_identity_key_once, AllocateThreadIdentityKey,
103
+ reclaimer);
104
+ pthread_setspecific(thread_identity_pthread_key,
105
+ reinterpret_cast<void*>(identity));
106
+ thread_identity_ptr = identity;
107
+ #elif ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_CPP11
108
+ thread_local std::unique_ptr<ThreadIdentity, ThreadIdentityReclaimerFunction>
109
+ holder(identity, reclaimer);
110
+ thread_identity_ptr = identity;
111
+ #else
112
+ #error Unimplemented ABSL_THREAD_IDENTITY_MODE
113
+ #endif
114
+ }
115
+
116
+ void ClearCurrentThreadIdentity() {
117
+ #if ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_TLS || \
118
+ ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_CPP11
119
+ thread_identity_ptr = nullptr;
120
+ #elif ABSL_THREAD_IDENTITY_MODE == \
121
+ ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC
122
+ // pthread_setspecific expected to clear value on destruction
123
+ assert(CurrentThreadIdentityIfPresent() == nullptr);
124
+ #endif
125
+ }
126
+
127
+ #if ABSL_THREAD_IDENTITY_MODE == ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC
128
+ ThreadIdentity* CurrentThreadIdentityIfPresent() {
129
+ bool initialized = pthread_key_initialized.load(std::memory_order_acquire);
130
+ if (!initialized) {
131
+ return nullptr;
132
+ }
133
+ return reinterpret_cast<ThreadIdentity*>(
134
+ pthread_getspecific(thread_identity_pthread_key));
135
+ }
136
+ #endif
137
+
138
+ } // namespace base_internal
139
+ ABSL_NAMESPACE_END
140
+ } // namespace absl