From 098da17f35ade5e8ff1e7dbe7c812da0cece9daa Mon Sep 17 00:00:00 2001 From: Danil Chapovalov Date: Thu, 14 Jan 2021 16:15:31 +0100 Subject: [PATCH] Reland "Replace RTC_WARN_UNUSED_RESULT with ABSL_MUST_USE_RESULT in c++ code" This is a reland of 8c2250eddc7263036397179a0794b9b17d7afb38 Original change's description: > Replace RTC_WARN_UNUSED_RESULT with ABSL_MUST_USE_RESULT in c++ code > > Bug: webrtc:12336 > Change-Id: If76f00d0883b5c8a90d3ef5554f5e22384b3fb58 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/197620 > Reviewed-by: Mirko Bonadei > Reviewed-by: Christoffer Rodbro > Commit-Queue: Danil Chapovalov > Cr-Commit-Position: refs/heads/master@{#32978} Bug: webrtc:12336 Change-Id: I1cd017d45c1578528dec4532345950e9823f4a63 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/201732 Reviewed-by: Mirko Bonadei Reviewed-by: Christoffer Rodbro Commit-Queue: Danil Chapovalov Cr-Commit-Position: refs/heads/master@{#33003} --- api/voip/BUILD.gn | 5 ++++- api/voip/voip_base.h | 3 ++- modules/congestion_controller/goog_cc/BUILD.gn | 2 +- .../goog_cc/probe_controller.h | 18 +++++++++--------- modules/rtp_rtcp/BUILD.gn | 2 +- .../source/rtcp_packet/loss_notification.h | 12 +++++++----- rtc_base/BUILD.gn | 6 ++++-- rtc_base/swap_queue.h | 6 +++--- rtc_base/synchronization/BUILD.gn | 1 - rtc_base/synchronization/mutex.h | 4 ++-- rtc_base/synchronization/mutex_abseil.h | 3 ++- .../synchronization/mutex_critical_section.h | 3 ++- rtc_base/synchronization/mutex_pthread.h | 3 ++- 13 files changed, 39 insertions(+), 29 deletions(-) diff --git a/api/voip/BUILD.gn b/api/voip/BUILD.gn index 4db59fd98c..9e4f68d30e 100644 --- a/api/voip/BUILD.gn +++ b/api/voip/BUILD.gn @@ -25,7 +25,10 @@ rtc_source_set("voip_api") { "../audio_codecs:audio_codecs_api", "../neteq:neteq_api", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] + absl_deps = [ + "//third_party/abseil-cpp/absl/base:core_headers", + "//third_party/abseil-cpp/absl/types:optional", + ] } rtc_library("voip_engine_factory") { diff --git a/api/voip/voip_base.h b/api/voip/voip_base.h index 6a411f8d88..d421480881 100644 --- a/api/voip/voip_base.h +++ b/api/voip/voip_base.h @@ -11,6 +11,7 @@ #ifndef API_VOIP_VOIP_BASE_H_ #define API_VOIP_VOIP_BASE_H_ +#include "absl/base/attributes.h" #include "absl/types/optional.h" #include "rtc_base/system/unused.h" @@ -36,7 +37,7 @@ class Transport; enum class ChannelId : int {}; -enum class RTC_WARN_UNUSED_RESULT VoipResult { +enum class ABSL_MUST_USE_RESULT VoipResult { // kOk indicates the function was successfully invoked with no error. kOk, // kInvalidArgument indicates the caller specified an invalid argument, such diff --git a/modules/congestion_controller/goog_cc/BUILD.gn b/modules/congestion_controller/goog_cc/BUILD.gn index a5bcf57e34..654f083f92 100644 --- a/modules/congestion_controller/goog_cc/BUILD.gn +++ b/modules/congestion_controller/goog_cc/BUILD.gn @@ -226,10 +226,10 @@ rtc_library("probe_controller") { "../../../rtc_base:macromagic", "../../../rtc_base:safe_conversions", "../../../rtc_base/experiments:field_trial_parser", - "../../../rtc_base/system:unused", "../../../system_wrappers:metrics", ] absl_deps = [ + "//third_party/abseil-cpp/absl/base:core_headers", "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/types:optional", ] diff --git a/modules/congestion_controller/goog_cc/probe_controller.h b/modules/congestion_controller/goog_cc/probe_controller.h index 11e92b97ae..bcaa293209 100644 --- a/modules/congestion_controller/goog_cc/probe_controller.h +++ b/modules/congestion_controller/goog_cc/probe_controller.h @@ -16,6 +16,7 @@ #include #include +#include "absl/base/attributes.h" #include "absl/types/optional.h" #include "api/rtc_event_log/rtc_event_log.h" #include "api/transport/network_control.h" @@ -23,7 +24,6 @@ #include "api/units/data_rate.h" #include "rtc_base/constructor_magic.h" #include "rtc_base/experiments/field_trial_parser.h" -#include "rtc_base/system/unused.h" namespace webrtc { @@ -63,7 +63,7 @@ class ProbeController { RtcEventLog* event_log); ~ProbeController(); - RTC_WARN_UNUSED_RESULT std::vector SetBitrates( + ABSL_MUST_USE_RESULT std::vector SetBitrates( int64_t min_bitrate_bps, int64_t start_bitrate_bps, int64_t max_bitrate_bps, @@ -71,14 +71,14 @@ class ProbeController { // The total bitrate, as opposed to the max bitrate, is the sum of the // configured bitrates for all active streams. - RTC_WARN_UNUSED_RESULT std::vector + ABSL_MUST_USE_RESULT std::vector OnMaxTotalAllocatedBitrate(int64_t max_total_allocated_bitrate, int64_t at_time_ms); - RTC_WARN_UNUSED_RESULT std::vector OnNetworkAvailability( + ABSL_MUST_USE_RESULT std::vector OnNetworkAvailability( NetworkAvailability msg); - RTC_WARN_UNUSED_RESULT std::vector SetEstimatedBitrate( + ABSL_MUST_USE_RESULT std::vector SetEstimatedBitrate( int64_t bitrate_bps, int64_t at_time_ms); @@ -87,7 +87,7 @@ class ProbeController { void SetAlrStartTimeMs(absl::optional alr_start_time); void SetAlrEndedTimeMs(int64_t alr_end_time); - RTC_WARN_UNUSED_RESULT std::vector RequestProbe( + ABSL_MUST_USE_RESULT std::vector RequestProbe( int64_t at_time_ms); // Sets a new maximum probing bitrate, without generating a new probe cluster. @@ -97,7 +97,7 @@ class ProbeController { // created EXCEPT for |enable_periodic_alr_probing_|. void Reset(int64_t at_time_ms); - RTC_WARN_UNUSED_RESULT std::vector Process( + ABSL_MUST_USE_RESULT std::vector Process( int64_t at_time_ms); private: @@ -110,9 +110,9 @@ class ProbeController { kProbingComplete, }; - RTC_WARN_UNUSED_RESULT std::vector + ABSL_MUST_USE_RESULT std::vector InitiateExponentialProbing(int64_t at_time_ms); - RTC_WARN_UNUSED_RESULT std::vector InitiateProbing( + ABSL_MUST_USE_RESULT std::vector InitiateProbing( int64_t now_ms, std::vector bitrates_to_probe, bool probe_further); diff --git a/modules/rtp_rtcp/BUILD.gn b/modules/rtp_rtcp/BUILD.gn index e10d8463fd..ecac3e505f 100644 --- a/modules/rtp_rtcp/BUILD.gn +++ b/modules/rtp_rtcp/BUILD.gn @@ -117,7 +117,6 @@ rtc_library("rtp_rtcp_format") { "../../rtc_base:deprecation", "../../rtc_base:divide_round", "../../rtc_base:rtc_base_approved", - "../../rtc_base/system:unused", "../../system_wrappers", "../video_coding:codec_globals_headers", ] @@ -352,6 +351,7 @@ rtc_library("rtcp_transceiver") { ] absl_deps = [ "//third_party/abseil-cpp/absl/algorithm:container", + "//third_party/abseil-cpp/absl/base:core_headers", "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/types:optional", ] diff --git a/modules/rtp_rtcp/source/rtcp_packet/loss_notification.h b/modules/rtp_rtcp/source/rtcp_packet/loss_notification.h index 2603a6715e..99f6d12da4 100644 --- a/modules/rtp_rtcp/source/rtcp_packet/loss_notification.h +++ b/modules/rtp_rtcp/source/rtcp_packet/loss_notification.h @@ -11,9 +11,9 @@ #ifndef MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_LOSS_NOTIFICATION_H_ #define MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_LOSS_NOTIFICATION_H_ +#include "absl/base/attributes.h" #include "modules/rtp_rtcp/source/rtcp_packet/common_header.h" #include "modules/rtp_rtcp/source/rtcp_packet/psfb.h" -#include "rtc_base/system/unused.h" namespace webrtc { namespace rtcp { @@ -29,14 +29,15 @@ class LossNotification : public Psfb { size_t BlockLength() const override; + ABSL_MUST_USE_RESULT bool Create(uint8_t* packet, size_t* index, size_t max_length, - PacketReadyCallback callback) const override - RTC_WARN_UNUSED_RESULT; + PacketReadyCallback callback) const override; // Parse assumes header is already parsed and validated. - bool Parse(const CommonHeader& packet) RTC_WARN_UNUSED_RESULT; + ABSL_MUST_USE_RESULT + bool Parse(const CommonHeader& packet); // Set all of the values transmitted by the loss notification message. // If the values may not be represented by a loss notification message, @@ -44,9 +45,10 @@ class LossNotification : public Psfb { // when |last_recieved| is ahead of |last_decoded| by more than 0x7fff. // This is because |last_recieved| is represented on the wire as a delta, // and only 15 bits are available for that delta. + ABSL_MUST_USE_RESULT bool Set(uint16_t last_decoded, uint16_t last_received, - bool decodability_flag) RTC_WARN_UNUSED_RESULT; + bool decodability_flag); // RTP sequence number of the first packet belong to the last decoded // non-discardable frame. diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index 184c298999..f6efa8e217 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -78,10 +78,12 @@ rtc_library("rtc_base_approved") { "system:arch", "system:no_unique_address", "system:rtc_export", - "system:unused", "third_party/base64", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] + absl_deps = [ + "//third_party/abseil-cpp/absl/base:core_headers", + "//third_party/abseil-cpp/absl/types:optional", + ] public_deps = [] # no-presubmit-check TODO(webrtc:8603) sources = [ diff --git a/rtc_base/swap_queue.h b/rtc_base/swap_queue.h index 9eac49a933..3c8149c163 100644 --- a/rtc_base/swap_queue.h +++ b/rtc_base/swap_queue.h @@ -17,8 +17,8 @@ #include #include +#include "absl/base/attributes.h" #include "rtc_base/checks.h" -#include "rtc_base/system/unused.h" namespace webrtc { @@ -127,7 +127,7 @@ class SwapQueue { // When specified, the T given in *input must pass the ItemVerifier() test. // The contents of *input after the call are then also guaranteed to pass the // ItemVerifier() test. - bool Insert(T* input) RTC_WARN_UNUSED_RESULT { + ABSL_MUST_USE_RESULT bool Insert(T* input) { RTC_DCHECK(input); RTC_DCHECK(queue_item_verifier_(*input)); @@ -168,7 +168,7 @@ class SwapQueue { // empty). When specified, The T given in *output must pass the ItemVerifier() // test and the contents of *output after the call are then also guaranteed to // pass the ItemVerifier() test. - bool Remove(T* output) RTC_WARN_UNUSED_RESULT { + ABSL_MUST_USE_RESULT bool Remove(T* output) { RTC_DCHECK(output); RTC_DCHECK(queue_item_verifier_(*output)); diff --git a/rtc_base/synchronization/BUILD.gn b/rtc_base/synchronization/BUILD.gn index 16922af748..6b22b22605 100644 --- a/rtc_base/synchronization/BUILD.gn +++ b/rtc_base/synchronization/BUILD.gn @@ -36,7 +36,6 @@ rtc_library("mutex") { "..:checks", "..:macromagic", "..:platform_thread_types", - "../system:unused", ] absl_deps = [ "//third_party/abseil-cpp/absl/base:core_headers" ] if (rtc_use_absl_mutex) { diff --git a/rtc_base/synchronization/mutex.h b/rtc_base/synchronization/mutex.h index 620fe74e4a..0023d90ef5 100644 --- a/rtc_base/synchronization/mutex.h +++ b/rtc_base/synchronization/mutex.h @@ -13,9 +13,9 @@ #include +#include "absl/base/attributes.h" #include "absl/base/const_init.h" #include "rtc_base/checks.h" -#include "rtc_base/system/unused.h" #include "rtc_base/thread_annotations.h" #if defined(WEBRTC_ABSL_MUTEX) @@ -41,7 +41,7 @@ class RTC_LOCKABLE Mutex final { void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION() { impl_.Lock(); } - RTC_WARN_UNUSED_RESULT bool TryLock() RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true) { + ABSL_MUST_USE_RESULT bool TryLock() RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true) { return impl_.TryLock(); } void Unlock() RTC_UNLOCK_FUNCTION() { diff --git a/rtc_base/synchronization/mutex_abseil.h b/rtc_base/synchronization/mutex_abseil.h index 4ad1d07eef..9247065ae6 100644 --- a/rtc_base/synchronization/mutex_abseil.h +++ b/rtc_base/synchronization/mutex_abseil.h @@ -11,6 +11,7 @@ #ifndef RTC_BASE_SYNCHRONIZATION_MUTEX_ABSEIL_H_ #define RTC_BASE_SYNCHRONIZATION_MUTEX_ABSEIL_H_ +#include "absl/base/attributes.h" #include "absl/synchronization/mutex.h" #include "rtc_base/thread_annotations.h" @@ -23,7 +24,7 @@ class RTC_LOCKABLE MutexImpl final { MutexImpl& operator=(const MutexImpl&) = delete; void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION() { mutex_.Lock(); } - RTC_WARN_UNUSED_RESULT bool TryLock() RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true) { + ABSL_MUST_USE_RESULT bool TryLock() RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true) { return mutex_.TryLock(); } void Unlock() RTC_UNLOCK_FUNCTION() { mutex_.Unlock(); } diff --git a/rtc_base/synchronization/mutex_critical_section.h b/rtc_base/synchronization/mutex_critical_section.h index d206794988..cb3d6a095c 100644 --- a/rtc_base/synchronization/mutex_critical_section.h +++ b/rtc_base/synchronization/mutex_critical_section.h @@ -23,6 +23,7 @@ #include // must come after windows headers. // clang-format on +#include "absl/base/attributes.h" #include "rtc_base/thread_annotations.h" namespace webrtc { @@ -37,7 +38,7 @@ class RTC_LOCKABLE MutexImpl final { void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION() { EnterCriticalSection(&critical_section_); } - RTC_WARN_UNUSED_RESULT bool TryLock() RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true) { + ABSL_MUST_USE_RESULT bool TryLock() RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true) { return TryEnterCriticalSection(&critical_section_) != FALSE; } void Unlock() RTC_UNLOCK_FUNCTION() { diff --git a/rtc_base/synchronization/mutex_pthread.h b/rtc_base/synchronization/mutex_pthread.h index c9496e72c9..8898ca5348 100644 --- a/rtc_base/synchronization/mutex_pthread.h +++ b/rtc_base/synchronization/mutex_pthread.h @@ -18,6 +18,7 @@ #include #endif +#include "absl/base/attributes.h" #include "rtc_base/thread_annotations.h" namespace webrtc { @@ -39,7 +40,7 @@ class RTC_LOCKABLE MutexImpl final { ~MutexImpl() { pthread_mutex_destroy(&mutex_); } void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION() { pthread_mutex_lock(&mutex_); } - RTC_WARN_UNUSED_RESULT bool TryLock() RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true) { + ABSL_MUST_USE_RESULT bool TryLock() RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true) { return pthread_mutex_trylock(&mutex_) == 0; } void Unlock() RTC_UNLOCK_FUNCTION() { pthread_mutex_unlock(&mutex_); }