Skip to content

Commit 436ba6c

Browse files
Abseil TeamAndy Soffer
authored andcommitted
Export of internal Abseil changes.
-- 22fceefcf070a0cf89bf1846bee16a9d36ad4161 by Derek Mauro <[email protected]>: Use function static for once initialization of flag registry. This is a workaround for the MSVC debug constexpr initialization issue in absl::once_flag. GitHub #304 PiperOrigin-RevId: 248169007 -- 97bbe6a5233802b61e758c55f7ba8926539cc4ca by Chris Kennelly <[email protected]>: Internal change PiperOrigin-RevId: 248139347 -- e72640ee079b9fa44e2c7f925fa0a608bcfea515 by Derek Mauro <[email protected]>: Re-write flags config. It doesn't have to be written in the convoluted way it currently is in the opensource-only code path. PiperOrigin-RevId: 248010502 -- 2a72552511b8086c78cb43012c1644e519b3807e by Abseil Team <[email protected]>: Handle pthread_getschedparam() failure. Log an error message if pthread_getschedparam() fails. In Android's Media Framework, libminijail (which I believe is a sandbox) aborts the process if pthread_getschedparam() is called: media.swcodec: libminijail[7526]: blocked syscall: sched_getparam ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ /system/bin/tombstoned: received crash request for pid 7526 Although this CL cannot handle that extreme failure mode, it handles an error return from pthread_getschedparam() and won't use the uninitialized param.sched_priority value in that case. PiperOrigin-RevId: 247999953 -- bb154a92be37987d00d652c7c792594f2f515d83 by Abseil Team <[email protected]>: Allow intrinsic int128 to be set for __aarch64__ targets. PiperOrigin-RevId: 247977594 GitOrigin-RevId: 22fceefcf070a0cf89bf1846bee16a9d36ad4161 Change-Id: I1f7ccfd82eb71446277a8e6f542fe835ac173d71
1 parent 0cbdc77 commit 436ba6c

File tree

8 files changed

+114
-45
lines changed

8 files changed

+114
-45
lines changed

absl/base/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ load(
1818
"//absl:copts/configure_copts.bzl",
1919
"ABSL_DEFAULT_COPTS",
2020
"ABSL_DEFAULT_LINKOPTS",
21-
"ABSL_TEST_COPTS",
2221
"ABSL_EXCEPTIONS_FLAG",
2322
"ABSL_EXCEPTIONS_FLAG_LINKOPTS",
23+
"ABSL_TEST_COPTS",
2424
)
2525

2626
package(default_visibility = ["//visibility:public"])

absl/base/config.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,13 @@
191191
// * On Clang:
192192
// * Building using Clang for Windows, where the Clang runtime library has
193193
// 128-bit support only on LP64 architectures, but Windows is LLP64.
194-
// * Building for aarch64, where __int128 exists but has exhibits a sporadic
195-
// compiler crashing bug.
196194
// * On Nvidia's nvcc:
197195
// * nvcc also defines __GNUC__ and __SIZEOF_INT128__, but not all versions
198196
// actually support __int128.
199197
#ifdef ABSL_HAVE_INTRINSIC_INT128
200198
#error ABSL_HAVE_INTRINSIC_INT128 cannot be directly set
201199
#elif defined(__SIZEOF_INT128__)
202-
#if (defined(__clang__) && !defined(_WIN32) && !defined(__aarch64__)) || \
200+
#if (defined(__clang__) && !defined(_WIN32)) || \
203201
(defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) || \
204202
(defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__))
205203
#define ABSL_HAVE_INTRINSIC_INT128 1

absl/flags/BUILD.bazel

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,20 @@ cc_test(
219219
],
220220
)
221221

