flag.cc
Go to the documentation of this file.
00001 //
00002 //  Copyright 2019 The Abseil Authors.
00003 //
00004 // Licensed under the Apache License, Version 2.0 (the "License");
00005 // you may not use this file except in compliance with the License.
00006 // You may obtain a copy of the License at
00007 //
00008 //      https://www.apache.org/licenses/LICENSE-2.0
00009 //
00010 // Unless required by applicable law or agreed to in writing, software
00011 // distributed under the License is distributed on an "AS IS" BASIS,
00012 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013 // See the License for the specific language governing permissions and
00014 // limitations under the License.
00015 
00016 #include "absl/flags/flag.h"
00017 
00018 #include <cstring>
00019 
00020 namespace absl {
00021 
00022 // We want to validate the type mismatch between type definition and
00023 // declaration. The lock-free implementation does not allow us to do it,
00024 // so in debug builds we always use the slower implementation, which always
00025 // validates the type.
00026 #ifndef NDEBUG
00027 #define ABSL_FLAGS_ATOMIC_GET(T)                              \
00028   T GetFlag(const absl::Flag<T>& flag) {                      \
00029     T result;                                                 \
00030     flag.internal.Read(&result, &flags_internal::FlagOps<T>); \
00031     return result;                                            \
00032   }
00033 #else
00034 #define ABSL_FLAGS_ATOMIC_GET(T)                                            \
00035   T GetFlag(const absl::Flag<T>& flag) {                                    \
00036     const int64_t r = flag.internal.atomic.load(std::memory_order_acquire); \
00037     if (r != flags_internal::CommandLineFlag::kAtomicInit) {                \
00038       T t;                                                                  \
00039       memcpy(&t, &r, sizeof(T));                                            \
00040       return t;                                                             \
00041     }                                                                       \
00042     T result;                                                               \
00043     flag.internal.Read(&result, &flags_internal::FlagOps<T>);               \
00044     return result;                                                          \
00045   }
00046 #endif
00047 
00048 ABSL_FLAGS_INTERNAL_FOR_EACH_LOCK_FREE(ABSL_FLAGS_ATOMIC_GET)
00049 
00050 #undef ABSL_FLAGS_ATOMIC_GET
00051 
00052 }  // namespace absl


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:14