diff options
-rw-r--r-- | BUILD.gn | 4 | ||||
-rw-r--r-- | common_audio/resampler/sinc_resampler.cc | 4 | ||||
-rw-r--r-- | common_audio/resampler/sinc_resampler.h | 2 | ||||
-rw-r--r-- | rtc_base/checks.cc | 5 | ||||
-rw-r--r-- | rtc_base/checks.h | 15 | ||||
-rw-r--r-- | rtc_base/system/BUILD.gn | 12 | ||||
-rw-r--r-- | rtc_base/system/arch.h | 58 | ||||
-rw-r--r-- | rtc_base/system/unused.h | 39 | ||||
-rw-r--r-- | typedefs.h | 102 |
9 files changed, 134 insertions, 107 deletions
@@ -377,6 +377,10 @@ rtc_source_set("typedefs") { sources = [ "typedefs.h", ] + deps = [ + "rtc_base/system:arch", + "rtc_base/system:unused", + ] } rtc_static_library("webrtc_common") { diff --git a/common_audio/resampler/sinc_resampler.cc b/common_audio/resampler/sinc_resampler.cc index c8577550c9..2ea91963e8 100644 --- a/common_audio/resampler/sinc_resampler.cc +++ b/common_audio/resampler/sinc_resampler.cc @@ -160,12 +160,12 @@ SincResampler::SincResampler(double io_sample_rate_ratio, AlignedMalloc(sizeof(float) * kKernelStorageSize, 16))), input_buffer_(static_cast<float*>( AlignedMalloc(sizeof(float) * input_buffer_size_, 16))), -#if defined(WEBRTC_CPU_DETECTION) +#if defined(WEBRTC_ARCH_X86_FAMILY) && !defined(__SSE2__) convolve_proc_(nullptr), #endif r1_(input_buffer_.get()), r2_(input_buffer_.get() + kKernelSize / 2) { -#if defined(WEBRTC_CPU_DETECTION) +#if defined(WEBRTC_ARCH_X86_FAMILY) && !defined(__SSE2__) InitializeCPUSpecificFeatures(); RTC_DCHECK(convolve_proc_); #endif diff --git a/common_audio/resampler/sinc_resampler.h b/common_audio/resampler/sinc_resampler.h index 774a9b74f0..deef7f63e4 100644 --- a/common_audio/resampler/sinc_resampler.h +++ b/common_audio/resampler/sinc_resampler.h @@ -149,7 +149,7 @@ class SincResampler { // TODO(ajm): Move to using a global static which must only be initialized // once by the user. We're not doing this initially, because we don't have // e.g. a LazyInstance helper in webrtc. -#if defined(WEBRTC_CPU_DETECTION) +#if defined(WEBRTC_ARCH_X86_FAMILY) && !defined(__SSE2__) typedef float (*ConvolveProc)(const float*, const float*, const float*, double); ConvolveProc convolve_proc_; diff --git a/rtc_base/checks.cc b/rtc_base/checks.cc index 820ca966a4..ebe53b876e 100644 --- a/rtc_base/checks.cc +++ b/rtc_base/checks.cc @@ -76,7 +76,7 @@ FatalMessage::FatalMessage(const char* file, int line, std::string* result) { delete result; } -NO_RETURN FatalMessage::~FatalMessage() { +RTC_NORETURN FatalMessage::~FatalMessage() { fflush(stdout); fflush(stderr); stream_ << std::endl << "#" << std::endl; @@ -112,6 +112,7 @@ template std::string* MakeCheckOpString<std::string, std::string>( } // namespace rtc // Function to call from the C version of the RTC_CHECK and RTC_DCHECK macros. -NO_RETURN void rtc_FatalMessage(const char* file, int line, const char* msg) { +RTC_NORETURN void rtc_FatalMessage(const char* file, int line, + const char* msg) { rtc::FatalMessage(file, line).stream() << msg; } diff --git a/rtc_base/checks.h b/rtc_base/checks.h index e9a19e6051..76b849f619 100644 --- a/rtc_base/checks.h +++ b/rtc_base/checks.h @@ -11,8 +11,6 @@ #ifndef RTC_BASE_CHECKS_H_ #define RTC_BASE_CHECKS_H_ -#include "typedefs.h" // NOLINT(build/include) - // If you for some reson need to know if DCHECKs are on, test the value of // RTC_DCHECK_IS_ON. (Test its value, not if it's defined; it'll always be // defined, to either a true or a false value.) @@ -22,10 +20,19 @@ #define RTC_DCHECK_IS_ON 0 #endif +// Annotate a function that will not return control flow to the caller. +#if defined(_MSC_VER) +#define RTC_NORETURN __declspec(noreturn) +#elif defined(__GNUC__) +#define RTC_NORETURN __attribute__ ((__noreturn__)) +#else +#define RTC_NORETURN +#endif + #ifdef __cplusplus extern "C" { #endif -NO_RETURN void rtc_FatalMessage(const char* file, int line, const char* msg); +RTC_NORETURN void rtc_FatalMessage(const char* file, int line, const char* msg); #ifdef __cplusplus } // extern "C" #endif @@ -233,7 +240,7 @@ class FatalMessage { FatalMessage(const char* file, int line); // Used for RTC_CHECK_EQ(), etc. Takes ownership of the given string. FatalMessage(const char* file, int line, std::string* result); - NO_RETURN ~FatalMessage(); + RTC_NORETURN ~FatalMessage(); std::ostream& stream() { return stream_; } diff --git a/rtc_base/system/BUILD.gn b/rtc_base/system/BUILD.gn index 0e42eba9aa..02ffaa79e9 100644 --- a/rtc_base/system/BUILD.gn +++ b/rtc_base/system/BUILD.gn @@ -12,6 +12,12 @@ if (is_android) { import("//build/config/android/rules.gni") } +rtc_source_set("arch") { + sources = [ + "arch.h", + ] +} + rtc_source_set("asm_defines") { sources = [ "asm_defines.h", @@ -48,3 +54,9 @@ rtc_source_set("no_inline") { "no_inline.h", ] } + +rtc_source_set("unused") { + sources = [ + "unused.h", + ] +} diff --git a/rtc_base/system/arch.h b/rtc_base/system/arch.h new file mode 100644 index 0000000000..a2a1180644 --- /dev/null +++ b/rtc_base/system/arch.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +// This file contains platform-specific typedefs and defines. +// Much of it is derived from Chromium's build/build_config.h. + +#ifndef RTC_BASE_SYSTEM_ARCH_H_ +#define RTC_BASE_SYSTEM_ARCH_H_ + +// Processor architecture detection. For more info on what's defined, see: +// http://msdn.microsoft.com/en-us/library/b0084kay.aspx +// http://www.agner.org/optimize/calling_conventions.pdf +// or with gcc, run: "echo | gcc -E -dM -" +#if defined(_M_X64) || defined(__x86_64__) +#define WEBRTC_ARCH_X86_FAMILY +#define WEBRTC_ARCH_X86_64 +#define WEBRTC_ARCH_64_BITS +#define WEBRTC_ARCH_LITTLE_ENDIAN +#elif defined(__aarch64__) +#define WEBRTC_ARCH_ARM_FAMILY +#define WEBRTC_ARCH_64_BITS +#define WEBRTC_ARCH_LITTLE_ENDIAN +#elif defined(_M_IX86) || defined(__i386__) +#define WEBRTC_ARCH_X86_FAMILY +#define WEBRTC_ARCH_X86 +#define WEBRTC_ARCH_32_BITS +#define WEBRTC_ARCH_LITTLE_ENDIAN +#elif defined(__ARMEL__) +#define WEBRTC_ARCH_ARM_FAMILY +#define WEBRTC_ARCH_32_BITS +#define WEBRTC_ARCH_LITTLE_ENDIAN +#elif defined(__MIPSEL__) +#define WEBRTC_ARCH_MIPS_FAMILY +#if defined(__LP64__) +#define WEBRTC_ARCH_64_BITS +#else +#define WEBRTC_ARCH_32_BITS +#endif +#define WEBRTC_ARCH_LITTLE_ENDIAN +#elif defined(__pnacl__) +#define WEBRTC_ARCH_32_BITS +#define WEBRTC_ARCH_LITTLE_ENDIAN +#else +#error Please add support for your architecture in typedefs.h +#endif + +#if !(defined(WEBRTC_ARCH_LITTLE_ENDIAN) ^ defined(WEBRTC_ARCH_BIG_ENDIAN)) +#error Define either WEBRTC_ARCH_LITTLE_ENDIAN or WEBRTC_ARCH_BIG_ENDIAN +#endif + +#endif // RTC_BASE_SYSTEM_ARCH_H_ diff --git a/rtc_base/system/unused.h b/rtc_base/system/unused.h new file mode 100644 index 0000000000..a0add4ee29 --- /dev/null +++ b/rtc_base/system/unused.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef RTC_BASE_SYSTEM_UNUSED_H_ +#define RTC_BASE_SYSTEM_UNUSED_H_ + +// Annotate a function indicating the caller must examine the return value. +// Use like: +// int foo() RTC_WARN_UNUSED_RESULT; +// To explicitly ignore a result, cast to void. +// TODO(kwiberg): Remove when we can use [[nodiscard]] from C++17. +#if defined(__clang__) +#define RTC_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) +#elif defined(__GNUC__) +// gcc has a __warn_unused_result__ attribute, but you can't quiet it by +// casting to void, so we don't use it. +#define RTC_WARN_UNUSED_RESULT +#else +#define RTC_WARN_UNUSED_RESULT +#endif + +// Prevent the compiler from warning about an unused variable. For example: +// int result = DoSomething(); +// assert(result == 17); +// RTC_UNUSED(result); +// Note: In most cases it is better to remove the unused variable rather than +// suppressing the compiler warning. +#ifndef RTC_UNUSED +#define RTC_UNUSED(x) static_cast<void>(x) +#endif // RTC_UNUSED + +#endif // RTC_BASE_SYSTEM_UNUSED_H_ diff --git a/typedefs.h b/typedefs.h index 073b18024a..dd10048ca4 100644 --- a/typedefs.h +++ b/typedefs.h @@ -8,108 +8,14 @@ * be found in the AUTHORS file in the root of the source tree. */ -// This file contains platform-specific typedefs and defines. -// Much of it is derived from Chromium's build/build_config.h. - +// TODO(solenberg): Make the files including typedefs.h directly include the +// files below they need. #ifndef TYPEDEFS_H_ #define TYPEDEFS_H_ -// Processor architecture detection. For more info on what's defined, see: -// http://msdn.microsoft.com/en-us/library/b0084kay.aspx -// http://www.agner.org/optimize/calling_conventions.pdf -// or with gcc, run: "echo | gcc -E -dM -" -#if defined(_M_X64) || defined(__x86_64__) -#define WEBRTC_ARCH_X86_FAMILY -#define WEBRTC_ARCH_X86_64 -#define WEBRTC_ARCH_64_BITS -#define WEBRTC_ARCH_LITTLE_ENDIAN -#elif defined(__aarch64__) -#define WEBRTC_ARCH_ARM_FAMILY -#define WEBRTC_ARCH_64_BITS -#define WEBRTC_ARCH_LITTLE_ENDIAN -#elif defined(_M_IX86) || defined(__i386__) -#define WEBRTC_ARCH_X86_FAMILY -#define WEBRTC_ARCH_X86 -#define WEBRTC_ARCH_32_BITS -#define WEBRTC_ARCH_LITTLE_ENDIAN -#elif defined(__ARMEL__) -#define WEBRTC_ARCH_ARM_FAMILY -#define WEBRTC_ARCH_32_BITS -#define WEBRTC_ARCH_LITTLE_ENDIAN -#elif defined(__MIPSEL__) -#define WEBRTC_ARCH_MIPS_FAMILY -#if defined(__LP64__) -#define WEBRTC_ARCH_64_BITS -#else -#define WEBRTC_ARCH_32_BITS -#endif -#define WEBRTC_ARCH_LITTLE_ENDIAN -#elif defined(__pnacl__) -#define WEBRTC_ARCH_32_BITS -#define WEBRTC_ARCH_LITTLE_ENDIAN -#else -#error Please add support for your architecture in typedefs.h -#endif - -#if !(defined(WEBRTC_ARCH_LITTLE_ENDIAN) ^ defined(WEBRTC_ARCH_BIG_ENDIAN)) -#error Define either WEBRTC_ARCH_LITTLE_ENDIAN or WEBRTC_ARCH_BIG_ENDIAN -#endif - -// TODO(zhongwei.yao): WEBRTC_CPU_DETECTION is only used in one place; we should -// probably just remove it. -#if (defined(WEBRTC_ARCH_X86_FAMILY) && !defined(__SSE2__)) -#define WEBRTC_CPU_DETECTION -#endif - #include <stdint.h> -// Annotate a function indicating the caller must examine the return value. -// Use like: -// int foo() RTC_WARN_UNUSED_RESULT; -// To explicitly ignore a result, cast to void. -// TODO(kwiberg): Remove when we can use [[nodiscard]] from C++17. -#if defined(__clang__) -#define RTC_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) -#elif defined(__GNUC__) -// gcc has a __warn_unused_result__ attribute, but you can't quiet it by -// casting to void, so we don't use it. -#define RTC_WARN_UNUSED_RESULT -#else -#define RTC_WARN_UNUSED_RESULT -#endif - -// Put after a variable that might not be used, to prevent compiler warnings: -// int result ATTRIBUTE_UNUSED = DoSomething(); -// assert(result == 17); -// Deprecated since it only works with GCC & clang. See RTC_UNUSED below. -// TODO(terelius): Remove. -#ifndef ATTRIBUTE_UNUSED -#if defined(__GNUC__) || defined(__clang__) -#define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) -#else -#define ATTRIBUTE_UNUSED -#endif -#endif - -#ifndef NO_RETURN -// Annotate a function that will not return control flow to the caller. -#if defined(_MSC_VER) -#define NO_RETURN __declspec(noreturn) -#elif defined(__GNUC__) -#define NO_RETURN __attribute__ ((__noreturn__)) -#else -#define NO_RETURN -#endif -#endif - -// Prevent the compiler from warning about an unused variable. For example: -// int result = DoSomething(); -// assert(result == 17); -// RTC_UNUSED(result); -// Note: In most cases it is better to remove the unused variable rather than -// suppressing the compiler warning. -#ifndef RTC_UNUSED -#define RTC_UNUSED(x) static_cast<void>(x) -#endif // RTC_UNUSED +#include "rtc_base/system/arch.h" +#include "rtc_base/system/unused.h" #endif // TYPEDEFS_H_ |