222+
cc_test(
223+
name = "config_test",
224+
size = "small",
225+
srcs = [
226+
"config_test.cc",
227+
],
228+
copts = ABSL_TEST_COPTS,
229+
linkopts = ABSL_DEFAULT_LINKOPTS,
230+
deps = [
231+
":config",
232+
"@com_google_googletest//:gtest_main",
233+
],
234+
)
235+
222236
cc_test(
223237
name = "flag_test",
224238
size = "small",

absl/flags/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ absl_cc_test(
201201
gtest_main
202202
)
203203

204+
absl_cc_test(
205+
NAME
206+
flags_config_test
207+
SRCS
208+
"config_test.cc"
209+
COPTS
210+
${ABSL_TEST_COPTS}
211+
DEPS
212+
absl::flags_config
213+
gtest_main
214+
)
215+
204216
absl_cc_test(
205217
NAME
206218
flags_flag_test

absl/flags/config.h

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,32 @@
1717
#define ABSL_FLAGS_CONFIG_H_
1818

1919
// Determine if we should strip string literals from the Flag objects.
20+
// By default we strip string literals on mobile platforms.
2021
#if !defined(ABSL_FLAGS_STRIP_NAMES)
2122

22-
// Non-mobile linux platforms don't strip string literals.
23-
#if (defined(__linux__) || defined(__Fuchsia__)) && !defined(__ANDROID__)
24-
#define ABSL_FLAGS_STRIP_NAMES 0
23+
#if defined(__ANDROID__)
24+
#define ABSL_FLAGS_STRIP_NAMES 1
2525

26-
// So do Macs (not iOS or embedded Apple platforms).
2726
#elif defined(__APPLE__)
2827
#include <TargetConditionals.h>
29-
#if !TARGET_OS_IPHONE && !TARGET_OS_EMBEDDED
30-
#define ABSL_FLAGS_STRIP_NAMES 0
28+
#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
29+
#define ABSL_FLAGS_STRIP_NAMES 1
30+
#elif defined(TARGET_OS_EMBEDDED) && TARGET_OS_EMBEDDED
31+
#define ABSL_FLAGS_STRIP_NAMES 1
32+
#endif // TARGET_OS_*
3133
#endif
3234

33-
// And Windows.
34-
#elif defined(_WIN32)
35-
#define ABSL_FLAGS_STRIP_NAMES 0
35+
#endif // !defined(ABSL_FLAGS_STRIP_NAMES)
3636

37-
// And Myriad.
38-
#elif defined(__myriad2__)
37+
#if !defined(ABSL_FLAGS_STRIP_NAMES)
38+
// If ABSL_FLAGS_STRIP_NAMES wasn't set on the command line or above,
39+
// the default is not to strip.
3940
#define ABSL_FLAGS_STRIP_NAMES 0
40-
4141
#endif
42-
#endif // !defined(ABSL_FLAGS_STRIP_NAMES)
4342

44-
#if ABSL_FLAGS_STRIP_NAMES
4543
#if !defined(ABSL_FLAGS_STRIP_HELP)
46-
#define ABSL_FLAGS_STRIP_HELP 1
47-
#endif
48-
#else
49-
#if !defined(ABSL_FLAGS_STRIP_HELP)
50-
#define ABSL_FLAGS_STRIP_HELP 0
51-
#endif
44+
// By default, if we strip names, we also strip help.
45+
#define ABSL_FLAGS_STRIP_HELP ABSL_FLAGS_STRIP_NAMES
5246
#endif
5347

5448
#endif // ABSL_FLAGS_CONFIG_H_

absl/flags/config_test.cc

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
#include "absl/flags/config.h"
16+
17+
#ifdef __APPLE__
18+
#include <TargetConditionals.h>
19+
#endif
20+
21+
#include "gtest/gtest.h"
22+
23+
#ifndef ABSL_FLAGS_STRIP_NAMES
24+
#error ABSL_FLAGS_STRIP_NAMES is not defined
25+
#endif
26+
27+
#ifndef ABSL_FLAGS_STRIP_HELP
28+
#error ABSL_FLAGS_STRIP_HELP is not defined
29+
#endif
30+
31+
namespace {
32+
33+
// Test that ABSL_FLAGS_STRIP_NAMES and ABSL_FLAGS_STRIP_HELP are configured how
34+
// we expect them to be configured by default. If you override this
35+
// configuration, this test will fail, but the code should still be safe to use.
36+
TEST(FlagsConfigTest, Test) {
37+
#if defined(__ANDROID__)
38+
EXPECT_EQ(ABSL_FLAGS_STRIP_NAMES, 1);
39+
EXPECT_EQ(ABSL_FLAGS_STRIP_HELP, 1);
40+
#elif defined(__myriad2__)
41+
EXPECT_EQ(ABSL_FLAGS_STRIP_NAMES, 0);
42+
EXPECT_EQ(ABSL_FLAGS_STRIP_HELP, 0);
43+
#elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
44+
EXPECT_EQ(ABSL_FLAGS_STRIP_NAMES, 1);
45+
EXPECT_EQ(ABSL_FLAGS_STRIP_HELP, 1);
46+
#elif defined(TARGET_OS_EMBEDDED) && TARGET_OS_EMBEDDED
47+
EXPECT_EQ(ABSL_FLAGS_STRIP_NAMES, 1);
48+
EXPECT_EQ(ABSL_FLAGS_STRIP_HELP, 1);
49+
#elif defined(__APPLE__)
50+
EXPECT_EQ(ABSL_FLAGS_STRIP_NAMES, 0);
51+
EXPECT_EQ(ABSL_FLAGS_STRIP_HELP, 0);
52+
#elif defined(_WIN32)
53+
EXPECT_EQ(ABSL_FLAGS_STRIP_NAMES, 0);
54+
EXPECT_EQ(ABSL_FLAGS_STRIP_HELP, 0);
55+
#elif defined(__linux__)
56+
EXPECT_EQ(ABSL_FLAGS_STRIP_NAMES, 0);
57+
EXPECT_EQ(ABSL_FLAGS_STRIP_HELP, 0);
58+
#endif
59+
}
60+
61+
} // namespace

absl/flags/internal/registry.cc

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "absl/flags/internal/registry.h"
1717

18-
#include "absl/base/call_once.h"
1918
#include "absl/base/dynamic_annotations.h"
2019
#include "absl/base/internal/raw_logging.h"
2120
#include "absl/flags/config.h"
@@ -151,29 +150,16 @@ class FlagRegistry {
151150

152151
FlagPtrMap flag_ptr_map_;
153152

154-
static FlagRegistry* global_registry_; // a singleton registry
155-
156-
static absl::once_flag global_registry_once_;
157-
158-
static void InitGlobalRegistry();
159-
160153
absl::Mutex lock_;
161154

162155
// Disallow
163156
FlagRegistry(const FlagRegistry&);
164157
FlagRegistry& operator=(const FlagRegistry&);
165158
};
166159

167-
// Get the singleton FlagRegistry object
168-
FlagRegistry* FlagRegistry::global_registry_ = nullptr;
169-
absl::once_flag FlagRegistry::global_registry_once_;
170-
171-
void FlagRegistry::InitGlobalRegistry() { global_registry_ = new FlagRegistry; }
172-
173160
FlagRegistry* FlagRegistry::GlobalRegistry() {
174-
absl::call_once(global_registry_once_, &InitGlobalRegistry);
175-
176-
return global_registry_;
161+
static FlagRegistry* global_registry = new FlagRegistry;
162+
return global_registry;
177163
}
178164

179165
namespace {

absl/synchronization/mutex.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -901,11 +901,15 @@ static PerThreadSynch *Enqueue(PerThreadSynch *head,
901901
// base_internal::CycleClock::Now() is 0.5%.
902902
int policy;
903903
struct sched_param param;
904-
pthread_getschedparam(pthread_self(), &policy, &param);
905-
s->priority = param.sched_priority;
906-
s->next_priority_read_cycles =
907-
now_cycles +
908-
static_cast<int64_t>(base_internal::CycleClock::Frequency());
904+
const int err = pthread_getschedparam(pthread_self(), &policy, &param);
905+
if (err != 0) {
906+
ABSL_RAW_LOG(ERROR, "pthread_getschedparam failed: %d", err);
907+
} else {
908+
s->priority = param.sched_priority;
909+
s->next_priority_read_cycles =
910+
now_cycles +
911+
static_cast<int64_t>(base_internal::CycleClock::Frequency());
912+
}
909913
}
910914
if (s->priority > head->priority) { // s's priority is above head's
911915
// try to put s in priority-fifo order, or failing that at the front.

0 commit comments

Comments
 (0)