diff options
Diffstat (limited to 'webrtc/system_wrappers')
64 files changed, 578 insertions, 1089 deletions
diff --git a/webrtc/system_wrappers/BUILD.gn b/webrtc/system_wrappers/BUILD.gn index 2f68eae634..5e0e41e832 100644 --- a/webrtc/system_wrappers/BUILD.gn +++ b/webrtc/system_wrappers/BUILD.gn @@ -22,7 +22,6 @@ static_library("system_wrappers") { "include/data_log.h", "include/data_log_c.h", "include/data_log_impl.h", - "include/event_tracer.h", "include/event_wrapper.h", "include/field_trial.h", "include/file_wrapper.h", @@ -38,7 +37,6 @@ static_library("system_wrappers") { "include/static_instance.h", "include/stl_util.h", "include/stringize_macros.h", - "include/thread_wrapper.h", "include/tick_util.h", "include/timestamp_extrapolator.h", "include/trace.h", @@ -67,7 +65,6 @@ static_library("system_wrappers") { "source/event_timer_posix.h", "source/event_timer_win.cc", "source/event_timer_win.h", - "source/event_tracer.cc", "source/file_impl.cc", "source/file_impl.h", "source/logging.cc", @@ -81,11 +78,6 @@ static_library("system_wrappers") { "source/rw_lock_win.h", "source/sleep.cc", "source/sort.cc", - "source/thread.cc", - "source/thread_posix.cc", - "source/thread_posix.h", - "source/thread_win.cc", - "source/thread_win.h", "source/tick_util.cc", "source/timestamp_extrapolator.cc", "source/trace_impl.cc", @@ -179,10 +171,6 @@ source_set("field_trial_default") { configs += [ "..:common_config" ] public_configs = [ "..:common_inherited_config" ] - - deps = [ - ":system_wrappers", - ] } source_set("metrics_default") { @@ -192,10 +180,6 @@ source_set("metrics_default") { configs += [ "..:common_config" ] public_configs = [ "..:common_inherited_config" ] - - deps = [ - ":system_wrappers", - ] } source_set("system_wrappers_default") { @@ -205,6 +189,7 @@ source_set("system_wrappers_default") { deps = [ ":field_trial_default", ":metrics_default", + ":system_wrappers", ] } diff --git a/webrtc/system_wrappers/OWNERS b/webrtc/system_wrappers/OWNERS index 76fdda254e..f55277e8ea 100644 --- a/webrtc/system_wrappers/OWNERS +++ b/webrtc/system_wrappers/OWNERS @@ -4,4 +4,9 @@ henrikg@webrtc.org mflodman@webrtc.org niklas.enbom@webrtc.org +# These are for the common case of adding or renaming files. If you're doing +# structural changes, please get a review from a reviewer in this file. +per-file *.gyp=* +per-file *.gypi=* + per-file BUILD.gn=kjellander@webrtc.org diff --git a/webrtc/system_wrappers/include/aligned_array.h b/webrtc/system_wrappers/include/aligned_array.h index a3a5911e36..a2ffe99c14 100644 --- a/webrtc/system_wrappers/include/aligned_array.h +++ b/webrtc/system_wrappers/include/aligned_array.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ALIGNED_ARRAY_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ALIGNED_ARRAY_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_ALIGNED_ARRAY_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_ALIGNED_ARRAY_ #include "webrtc/base/checks.h" #include "webrtc/system_wrappers/include/aligned_malloc.h" @@ -20,21 +20,20 @@ namespace webrtc { // aligned to the given byte alignment. template<typename T> class AlignedArray { public: - AlignedArray(int rows, size_t cols, int alignment) + AlignedArray(size_t rows, size_t cols, size_t alignment) : rows_(rows), - cols_(cols), - alignment_(alignment) { - RTC_CHECK_GT(alignment_, 0); + cols_(cols) { + RTC_CHECK_GT(alignment, 0u); head_row_ = static_cast<T**>(AlignedMalloc(rows_ * sizeof(*head_row_), - alignment_)); - for (int i = 0; i < rows_; ++i) { + alignment)); + for (size_t i = 0; i < rows_; ++i) { head_row_[i] = static_cast<T*>(AlignedMalloc(cols_ * sizeof(**head_row_), - alignment_)); + alignment)); } } ~AlignedArray() { - for (int i = 0; i < rows_; ++i) { + for (size_t i = 0; i < rows_; ++i) { AlignedFree(head_row_[i]); } AlignedFree(head_row_); @@ -48,27 +47,27 @@ template<typename T> class AlignedArray { return head_row_; } - T* Row(int row) { + T* Row(size_t row) { RTC_CHECK_LE(row, rows_); return head_row_[row]; } - const T* Row(int row) const { + const T* Row(size_t row) const { RTC_CHECK_LE(row, rows_); return head_row_[row]; } - T& At(int row, size_t col) { + T& At(size_t row, size_t col) { RTC_CHECK_LE(col, cols_); return Row(row)[col]; } - const T& At(int row, size_t col) const { + const T& At(size_t row, size_t col) const { RTC_CHECK_LE(col, cols_); return Row(row)[col]; } - int rows() const { + size_t rows() const { return rows_; } @@ -77,12 +76,11 @@ template<typename T> class AlignedArray { } private: - int rows_; + size_t rows_; size_t cols_; - int alignment_; T** head_row_; }; } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ALIGNED_ARRAY_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_ALIGNED_ARRAY_ diff --git a/webrtc/system_wrappers/include/aligned_malloc.h b/webrtc/system_wrappers/include/aligned_malloc.h index 5d343cde7c..277abec020 100644 --- a/webrtc/system_wrappers/include/aligned_malloc.h +++ b/webrtc/system_wrappers/include/aligned_malloc.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ALIGNED_MALLOC_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ALIGNED_MALLOC_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_ALIGNED_MALLOC_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_ALIGNED_MALLOC_H_ // The functions declared here // 1) Allocates block of aligned memory. @@ -56,4 +56,4 @@ struct AlignedFreeDeleter { } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ALIGNED_MALLOC_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_ALIGNED_MALLOC_H_ diff --git a/webrtc/system_wrappers/include/asm_defines.h b/webrtc/system_wrappers/include/asm_defines.h index c2a688f00a..fe4c05effc 100644 --- a/webrtc/system_wrappers/include/asm_defines.h +++ b/webrtc/system_wrappers/include/asm_defines.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ASM_DEFINES_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ASM_DEFINES_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_ASM_DEFINES_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_ASM_DEFINES_H_ #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits @@ -63,4 +63,4 @@ strheq \reg1, \reg2, \num .text -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ASM_DEFINES_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_ASM_DEFINES_H_ diff --git a/webrtc/system_wrappers/include/atomic32.h b/webrtc/system_wrappers/include/atomic32.h index 36ca144bda..78e649d8b6 100644 --- a/webrtc/system_wrappers/include/atomic32.h +++ b/webrtc/system_wrappers/include/atomic32.h @@ -12,8 +12,8 @@ // doing, use locks instead! :-) // // Note: assumes 32-bit (or higher) system -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ATOMIC32_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ATOMIC32_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_ATOMIC32_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_ATOMIC32_H_ #include <stddef.h> @@ -63,4 +63,4 @@ class Atomic32 { } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ATOMIC32_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_ATOMIC32_H_ diff --git a/webrtc/system_wrappers/include/clock.h b/webrtc/system_wrappers/include/clock.h index 14253ba560..f443057bea 100644 --- a/webrtc/system_wrappers/include/clock.h +++ b/webrtc/system_wrappers/include/clock.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CLOCK_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CLOCK_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CLOCK_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CLOCK_H_ #include "webrtc/base/scoped_ptr.h" #include "webrtc/system_wrappers/include/rw_lock_wrapper.h" @@ -81,4 +81,4 @@ class SimulatedClock : public Clock { }; // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CLOCK_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CLOCK_H_ diff --git a/webrtc/system_wrappers/include/compile_assert_c.h b/webrtc/system_wrappers/include/compile_assert_c.h index dbb5292d97..b402d7192d 100644 --- a/webrtc/system_wrappers/include/compile_assert_c.h +++ b/webrtc/system_wrappers/include/compile_assert_c.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_COMPILE_ASSERT_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_COMPILE_ASSERT_H_ #ifdef __cplusplus #error "Only use this for C files. For C++, use static_assert." @@ -21,4 +21,4 @@ // COMPILE_ASSERT(sizeof(foo) < 128); #define COMPILE_ASSERT(expression) switch (0) {case 0: case expression:;} -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_COMPILE_ASSERT_H_ diff --git a/webrtc/system_wrappers/include/condition_variable_wrapper.h b/webrtc/system_wrappers/include/condition_variable_wrapper.h index 151f00ece1..37ca30f036 100644 --- a/webrtc/system_wrappers/include/condition_variable_wrapper.h +++ b/webrtc/system_wrappers/include/condition_variable_wrapper.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CONDITION_VARIABLE_WRAPPER_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CONDITION_VARIABLE_WRAPPER_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CONDITION_VARIABLE_WRAPPER_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CONDITION_VARIABLE_WRAPPER_H_ namespace webrtc { @@ -39,4 +39,4 @@ class ConditionVariableWrapper { } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CONDITION_VARIABLE_WRAPPER_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CONDITION_VARIABLE_WRAPPER_H_ diff --git a/webrtc/system_wrappers/include/cpu_features_wrapper.h b/webrtc/system_wrappers/include/cpu_features_wrapper.h index 5697c49164..9838d94e58 100644 --- a/webrtc/system_wrappers/include/cpu_features_wrapper.h +++ b/webrtc/system_wrappers/include/cpu_features_wrapper.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_FEATURES_WRAPPER_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_FEATURES_WRAPPER_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CPU_FEATURES_WRAPPER_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CPU_FEATURES_WRAPPER_H_ #if defined(__cplusplus) || defined(c_plusplus) extern "C" { @@ -48,4 +48,4 @@ extern uint64_t WebRtc_GetCPUFeaturesARM(void); } // extern "C" #endif -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_FEATURES_WRAPPER_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CPU_FEATURES_WRAPPER_H_ diff --git a/webrtc/system_wrappers/include/cpu_info.h b/webrtc/system_wrappers/include/cpu_info.h index 65888b8d32..3c00d33ed3 100644 --- a/webrtc/system_wrappers/include/cpu_info.h +++ b/webrtc/system_wrappers/include/cpu_info.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_INFO_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_INFO_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CPU_INFO_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CPU_INFO_H_ #include "webrtc/typedefs.h" @@ -25,4 +25,4 @@ class CpuInfo { } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_INFO_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CPU_INFO_H_ diff --git a/webrtc/system_wrappers/include/critical_section_wrapper.h b/webrtc/system_wrappers/include/critical_section_wrapper.h index e93a249e25..7dd217e40d 100644 --- a/webrtc/system_wrappers/include/critical_section_wrapper.h +++ b/webrtc/system_wrappers/include/critical_section_wrapper.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CRITICAL_SECTION_WRAPPER_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CRITICAL_SECTION_WRAPPER_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CRITICAL_SECTION_WRAPPER_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CRITICAL_SECTION_WRAPPER_H_ // If the critical section is heavily contended it may be beneficial to use // read/write locks instead. @@ -51,4 +51,4 @@ class SCOPED_LOCKABLE CriticalSectionScoped { } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CRITICAL_SECTION_WRAPPER_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CRITICAL_SECTION_WRAPPER_H_ diff --git a/webrtc/system_wrappers/include/data_log.h b/webrtc/system_wrappers/include/data_log.h index cf095674a3..f6cad88e96 100644 --- a/webrtc/system_wrappers/include/data_log.h +++ b/webrtc/system_wrappers/include/data_log.h @@ -28,8 +28,8 @@ // // Table names and column names are case sensitive. -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_DATA_LOG_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_DATA_LOG_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_H_ #include <string> @@ -116,4 +116,4 @@ class DataLog { } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_DATA_LOG_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_H_ diff --git a/webrtc/system_wrappers/include/data_log_c.h b/webrtc/system_wrappers/include/data_log_c.h index 4ff8329c85..d31e4d972e 100644 --- a/webrtc/system_wrappers/include/data_log_c.h +++ b/webrtc/system_wrappers/include/data_log_c.h @@ -12,8 +12,8 @@ // mapped here except for InsertCell as C does not support templates. // See data_log.h for a description of the functions. -#ifndef SRC_SYSTEM_WRAPPERS_INTERFACE_DATA_LOG_C_H_ -#define SRC_SYSTEM_WRAPPERS_INTERFACE_DATA_LOG_C_H_ +#ifndef SRC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_C_H_ +#define SRC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_C_H_ #include <stddef.h> // size_t @@ -82,4 +82,4 @@ int WebRtcDataLog_NextRow(const char* table_name); } // end of extern "C" #endif -#endif // SRC_SYSTEM_WRAPPERS_INTERFACE_DATA_LOG_C_H_ // NOLINT +#endif // SRC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_C_H_ // NOLINT diff --git a/webrtc/system_wrappers/include/data_log_impl.h b/webrtc/system_wrappers/include/data_log_impl.h index 56d98f891e..35519609b9 100644 --- a/webrtc/system_wrappers/include/data_log_impl.h +++ b/webrtc/system_wrappers/include/data_log_impl.h @@ -14,16 +14,16 @@ // These classes are helper classes used for logging data for offline // processing. Data logged with these classes can conveniently be parsed and // processed with e.g. Matlab. -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_DATA_LOG_IMPL_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_DATA_LOG_IMPL_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_IMPL_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_IMPL_H_ #include <map> #include <sstream> #include <string> #include <vector> +#include "webrtc/base/platform_thread.h" #include "webrtc/base/scoped_ptr.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/typedefs.h" namespace webrtc { @@ -146,10 +146,12 @@ class DataLogImpl { int counter_; TableMap tables_; EventWrapper* flush_event_; - rtc::scoped_ptr<ThreadWrapper> file_writer_thread_; + // This is a scoped_ptr so that we don't have to create threads in the no-op + // impl. + rtc::scoped_ptr<rtc::PlatformThread> file_writer_thread_; RWLockWrapper* tables_lock_; }; } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_DATA_LOG_IMPL_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_IMPL_H_ diff --git a/webrtc/system_wrappers/include/event_tracer.h b/webrtc/system_wrappers/include/event_tracer.h deleted file mode 100644 index 9b1eb1eb92..0000000000 --- a/webrtc/system_wrappers/include/event_tracer.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2012 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 defines the interface for event tracing in WebRTC. -// -// Event log handlers are set through SetupEventTracer(). User of this API will -// provide two function pointers to handle event tracing calls. -// -// * GetCategoryEnabledPtr -// Event tracing system calls this function to determine if a particular -// event category is enabled. -// -// * AddTraceEventPtr -// Adds a tracing event. It is the user's responsibility to log the data -// provided. -// -// Parameters for the above two functions are described in trace_event.h. - -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_EVENT_TRACER_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_EVENT_TRACER_H_ - -// This file has moved. -// TODO(tommi): Delete after removing dependencies and updating Chromium. -#include "webrtc/base/event_tracer.h" - -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_EVENT_TRACER_H_ diff --git a/webrtc/system_wrappers/include/event_wrapper.h b/webrtc/system_wrappers/include/event_wrapper.h index bd12eef908..cc3722bd6b 100644 --- a/webrtc/system_wrappers/include/event_wrapper.h +++ b/webrtc/system_wrappers/include/event_wrapper.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_EVENT_WRAPPER_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_EVENT_WRAPPER_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_EVENT_WRAPPER_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_EVENT_WRAPPER_H_ namespace webrtc { enum EventTypeWrapper { @@ -67,4 +67,4 @@ class EventTimerWrapper : public EventWrapper { } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_EVENT_WRAPPER_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_EVENT_WRAPPER_H_ diff --git a/webrtc/system_wrappers/include/field_trial.h b/webrtc/system_wrappers/include/field_trial.h index 2af083cdac..62fbfd1a50 100644 --- a/webrtc/system_wrappers/include/field_trial.h +++ b/webrtc/system_wrappers/include/field_trial.h @@ -8,8 +8,8 @@ // be found in the AUTHORS file in the root of the source tree. // -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_FIELD_TRIAL_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_FIELD_TRIAL_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_FIELD_TRIAL_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_FIELD_TRIAL_H_ #include <string> @@ -65,4 +65,4 @@ std::string FindFullName(const std::string& name); } // namespace field_trial } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_FIELD_TRIAL_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_FIELD_TRIAL_H_ diff --git a/webrtc/system_wrappers/include/field_trial_default.h b/webrtc/system_wrappers/include/field_trial_default.h index fafe550dcc..7417ced39d 100644 --- a/webrtc/system_wrappers/include/field_trial_default.h +++ b/webrtc/system_wrappers/include/field_trial_default.h @@ -8,8 +8,8 @@ // be found in the AUTHORS file in the root of the source tree. // -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_FIELD_TRIAL_DEFAULT_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_FIELD_TRIAL_DEFAULT_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_FIELD_TRIAL_DEFAULT_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_FIELD_TRIAL_DEFAULT_H_ namespace webrtc { namespace field_trial { @@ -20,7 +20,9 @@ namespace field_trial { // Note: trials_string must never be destroyed. void InitFieldTrialsFromString(const char* trials_string); +const char* GetFieldTrialString(); + } // namespace field_trial } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_FIELD_TRIAL_DEFAULT_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_FIELD_TRIAL_DEFAULT_H_ diff --git a/webrtc/system_wrappers/include/file_wrapper.h b/webrtc/system_wrappers/include/file_wrapper.h index 8f4e09f9c9..b32a62f2f9 100644 --- a/webrtc/system_wrappers/include/file_wrapper.h +++ b/webrtc/system_wrappers/include/file_wrapper.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_FILE_WRAPPER_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_FILE_WRAPPER_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_FILE_WRAPPER_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_FILE_WRAPPER_H_ #include <stddef.h> #include <stdio.h> @@ -75,4 +75,4 @@ class FileWrapper : public InStream, public OutStream { } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_FILE_WRAPPER_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_FILE_WRAPPER_H_ diff --git a/webrtc/system_wrappers/include/logcat_trace_context.h b/webrtc/system_wrappers/include/logcat_trace_context.h index 0b74734043..8bb01d8102 100644 --- a/webrtc/system_wrappers/include/logcat_trace_context.h +++ b/webrtc/system_wrappers/include/logcat_trace_context.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_LOGCAT_TRACE_CONTEXT_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_LOGCAT_TRACE_CONTEXT_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_LOGCAT_TRACE_CONTEXT_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_LOGCAT_TRACE_CONTEXT_H_ #include "webrtc/system_wrappers/include/trace.h" @@ -32,4 +32,4 @@ class LogcatTraceContext : public webrtc::TraceCallback { } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_LOGCAT_TRACE_CONTEXT_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_LOGCAT_TRACE_CONTEXT_H_ diff --git a/webrtc/system_wrappers/include/logging.h b/webrtc/system_wrappers/include/logging.h index 41c436b1f3..0089841d4e 100644 --- a/webrtc/system_wrappers/include/logging.h +++ b/webrtc/system_wrappers/include/logging.h @@ -36,20 +36,8 @@ // type (basically, it just doesn't prepend the namespace). // LOG_F(sev) Like LOG(), but includes the name of the current function. -// Additional helper macros added by WebRTC: -// LOG_API is a shortcut for API call logging. Pass in the input parameters of -// the method. For example: -// Foo(int bar, int baz) { -// LOG_API2(bar, baz); -// } -// -// LOG_FERR is a shortcut for logging a failed function call. For example: -// if (!Foo(bar)) { -// LOG_FERR1(LS_WARNING, Foo, bar); -// } - -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_LOGGING_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_LOGGING_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_LOGGING_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_LOGGING_H_ #include <sstream> @@ -131,31 +119,14 @@ class LogMessageVoidify { webrtc::LogMessage(__FILE__, __LINE__, sev).stream() // The _F version prefixes the message with the current function name. -#if (defined(__GNUC__) && defined(_DEBUG)) || defined(WANT_PRETTY_LOG_F) +#if (defined(__GNUC__) && !defined(NDEBUG)) || defined(WANT_PRETTY_LOG_F) #define LOG_F(sev) LOG(sev) << __PRETTY_FUNCTION__ << ": " #else #define LOG_F(sev) LOG(sev) << __FUNCTION__ << ": " #endif -#define LOG_API0() LOG_F(LS_VERBOSE) -#define LOG_API1(v1) LOG_API0() << #v1 << "=" << v1 -#define LOG_API2(v1, v2) LOG_API1(v1) \ - << ", " << #v2 << "=" << v2 -#define LOG_API3(v1, v2, v3) LOG_API2(v1, v2) \ - << ", " << #v3 << "=" << v3 - -#define LOG_FERR0(sev, func) LOG(sev) << #func << " failed" -#define LOG_FERR1(sev, func, v1) LOG_FERR0(sev, func) \ - << ": " << #v1 << "=" << v1 -#define LOG_FERR2(sev, func, v1, v2) LOG_FERR1(sev, func, v1) \ - << ", " << #v2 << "=" << v2 -#define LOG_FERR3(sev, func, v1, v2, v3) LOG_FERR2(sev, func, v1, v2) \ - << ", " << #v3 << "=" << v3 -#define LOG_FERR4(sev, func, v1, v2, v3, v4) LOG_FERR3(sev, func, v1, v2, v3) \ - << ", " << #v4 << "=" << v4 - #endif // LOG } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_LOGGING_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_LOGGING_H_ diff --git a/webrtc/system_wrappers/include/metrics.h b/webrtc/system_wrappers/include/metrics.h index 7ebe3bde3d..4cd74c5e84 100644 --- a/webrtc/system_wrappers/include/metrics.h +++ b/webrtc/system_wrappers/include/metrics.h @@ -8,11 +8,13 @@ // be found in the AUTHORS file in the root of the source tree. // -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_METRICS_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_METRICS_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ #include <string> +#include "webrtc/base/atomicops.h" +#include "webrtc/base/checks.h" #include "webrtc/common_types.h" // Macros for allowing WebRTC clients (e.g. Chrome) to gather and aggregate @@ -58,54 +60,98 @@ // Macros for adding samples to a named histogram. -// -// NOTE: this is a temporary solution. -// The aim is to mimic the behaviour in Chromium's src/base/metrics/histograms.h -// However as atomics are not supported in webrtc, this is for now a modified -// and temporary solution. Note that the histogram is constructed/found for -// each call. Therefore, for now only use this implementation for metrics -// that do not need to be updated frequently. -// TODO(asapersson): Change implementation when atomics are supported. -// Also consider changing string to const char* when switching to atomics. -// Histogram for counters. -#define RTC_HISTOGRAM_COUNTS_100(name, sample) RTC_HISTOGRAM_COUNTS( \ - name, sample, 1, 100, 50) +// Histogram for counters (exponentially spaced buckets). +#define RTC_HISTOGRAM_COUNTS_100(name, sample) \ + RTC_HISTOGRAM_COUNTS(name, sample, 1, 100, 50) -#define RTC_HISTOGRAM_COUNTS_200(name, sample) RTC_HISTOGRAM_COUNTS( \ - name, sample, 1, 200, 50) +#define RTC_HISTOGRAM_COUNTS_200(name, sample) \ + RTC_HISTOGRAM_COUNTS(name, sample, 1, 200, 50) -#define RTC_HISTOGRAM_COUNTS_1000(name, sample) RTC_HISTOGRAM_COUNTS( \ - name, sample, 1, 1000, 50) +#define RTC_HISTOGRAM_COUNTS_1000(name, sample) \ + RTC_HISTOGRAM_COUNTS(name, sample, 1, 1000, 50) -#define RTC_HISTOGRAM_COUNTS_10000(name, sample) RTC_HISTOGRAM_COUNTS( \ - name, sample, 1, 10000, 50) +#define RTC_HISTOGRAM_COUNTS_10000(name, sample) \ + RTC_HISTOGRAM_COUNTS(name, sample, 1, 10000, 50) -#define RTC_HISTOGRAM_COUNTS_100000(name, sample) RTC_HISTOGRAM_COUNTS( \ - name, sample, 1, 100000, 50) +#define RTC_HISTOGRAM_COUNTS_100000(name, sample) \ + RTC_HISTOGRAM_COUNTS(name, sample, 1, 100000, 50) #define RTC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count) \ - RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ - webrtc::metrics::HistogramFactoryGetCounts( \ - name, min, max, bucket_count)) + RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ + webrtc::metrics::HistogramFactoryGetCounts(name, min, max, bucket_count)) + +// Deprecated. +// TODO(asapersson): Remove. +#define RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample) \ + RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100, 50) + +#define RTC_HISTOGRAM_COUNTS_SPARSE_200(name, sample) \ + RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 200, 50) + +#define RTC_HISTOGRAM_COUNTS_SPARSE_1000(name, sample) \ + RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 1000, 50) + +#define RTC_HISTOGRAM_COUNTS_SPARSE_10000(name, sample) \ + RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 10000, 50) + +#define RTC_HISTOGRAM_COUNTS_SPARSE_100000(name, sample) \ + RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, 1, 100000, 50) + +#define RTC_HISTOGRAM_COUNTS_SPARSE(name, sample, min, max, bucket_count) \ + RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \ + webrtc::metrics::HistogramFactoryGetCounts(name, min, max, bucket_count)) -// Histogram for percentage. +// Histogram for percentage (evenly spaced buckets). #define RTC_HISTOGRAM_PERCENTAGE(name, sample) \ - RTC_HISTOGRAM_ENUMERATION(name, sample, 101) + RTC_HISTOGRAM_ENUMERATION(name, sample, 101) -// Histogram for enumerators. +// Deprecated. +// TODO(asapersson): Remove. +#define RTC_HISTOGRAM_PERCENTAGE_SPARSE(name, sample) \ + RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, 101) + +// Histogram for enumerators (evenly spaced buckets). // |boundary| should be above the max enumerator sample. #define RTC_HISTOGRAM_ENUMERATION(name, sample, boundary) \ - RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ - webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) + RTC_HISTOGRAM_COMMON_BLOCK(name, sample, \ + webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) +// Deprecated. +// TODO(asapersson): Remove. +#define RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, boundary) \ + RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, \ + webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary)) + +// The name of the histogram should not vary. +// TODO(asapersson): Consider changing string to const char*. #define RTC_HISTOGRAM_COMMON_BLOCK(constant_name, sample, \ factory_get_invocation) \ do { \ - webrtc::metrics::Histogram* histogram_pointer = factory_get_invocation; \ + static webrtc::metrics::Histogram* atomic_histogram_pointer = nullptr; \ + webrtc::metrics::Histogram* histogram_pointer = \ + rtc::AtomicOps::AcquireLoadPtr(&atomic_histogram_pointer); \ + if (!histogram_pointer) { \ + histogram_pointer = factory_get_invocation; \ + webrtc::metrics::Histogram* prev_pointer = \ + rtc::AtomicOps::CompareAndSwapPtr( \ + &atomic_histogram_pointer, \ + static_cast<webrtc::metrics::Histogram*>(nullptr), \ + histogram_pointer); \ + RTC_DCHECK(prev_pointer == nullptr || \ + prev_pointer == histogram_pointer); \ + } \ webrtc::metrics::HistogramAdd(histogram_pointer, constant_name, sample); \ } while (0) +// Deprecated. +// The histogram is constructed/found for each call. +// May be used for histograms with infrequent updates. +#define RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, factory_get_invocation) \ + do { \ + webrtc::metrics::Histogram* histogram_pointer = factory_get_invocation; \ + webrtc::metrics::HistogramAdd(histogram_pointer, name, sample); \ + } while (0) namespace webrtc { namespace metrics { @@ -135,5 +181,5 @@ void HistogramAdd( } // namespace metrics } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_METRICS_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ diff --git a/webrtc/system_wrappers/include/ntp_time.h b/webrtc/system_wrappers/include/ntp_time.h new file mode 100644 index 0000000000..229666e8dd --- /dev/null +++ b/webrtc/system_wrappers/include/ntp_time.h @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2015 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 WEBRTC_SYSTEM_WRAPPERS_INCLUDE_NTP_TIME_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_NTP_TIME_H_ + +#include "webrtc/base/basictypes.h" +#include "webrtc/system_wrappers/include/clock.h" + +namespace webrtc { + +class NtpTime { + public: + NtpTime() : seconds_(0), fractions_(0) {} + explicit NtpTime(const Clock& clock) { + clock.CurrentNtp(seconds_, fractions_); + } + NtpTime(uint32_t seconds, uint32_t fractions) + : seconds_(seconds), fractions_(fractions) {} + + NtpTime(const NtpTime&) = default; + NtpTime& operator=(const NtpTime&) = default; + + void SetCurrent(const Clock& clock) { + clock.CurrentNtp(seconds_, fractions_); + } + void Set(uint32_t seconds, uint32_t fractions) { + seconds_ = seconds; + fractions_ = fractions; + } + void Reset() { + seconds_ = 0; + fractions_ = 0; + } + + int64_t ToMs() const { return Clock::NtpToMs(seconds_, fractions_); } + + // NTP standard (RFC1305, section 3.1) explicitly state value 0/0 is invalid. + bool Valid() const { return !(seconds_ == 0 && fractions_ == 0); } + + uint32_t seconds() const { return seconds_; } + uint32_t fractions() const { return fractions_; } + + private: + uint32_t seconds_; + uint32_t fractions_; +}; + +inline bool operator==(const NtpTime& n1, const NtpTime& n2) { + return n1.seconds() == n2.seconds() && n1.fractions() == n2.fractions(); +} +inline bool operator!=(const NtpTime& n1, const NtpTime& n2) { + return !(n1 == n2); +} + +} // namespace webrtc +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_NTP_TIME_H_ diff --git a/webrtc/system_wrappers/include/ref_count.h b/webrtc/system_wrappers/include/ref_count.h index 8ca06cdf6c..3dd335a8da 100644 --- a/webrtc/system_wrappers/include/ref_count.h +++ b/webrtc/system_wrappers/include/ref_count.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef SYSTEM_WRAPPERS_INTERFACE_REF_COUNT_H_ -#define SYSTEM_WRAPPERS_INTERFACE_REF_COUNT_H_ +#ifndef SYSTEM_WRAPPERS_INCLUDE_REF_COUNT_H_ +#define SYSTEM_WRAPPERS_INCLUDE_REF_COUNT_H_ #include "webrtc/system_wrappers/include/atomic32.h" @@ -79,4 +79,4 @@ class RefCountImpl : public T { } // namespace webrtc -#endif // SYSTEM_WRAPPERS_INTERFACE_REF_COUNT_H_ +#endif // SYSTEM_WRAPPERS_INCLUDE_REF_COUNT_H_ diff --git a/webrtc/system_wrappers/include/rtp_to_ntp.h b/webrtc/system_wrappers/include/rtp_to_ntp.h index dfc25cd9e9..0c91928626 100644 --- a/webrtc/system_wrappers/include/rtp_to_ntp.h +++ b/webrtc/system_wrappers/include/rtp_to_ntp.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef SYSTEM_WRAPPERS_INTERFACE_RTP_TO_NTP_H_ -#define SYSTEM_WRAPPERS_INTERFACE_RTP_TO_NTP_H_ +#ifndef SYSTEM_WRAPPERS_INCLUDE_RTP_TO_NTP_H_ +#define SYSTEM_WRAPPERS_INCLUDE_RTP_TO_NTP_H_ #include <list> @@ -47,4 +47,4 @@ int CheckForWrapArounds(uint32_t rtp_timestamp, uint32_t rtcp_rtp_timestamp); } // namespace webrtc -#endif // SYSTEM_WRAPPERS_INTERFACE_RTP_TO_NTP_H_ +#endif // SYSTEM_WRAPPERS_INCLUDE_RTP_TO_NTP_H_ diff --git a/webrtc/system_wrappers/include/rw_lock_wrapper.h b/webrtc/system_wrappers/include/rw_lock_wrapper.h index dbe6d6c7c0..751b6a1df5 100644 --- a/webrtc/system_wrappers/include/rw_lock_wrapper.h +++ b/webrtc/system_wrappers/include/rw_lock_wrapper.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_RW_LOCK_WRAPPER_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_RW_LOCK_WRAPPER_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_RW_LOCK_WRAPPER_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_RW_LOCK_WRAPPER_H_ #include "webrtc/base/thread_annotations.h" @@ -65,4 +65,4 @@ class SCOPED_LOCKABLE WriteLockScoped { } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_RW_LOCK_WRAPPER_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_RW_LOCK_WRAPPER_H_ diff --git a/webrtc/system_wrappers/include/scoped_vector.h b/webrtc/system_wrappers/include/scoped_vector.h index 1e89a9d245..15c3380c8c 100644 --- a/webrtc/system_wrappers/include/scoped_vector.h +++ b/webrtc/system_wrappers/include/scoped_vector.h @@ -10,12 +10,13 @@ // Borrowed from Chromium's src/base/memory/scoped_vector.h. -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_SCOPED_VECTOR_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_SCOPED_VECTOR_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_SCOPED_VECTOR_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_SCOPED_VECTOR_H_ #include <vector> #include "webrtc/base/checks.h" +#include "webrtc/base/deprecation.h" #include "webrtc/system_wrappers/include/stl_util.h" namespace webrtc { @@ -43,9 +44,7 @@ class ScopedVector { ~ScopedVector() { clear(); } // Move construction and assignment. - ScopedVector(ScopedVector&& other) { - *this = static_cast<ScopedVector&&>(other); - } + ScopedVector(ScopedVector&& other) { *this = std::move(other); } ScopedVector& operator=(ScopedVector&& other) { std::swap(v_, other.v_); // The arguments are std::vectors, so std::swap // is the one that we want. @@ -58,7 +57,11 @@ class ScopedVector { ScopedVector& operator=(const ScopedVector& other) = delete; // Get an rvalue reference. (sv.Pass() does the same thing as std::move(sv).) - ScopedVector&& Pass() { return static_cast<ScopedVector&&>(*this); } + // Deprecated; remove in March 2016 (bug 5373). + RTC_DEPRECATED ScopedVector&& Pass() { return DEPRECATED_Pass(); } + ScopedVector&& DEPRECATED_Pass() { + return std::move(*this); + } reference operator[](size_t index) { return v_[index]; } const_reference operator[](size_t index) const { return v_[index]; } @@ -154,4 +157,4 @@ class ScopedVector { } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_SCOPED_VECTOR_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_SCOPED_VECTOR_H_ diff --git a/webrtc/system_wrappers/include/sleep.h b/webrtc/system_wrappers/include/sleep.h index c0205bf085..e7ed8b32b8 100644 --- a/webrtc/system_wrappers/include/sleep.h +++ b/webrtc/system_wrappers/include/sleep.h @@ -9,8 +9,8 @@ */ // An OS-independent sleep function. -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_SLEEP_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_SLEEP_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_SLEEP_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_SLEEP_H_ namespace webrtc { @@ -21,4 +21,4 @@ void SleepMs(int msecs); } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_SLEEP_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_SLEEP_H_ diff --git a/webrtc/system_wrappers/include/sort.h b/webrtc/system_wrappers/include/sort.h index da6ff8d52e..5bf2afa8a5 100644 --- a/webrtc/system_wrappers/include/sort.h +++ b/webrtc/system_wrappers/include/sort.h @@ -10,8 +10,8 @@ // Generic unstable sorting routines. -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_SORT_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_SORT_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_SORT_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_SORT_H_ #include "webrtc/common_types.h" #include "webrtc/typedefs.h" @@ -62,4 +62,4 @@ int32_t KeySort(void* data, void* key, uint32_t num_of_elements, } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_SORT_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_SORT_H_ diff --git a/webrtc/system_wrappers/include/static_instance.h b/webrtc/system_wrappers/include/static_instance.h index fd986b821d..41946d9230 100644 --- a/webrtc/system_wrappers/include/static_instance.h +++ b/webrtc/system_wrappers/include/static_instance.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_STATIC_INSTANCE_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_STATIC_INSTANCE_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_STATIC_INSTANCE_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_STATIC_INSTANCE_H_ #include <assert.h> @@ -150,4 +150,4 @@ static T* GetStaticInstance(CountOperation count_operation) { } // namspace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_STATIC_INSTANCE_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_STATIC_INSTANCE_H_ diff --git a/webrtc/system_wrappers/include/stl_util.h b/webrtc/system_wrappers/include/stl_util.h index ebe855fb10..b7a702113f 100644 --- a/webrtc/system_wrappers/include/stl_util.h +++ b/webrtc/system_wrappers/include/stl_util.h @@ -10,8 +10,8 @@ // Borrowed from Chromium's src/base/stl_util.h. -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_STL_UTIL_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_STL_UTIL_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_STL_UTIL_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_STL_UTIL_H_ #include <assert.h> #include <algorithm> @@ -262,4 +262,4 @@ bool STLIncludes(const Arg1& a1, const Arg2& a2) { } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_STL_UTIL_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_STL_UTIL_H_ diff --git a/webrtc/system_wrappers/include/stringize_macros.h b/webrtc/system_wrappers/include/stringize_macros.h index ab8c43d4e2..9c8e7e9120 100644 --- a/webrtc/system_wrappers/include/stringize_macros.h +++ b/webrtc/system_wrappers/include/stringize_macros.h @@ -15,8 +15,8 @@ // symbols (or their output) and manipulating preprocessor symbols // that define strings. -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_STRINGIZE_MACROS_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_STRINGIZE_MACROS_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_STRINGIZE_MACROS_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_STRINGIZE_MACROS_H_ // This is not very useful as it does not expand defined symbols if // called directly. Use its counterpart without the _NO_EXPANSION @@ -35,4 +35,4 @@ // STRINGIZE(B(y)) produces "myobj->FunctionCall(y)" #define STRINGIZE(x) STRINGIZE_NO_EXPANSION(x) -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_STRINGIZE_MACROS_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_STRINGIZE_MACROS_H_ diff --git a/webrtc/system_wrappers/include/thread_wrapper.h b/webrtc/system_wrappers/include/thread_wrapper.h deleted file mode 100644 index 742056198a..0000000000 --- a/webrtc/system_wrappers/include/thread_wrapper.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2011 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. - */ - -// System independant wrapper for spawning threads -// Note: the spawned thread will loop over the callback function until stopped. -// Note: The callback function is expected to return every 2 seconds or more -// often. - -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_THREAD_WRAPPER_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_THREAD_WRAPPER_H_ - -#if defined(WEBRTC_WIN) -#include <windows.h> -#endif - -#include "webrtc/base/scoped_ptr.h" -#include "webrtc/common_types.h" -#include "webrtc/typedefs.h" - -namespace webrtc { - -// Callback function that the spawned thread will enter once spawned. -// A return value of false is interpreted as that the function has no -// more work to do and that the thread can be released. -typedef bool(*ThreadRunFunction)(void*); - -enum ThreadPriority { -#ifdef WEBRTC_WIN - kLowPriority = THREAD_PRIORITY_BELOW_NORMAL, - kNormalPriority = THREAD_PRIORITY_NORMAL, - kHighPriority = THREAD_PRIORITY_ABOVE_NORMAL, - kHighestPriority = THREAD_PRIORITY_HIGHEST, - kRealtimePriority = THREAD_PRIORITY_TIME_CRITICAL -#else - kLowPriority = 1, - kNormalPriority = 2, - kHighPriority = 3, - kHighestPriority = 4, - kRealtimePriority = 5 -#endif -}; - -// Represents a simple worker thread. The implementation must be assumed -// to be single threaded, meaning that all methods of the class, must be -// called from the same thread, including instantiation. -// TODO(tommi): There's no need for this to be a virtual interface since there's -// only ever a single implementation of it. -class ThreadWrapper { - public: - virtual ~ThreadWrapper() {} - - // Factory method. Constructor disabled. - // - // func Pointer to a, by user, specified callback function. - // obj Object associated with the thread. Passed in the callback - // function. - // prio Thread priority. May require root/admin rights. - // thread_name NULL terminated thread name, will be visable in the Windows - // debugger. - static rtc::scoped_ptr<ThreadWrapper> CreateThread(ThreadRunFunction func, - void* obj, const char* thread_name); - - // Get the current thread's thread ID. - // NOTE: This is a static method. It returns the id of the calling thread, - // *not* the id of the worker thread that a ThreadWrapper instance represents. - // TODO(tommi): Move outside of the ThreadWrapper class to avoid confusion. - static uint32_t GetThreadId(); - - // Tries to spawns a thread and returns true if that was successful. - // Additionally, it tries to set thread priority according to the priority - // from when CreateThread was called. However, failure to set priority will - // not result in a false return value. - virtual bool Start() = 0; - - // Stops the spawned thread and waits for it to be reclaimed with a timeout - // of two seconds. Will return false if the thread was not reclaimed. - // Multiple tries to Stop are allowed (e.g. to wait longer than 2 seconds). - // It's ok to call Stop() even if the spawned thread has been reclaimed. - virtual bool Stop() = 0; - - // Set the priority of the worker thread. Must be called when thread - // is running. - virtual bool SetPriority(ThreadPriority priority) = 0; -}; - -} // namespace webrtc - -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_THREAD_WRAPPER_H_ diff --git a/webrtc/system_wrappers/include/tick_util.h b/webrtc/system_wrappers/include/tick_util.h index 0b7890e7c8..52f9b4ae4d 100644 --- a/webrtc/system_wrappers/include/tick_util.h +++ b/webrtc/system_wrappers/include/tick_util.h @@ -11,8 +11,8 @@ // System independant wrapper for polling elapsed time in ms and us. // The implementation works in the tick domain which can be mapped over to the // time domain. -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TICK_UTIL_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TICK_UTIL_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_TICK_UTIL_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_TICK_UTIL_H_ #if _WIN32 // Note: The Windows header must always be included before mmsystem.h @@ -56,6 +56,8 @@ class TickTime { static int64_t TicksToMilliseconds(const int64_t ticks); + static int64_t TicksToMicroseconds(const int64_t ticks); + // Returns a TickTime that is ticks later than the passed TickTime. friend TickTime operator+(const TickTime lhs, const int64_t ticks); TickTime& operator+=(const int64_t& ticks); @@ -63,19 +65,9 @@ class TickTime { // Returns a TickInterval that is the difference in ticks beween rhs and lhs. friend TickInterval operator-(const TickTime& lhs, const TickTime& rhs); - // Call to engage the fake clock. This is useful for tests since relying on - // a real clock often makes the test flaky. - static void UseFakeClock(int64_t start_millisecond); - - // Advance the fake clock. Must be called after UseFakeClock. - static void AdvanceFakeClock(int64_t milliseconds); - private: static int64_t QueryOsForTicks(); - static bool use_fake_clock_; - static int64_t fake_ticks_; - int64_t ticks_; }; @@ -83,6 +75,7 @@ class TickTime { class TickInterval { public: TickInterval(); + explicit TickInterval(int64_t interval); int64_t Milliseconds() const; int64_t Microseconds() const; @@ -103,8 +96,6 @@ class TickInterval { friend bool operator>=(const TickInterval& lhs, const TickInterval& rhs); private: - explicit TickInterval(int64_t interval); - friend class TickTime; friend TickInterval operator-(const TickTime& lhs, const TickTime& rhs); @@ -112,6 +103,14 @@ class TickInterval { int64_t interval_; }; +inline int64_t TickInterval::Milliseconds() const { + return TickTime::TicksToMilliseconds(interval_); +} + +inline int64_t TickInterval::Microseconds() const { + return TickTime::TicksToMicroseconds(interval_); +} + inline TickInterval operator+(const TickInterval& lhs, const TickInterval& rhs) { return TickInterval(lhs.interval_ + rhs.interval_); @@ -157,82 +156,13 @@ inline TickTime::TickTime(int64_t ticks) } inline TickTime TickTime::Now() { - if (use_fake_clock_) - return TickTime(fake_ticks_); - else - return TickTime(QueryOsForTicks()); -} - -inline int64_t TickTime::MillisecondTimestamp() { - int64_t ticks = TickTime::Now().Ticks(); -#if _WIN32 -#ifdef USE_QUERY_PERFORMANCE_COUNTER - LARGE_INTEGER qpfreq; - QueryPerformanceFrequency(&qpfreq); - return (ticks * 1000) / qpfreq.QuadPart; -#else - return ticks; -#endif -#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) - return ticks / 1000000LL; -#else - return ticks / 1000LL; -#endif -} - -inline int64_t TickTime::MicrosecondTimestamp() { - int64_t ticks = TickTime::Now().Ticks(); -#if _WIN32 -#ifdef USE_QUERY_PERFORMANCE_COUNTER - LARGE_INTEGER qpfreq; - QueryPerformanceFrequency(&qpfreq); - return (ticks * 1000) / (qpfreq.QuadPart / 1000); -#else - return ticks * 1000LL; -#endif -#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) - return ticks / 1000LL; -#else - return ticks; -#endif + return TickTime(QueryOsForTicks()); } inline int64_t TickTime::Ticks() const { return ticks_; } -inline int64_t TickTime::MillisecondsToTicks(const int64_t ms) { -#if _WIN32 -#ifdef USE_QUERY_PERFORMANCE_COUNTER - LARGE_INTEGER qpfreq; - QueryPerformanceFrequency(&qpfreq); - return (qpfreq.QuadPart * ms) / 1000; -#else - return ms; -#endif -#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) - return ms * 1000000LL; -#else - return ms * 1000LL; -#endif -} - -inline int64_t TickTime::TicksToMilliseconds(const int64_t ticks) { -#if _WIN32 -#ifdef USE_QUERY_PERFORMANCE_COUNTER - LARGE_INTEGER qpfreq; - QueryPerformanceFrequency(&qpfreq); - return (ticks * 1000) / qpfreq.QuadPart; -#else - return ticks; -#endif -#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) - return ticks / 1000000LL; -#else - return ticks / 1000LL; -#endif -} - inline TickTime& TickTime::operator+=(const int64_t& ticks) { ticks_ += ticks; return *this; @@ -245,44 +175,6 @@ inline TickInterval::TickInterval(const int64_t interval) : interval_(interval) { } -inline int64_t TickInterval::Milliseconds() const { -#if _WIN32 -#ifdef USE_QUERY_PERFORMANCE_COUNTER - LARGE_INTEGER qpfreq; - QueryPerformanceFrequency(&qpfreq); - return (interval_ * 1000) / qpfreq.QuadPart; -#else - // interval_ is in ms - return interval_; -#endif -#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) - // interval_ is in ns - return interval_ / 1000000; -#else - // interval_ is usecs - return interval_ / 1000; -#endif -} - -inline int64_t TickInterval::Microseconds() const { -#if _WIN32 -#ifdef USE_QUERY_PERFORMANCE_COUNTER - LARGE_INTEGER qpfreq; - QueryPerformanceFrequency(&qpfreq); - return (interval_ * 1000000) / qpfreq.QuadPart; -#else - // interval_ is in ms - return interval_ * 1000LL; -#endif -#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) - // interval_ is in ns - return interval_ / 1000; -#else - // interval_ is usecs - return interval_; -#endif -} - inline TickInterval& TickInterval::operator+=(const TickInterval& rhs) { interval_ += rhs.interval_; return *this; @@ -295,4 +187,4 @@ inline TickInterval& TickInterval::operator-=(const TickInterval& rhs) { } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TICK_UTIL_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_TICK_UTIL_H_ diff --git a/webrtc/system_wrappers/include/timestamp_extrapolator.h b/webrtc/system_wrappers/include/timestamp_extrapolator.h index b8a8b05d97..d9c5c6fb37 100644 --- a/webrtc/system_wrappers/include/timestamp_extrapolator.h +++ b/webrtc/system_wrappers/include/timestamp_extrapolator.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef SYSTEM_WRAPPERS_INTERFACE_TIMESTAMP_EXTRAPOLATOR_H_ -#define SYSTEM_WRAPPERS_INTERFACE_TIMESTAMP_EXTRAPOLATOR_H_ +#ifndef SYSTEM_WRAPPERS_INCLUDE_TIMESTAMP_EXTRAPOLATOR_H_ +#define SYSTEM_WRAPPERS_INCLUDE_TIMESTAMP_EXTRAPOLATOR_H_ #include "webrtc/system_wrappers/include/rw_lock_wrapper.h" #include "webrtc/typedefs.h" @@ -53,4 +53,4 @@ private: } // namespace webrtc -#endif // SYSTEM_WRAPPERS_INTERFACE_TIMESTAMP_EXTRAPOLATOR_H_ +#endif // SYSTEM_WRAPPERS_INCLUDE_TIMESTAMP_EXTRAPOLATOR_H_ diff --git a/webrtc/system_wrappers/include/trace.h b/webrtc/system_wrappers/include/trace.h index e63b603d1b..25a3d746c4 100644 --- a/webrtc/system_wrappers/include/trace.h +++ b/webrtc/system_wrappers/include/trace.h @@ -13,8 +13,8 @@ * messages. Apply filtering to avoid that. */ -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_TRACE_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_TRACE_H_ #include "webrtc/common_types.h" #include "webrtc/typedefs.h" @@ -89,4 +89,4 @@ class Trace { } // namespace webrtc -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_TRACE_H_ diff --git a/webrtc/system_wrappers/include/utf_util_win.h b/webrtc/system_wrappers/include/utf_util_win.h index cc48fd254d..0e3f2d01c6 100644 --- a/webrtc/system_wrappers/include/utf_util_win.h +++ b/webrtc/system_wrappers/include/utf_util_win.h @@ -10,8 +10,8 @@ // Conversion functions for UTF-8 and UTF-16 strings on Windows. // Duplicated from talk/base/win32.h. -#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_UTF_UTIL_H_ -#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_UTF_UTIL_H_ +#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_UTF_UTIL_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_UTF_UTIL_H_ #ifdef WIN32 #include <windows.h> @@ -54,4 +54,4 @@ inline std::string ToUtf8(const std::wstring& wstr) { } // namespace webrtc #endif // WIN32 -#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_UTF_UTIL_H_ +#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_UTF_UTIL_H_ diff --git a/webrtc/system_wrappers/source/Android.mk b/webrtc/system_wrappers/source/Android.mk index b58f902009..480af5177e 100644 --- a/webrtc/system_wrappers/source/Android.mk +++ b/webrtc/system_wrappers/source/Android.mk @@ -31,12 +31,10 @@ LOCAL_SRC_FILES := \ logging.cc \ metrics_default.cc \ rw_lock.cc \ - thread.cc \ trace_impl.cc \ condition_variable_posix.cc \ critical_section_posix.cc \ sleep.cc \ - thread_posix.cc \ trace_posix.cc \ rw_lock_posix.cc \ diff --git a/webrtc/system_wrappers/source/aligned_array_unittest.cc b/webrtc/system_wrappers/source/aligned_array_unittest.cc index 8d898af03e..01238f8342 100644 --- a/webrtc/system_wrappers/source/aligned_array_unittest.cc +++ b/webrtc/system_wrappers/source/aligned_array_unittest.cc @@ -16,7 +16,7 @@ namespace { -bool IsAligned(const void* ptr, int alignment) { +bool IsAligned(const void* ptr, size_t alignment) { return reinterpret_cast<uintptr_t>(ptr) % alignment == 0; } @@ -27,7 +27,7 @@ namespace webrtc { TEST(AlignedArrayTest, CheckAlignment) { AlignedArray<bool> arr(10, 7, 128); ASSERT_TRUE(IsAligned(arr.Array(), 128)); - for (int i = 0; i < 10; ++i) { + for (size_t i = 0; i < 10; ++i) { ASSERT_TRUE(IsAligned(arr.Row(i), 128)); ASSERT_EQ(arr.Row(i), arr.Array()[i]); } @@ -36,13 +36,13 @@ TEST(AlignedArrayTest, CheckAlignment) { TEST(AlignedArrayTest, CheckOverlap) { AlignedArray<size_t> arr(10, 7, 128); - for (int i = 0; i < 10; ++i) { + for (size_t i = 0; i < 10; ++i) { for (size_t j = 0; j < 7; ++j) { arr.At(i, j) = 20 * i + j; } } - for (int i = 0; i < 10; ++i) { + for (size_t i = 0; i < 10; ++i) { for (size_t j = 0; j < 7; ++j) { ASSERT_EQ(arr.At(i, j), 20 * i + j); ASSERT_EQ(arr.Row(i)[j], 20 * i + j); @@ -53,7 +53,7 @@ TEST(AlignedArrayTest, CheckOverlap) { TEST(AlignedArrayTest, CheckRowsCols) { AlignedArray<bool> arr(10, 7, 128); - ASSERT_EQ(arr.rows(), 10); + ASSERT_EQ(arr.rows(), 10u); ASSERT_EQ(arr.cols(), 7u); } diff --git a/webrtc/system_wrappers/source/condition_variable_unittest.cc b/webrtc/system_wrappers/source/condition_variable_unittest.cc index ed845cc21e..5a8dd0b36e 100644 --- a/webrtc/system_wrappers/source/condition_variable_unittest.cc +++ b/webrtc/system_wrappers/source/condition_variable_unittest.cc @@ -11,9 +11,9 @@ #include "webrtc/system_wrappers/include/condition_variable_wrapper.h" #include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/system_wrappers/include/trace.h" @@ -144,12 +144,10 @@ bool WaitingRunFunction(void* obj) { class CondVarTest : public ::testing::Test { public: - CondVarTest() {} + CondVarTest() : thread_(&WaitingRunFunction, &baton_, "CondVarTest") {} virtual void SetUp() { - thread_ = ThreadWrapper::CreateThread(&WaitingRunFunction, - &baton_, "CondVarTest"); - ASSERT_TRUE(thread_->Start()); + thread_.Start(); } virtual void TearDown() { @@ -160,14 +158,14 @@ class CondVarTest : public ::testing::Test { // and Pass). ASSERT_TRUE(baton_.Pass(kShortWaitMs)); ASSERT_TRUE(baton_.Grab(kShortWaitMs)); - ASSERT_TRUE(thread_->Stop()); + thread_.Stop(); } protected: Baton baton_; private: - rtc::scoped_ptr<ThreadWrapper> thread_; + rtc::PlatformThread thread_; }; // The SetUp and TearDown functions use condition variables. diff --git a/webrtc/system_wrappers/source/critical_section_unittest.cc b/webrtc/system_wrappers/source/critical_section_unittest.cc index 6848bdd06b..9abf8b8017 100644 --- a/webrtc/system_wrappers/source/critical_section_unittest.cc +++ b/webrtc/system_wrappers/source/critical_section_unittest.cc @@ -12,7 +12,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/system_wrappers/include/sleep.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/system_wrappers/include/trace.h" namespace webrtc { @@ -78,10 +78,10 @@ TEST_F(CritSectTest, ThreadWakesOnce) NO_THREAD_SAFETY_ANALYSIS { CriticalSectionWrapper* crit_sect = CriticalSectionWrapper::CreateCriticalSection(); ProtectedCount count(crit_sect); - rtc::scoped_ptr<ThreadWrapper> thread = ThreadWrapper::CreateThread( + rtc::PlatformThread thread( &LockUnlockThenStopRunFunction, &count, "ThreadWakesOnce"); crit_sect->Enter(); - ASSERT_TRUE(thread->Start()); + thread.Start(); SwitchProcess(); // The critical section is of reentrant mode, so this should not release // the lock, even though count.Count() locks and unlocks the critical section @@ -90,7 +90,7 @@ TEST_F(CritSectTest, ThreadWakesOnce) NO_THREAD_SAFETY_ANALYSIS { ASSERT_EQ(0, count.Count()); crit_sect->Leave(); // This frees the thread to act. EXPECT_TRUE(WaitForCount(1, &count)); - EXPECT_TRUE(thread->Stop()); + thread.Stop(); delete crit_sect; } @@ -105,10 +105,10 @@ TEST_F(CritSectTest, ThreadWakesTwice) NO_THREAD_SAFETY_ANALYSIS { CriticalSectionWrapper* crit_sect = CriticalSectionWrapper::CreateCriticalSection(); ProtectedCount count(crit_sect); - rtc::scoped_ptr<ThreadWrapper> thread = ThreadWrapper::CreateThread( + rtc::PlatformThread thread( &LockUnlockRunFunction, &count, "ThreadWakesTwice"); crit_sect->Enter(); // Make sure counter stays 0 until we wait for it. - ASSERT_TRUE(thread->Start()); + thread.Start(); crit_sect->Leave(); // The thread is capable of grabbing the lock multiple times, @@ -128,7 +128,7 @@ TEST_F(CritSectTest, ThreadWakesTwice) NO_THREAD_SAFETY_ANALYSIS { SwitchProcess(); EXPECT_TRUE(WaitForCount(count_before + 1, &count)); - EXPECT_TRUE(thread->Stop()); + thread.Stop(); delete crit_sect; } diff --git a/webrtc/system_wrappers/source/data_log.cc b/webrtc/system_wrappers/source/data_log.cc index dbc8ea1505..778769603b 100644 --- a/webrtc/system_wrappers/source/data_log.cc +++ b/webrtc/system_wrappers/source/data_log.cc @@ -318,11 +318,12 @@ int DataLog::NextRow(const std::string& table_name) { } DataLogImpl::DataLogImpl() - : counter_(1), - tables_(), - flush_event_(EventWrapper::Create()), - tables_lock_(RWLockWrapper::CreateRWLock()) { -} + : counter_(1), + tables_(), + flush_event_(EventWrapper::Create()), + file_writer_thread_( + new rtc::PlatformThread(DataLogImpl::Run, instance_, "DataLog")), + tables_lock_(RWLockWrapper::CreateRWLock()) {} DataLogImpl::~DataLogImpl() { StopThread(); @@ -348,12 +349,8 @@ int DataLogImpl::CreateLog() { } int DataLogImpl::Init() { - file_writer_thread_ = ThreadWrapper::CreateThread( - DataLogImpl::Run, instance_, "DataLog"); - bool success = file_writer_thread_->Start(); - if (!success) - return -1; - file_writer_thread_->SetPriority(kHighestPriority); + file_writer_thread_->Start(); + file_writer_thread_->SetPriority(rtc::kHighestPriority); return 0; } @@ -406,13 +403,8 @@ int DataLogImpl::NextRow(const std::string& table_name) { if (tables_.count(table_name) == 0) return -1; tables_[table_name]->NextRow(); - if (!file_writer_thread_) { - // Write every row to file as they get complete. - tables_[table_name]->Flush(); - } else { - // Signal a complete row - flush_event_->Set(); - } + // Signal a complete row + flush_event_->Set(); return 0; } @@ -435,10 +427,8 @@ void DataLogImpl::Process() { } void DataLogImpl::StopThread() { - if (file_writer_thread_) { - flush_event_->Set(); - file_writer_thread_->Stop(); - } + flush_event_->Set(); + file_writer_thread_->Stop(); } } // namespace webrtc diff --git a/webrtc/system_wrappers/source/event_timer_posix.cc b/webrtc/system_wrappers/source/event_timer_posix.cc index 99eebcb70a..9f9a324bcb 100644 --- a/webrtc/system_wrappers/source/event_timer_posix.cc +++ b/webrtc/system_wrappers/source/event_timer_posix.cc @@ -154,14 +154,14 @@ bool EventTimerPosix::StartTimer(bool periodic, unsigned long time) { // Start the timer thread timer_event_.reset(new EventTimerPosix()); const char* thread_name = "WebRtc_event_timer_thread"; - timer_thread_ = ThreadWrapper::CreateThread(Run, this, thread_name); + timer_thread_.reset(new rtc::PlatformThread(Run, this, thread_name)); periodic_ = periodic; time_ = time; - bool started = timer_thread_->Start(); - timer_thread_->SetPriority(kRealtimePriority); + timer_thread_->Start(); + timer_thread_->SetPriority(rtc::kRealtimePriority); pthread_mutex_unlock(&mutex_); - return started; + return true; } bool EventTimerPosix::Run(void* obj) { @@ -215,9 +215,7 @@ bool EventTimerPosix::StopTimer() { timer_event_->Set(); } if (timer_thread_) { - if (!timer_thread_->Stop()) { - return false; - } + timer_thread_->Stop(); timer_thread_.reset(); } timer_event_.reset(); diff --git a/webrtc/system_wrappers/source/event_timer_posix.h b/webrtc/system_wrappers/source/event_timer_posix.h index 21c4ac702e..bbf51f72db 100644 --- a/webrtc/system_wrappers/source/event_timer_posix.h +++ b/webrtc/system_wrappers/source/event_timer_posix.h @@ -16,7 +16,7 @@ #include <pthread.h> #include <time.h> -#include "webrtc/system_wrappers/include/thread_wrapper.h" +#include "webrtc/base/platform_thread.h" namespace webrtc { @@ -46,7 +46,8 @@ class EventTimerPosix : public EventTimerWrapper { pthread_mutex_t mutex_; bool event_set_; - rtc::scoped_ptr<ThreadWrapper> timer_thread_; + // TODO(pbos): Remove scoped_ptr and use PlatformThread directly. + rtc::scoped_ptr<rtc::PlatformThread> timer_thread_; rtc::scoped_ptr<EventTimerPosix> timer_event_; timespec created_at_; diff --git a/webrtc/system_wrappers/source/event_tracer.cc b/webrtc/system_wrappers/source/event_tracer.cc deleted file mode 100644 index 9328e80036..0000000000 --- a/webrtc/system_wrappers/source/event_tracer.cc +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) 2012 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 has moved. -// TODO(tommi): Delete after removing dependencies and updating Chromium. diff --git a/webrtc/system_wrappers/source/event_tracer_unittest.cc b/webrtc/system_wrappers/source/event_tracer_unittest.cc deleted file mode 100644 index 9328e80036..0000000000 --- a/webrtc/system_wrappers/source/event_tracer_unittest.cc +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) 2012 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 has moved. -// TODO(tommi): Delete after removing dependencies and updating Chromium. diff --git a/webrtc/system_wrappers/source/field_trial_default.cc b/webrtc/system_wrappers/source/field_trial_default.cc index 1a9bd6bc79..0e2c286117 100644 --- a/webrtc/system_wrappers/source/field_trial_default.cc +++ b/webrtc/system_wrappers/source/field_trial_default.cc @@ -58,5 +58,9 @@ void InitFieldTrialsFromString(const char* trials_string) { trials_init_string = trials_string; } +const char* GetFieldTrialString() { + return trials_init_string; +} + } // namespace field_trial } // namespace webrtc diff --git a/webrtc/system_wrappers/source/logging_unittest.cc b/webrtc/system_wrappers/source/logging_unittest.cc index 633d84b76b..2da24b26f4 100644 --- a/webrtc/system_wrappers/source/logging_unittest.cc +++ b/webrtc/system_wrappers/source/logging_unittest.cc @@ -72,18 +72,5 @@ TEST_F(LoggingTest, LogStream) { } } -TEST_F(LoggingTest, LogFunctionError) { - { - CriticalSectionScoped cs(crit_.get()); - int bar = 42; - int baz = 99; - level_ = kTraceError; - expected_log_ << "(logging_unittest.cc:" << __LINE__ + 2 - << "): Foo failed: bar=" << bar << ", baz=" << baz; - LOG_FERR2(LS_ERROR, Foo, bar, baz); - cv_->SleepCS(*crit_.get(), 2000); - } -} - } // namespace } // namespace webrtc diff --git a/webrtc/system_wrappers/source/metrics_unittest.cc b/webrtc/system_wrappers/source/metrics_unittest.cc new file mode 100644 index 0000000000..8319b78ee0 --- /dev/null +++ b/webrtc/system_wrappers/source/metrics_unittest.cc @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2015 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. + */ + +#include "testing/gtest/include/gtest/gtest.h" + +#include "webrtc/system_wrappers/include/metrics.h" +#include "webrtc/test/histogram.h" + +namespace webrtc { +namespace { +const int kSample = 22; +const std::string kName = "Name"; + +void AddSparseSample(const std::string& name, int sample) { + RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample); +} +#if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) +void AddSample(const std::string& name, int sample) { + RTC_HISTOGRAM_COUNTS_100(name, sample); +} +#endif // GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) +} // namespace + +TEST(MetricsTest, InitiallyNoSamples) { + test::ClearHistograms(); + EXPECT_EQ(0, test::NumHistogramSamples(kName)); + EXPECT_EQ(-1, test::LastHistogramSample(kName)); +} + +TEST(MetricsTest, RtcHistogramPercent_AddSample) { + test::ClearHistograms(); + RTC_HISTOGRAM_PERCENTAGE(kName, kSample); + EXPECT_EQ(1, test::NumHistogramSamples(kName)); + EXPECT_EQ(kSample, test::LastHistogramSample(kName)); +} + +TEST(MetricsTest, RtcHistogramEnumeration_AddSample) { + test::ClearHistograms(); + RTC_HISTOGRAM_ENUMERATION(kName, kSample, kSample + 1); + EXPECT_EQ(1, test::NumHistogramSamples(kName)); + EXPECT_EQ(kSample, test::LastHistogramSample(kName)); +} + +TEST(MetricsTest, RtcHistogramCountsSparse_AddSample) { + test::ClearHistograms(); + RTC_HISTOGRAM_COUNTS_SPARSE_100(kName, kSample); + EXPECT_EQ(1, test::NumHistogramSamples(kName)); + EXPECT_EQ(kSample, test::LastHistogramSample(kName)); +} + +TEST(MetricsTest, RtcHistogramCounts_AddSample) { + test::ClearHistograms(); + RTC_HISTOGRAM_COUNTS_100(kName, kSample); + EXPECT_EQ(1, test::NumHistogramSamples(kName)); + EXPECT_EQ(kSample, test::LastHistogramSample(kName)); +} + +TEST(MetricsTest, RtcHistogramCounts_AddMultipleSamples) { + test::ClearHistograms(); + const int kNumSamples = 10; + for (int i = 0; i < kNumSamples; ++i) { + RTC_HISTOGRAM_COUNTS_100(kName, i); + } + EXPECT_EQ(kNumSamples, test::NumHistogramSamples(kName)); + EXPECT_EQ(kNumSamples - 1, test::LastHistogramSample(kName)); +} + +TEST(MetricsTest, RtcHistogramSparse_NonConstantNameWorks) { + test::ClearHistograms(); + AddSparseSample("Name1", kSample); + AddSparseSample("Name2", kSample); + EXPECT_EQ(1, test::NumHistogramSamples("Name1")); + EXPECT_EQ(1, test::NumHistogramSamples("Name2")); +} + +#if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) +TEST(MetricsTest, RtcHistogram_FailsForNonConstantName) { + test::ClearHistograms(); + AddSample("Name1", kSample); + EXPECT_DEATH(AddSample("Name2", kSample), ""); +} +#endif // GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) + +} // namespace webrtc diff --git a/webrtc/system_wrappers/source/ntp_time_unittest.cc b/webrtc/system_wrappers/source/ntp_time_unittest.cc new file mode 100644 index 0000000000..ff11288c1b --- /dev/null +++ b/webrtc/system_wrappers/source/ntp_time_unittest.cc @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2014 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. + */ + +#include "testing/gtest/include/gtest/gtest.h" + +#include "webrtc/system_wrappers/include/ntp_time.h" + +namespace webrtc { +namespace { + +const uint32_t kNtpSec = 0x12345678; +const uint32_t kNtpFrac = 0x23456789; + +TEST(NtpTimeTest, NoValueMeansInvalid) { + NtpTime ntp; + EXPECT_FALSE(ntp.Valid()); +} + +TEST(NtpTimeTest, CanResetValue) { + NtpTime ntp(kNtpSec, kNtpFrac); + EXPECT_TRUE(ntp.Valid()); + ntp.Reset(); + EXPECT_FALSE(ntp.Valid()); +} + +TEST(NtpTimeTest, CanGetWhatIsSet) { + NtpTime ntp; + ntp.Set(kNtpSec, kNtpFrac); + EXPECT_EQ(kNtpSec, ntp.seconds()); + EXPECT_EQ(kNtpFrac, ntp.fractions()); +} + +TEST(NtpTimeTest, SetIsSameAs2ParameterConstructor) { + NtpTime ntp1(kNtpSec, kNtpFrac); + NtpTime ntp2; + EXPECT_NE(ntp1, ntp2); + + ntp2.Set(kNtpSec, kNtpFrac); + EXPECT_EQ(ntp1, ntp2); +} + +TEST(NtpTimeTest, SetCurrentIsSameAs1ParameterConstructor) { + SimulatedClock clock(0x0123456789abcdef); + + NtpTime ntp1(clock); + NtpTime ntp2; + EXPECT_NE(ntp1, ntp2); + + ntp2.SetCurrent(clock); + EXPECT_EQ(ntp1, ntp2); +} + +TEST(NtpTimeTest, ToMsMeansToNtpMilliseconds) { + SimulatedClock clock(0x123456789abc); + + NtpTime ntp(clock); + EXPECT_EQ(ntp.ToMs(), Clock::NtpToMs(ntp.seconds(), ntp.fractions())); + EXPECT_EQ(ntp.ToMs(), clock.CurrentNtpInMilliseconds()); +} + +} // namespace +} // namespace webrtc diff --git a/webrtc/system_wrappers/source/scoped_vector_unittest.cc b/webrtc/system_wrappers/source/scoped_vector_unittest.cc index b049e4a340..6e38f01f0b 100644 --- a/webrtc/system_wrappers/source/scoped_vector_unittest.cc +++ b/webrtc/system_wrappers/source/scoped_vector_unittest.cc @@ -221,7 +221,8 @@ TEST(ScopedVectorTest, MoveConstruct) { EXPECT_FALSE(scoped_vector.empty()); EXPECT_TRUE(watcher.IsWatching(scoped_vector.back())); - ScopedVector<LifeCycleObject> scoped_vector_copy(scoped_vector.Pass()); + ScopedVector<LifeCycleObject> scoped_vector_copy( + scoped_vector.DEPRECATED_Pass()); EXPECT_TRUE(scoped_vector.empty()); EXPECT_FALSE(scoped_vector_copy.empty()); EXPECT_TRUE(watcher.IsWatching(scoped_vector_copy.back())); @@ -241,7 +242,7 @@ TEST(ScopedVectorTest, MoveAssign) { EXPECT_FALSE(scoped_vector.empty()); EXPECT_TRUE(watcher.IsWatching(scoped_vector.back())); - scoped_vector_assign = scoped_vector.Pass(); + scoped_vector_assign = scoped_vector.DEPRECATED_Pass(); EXPECT_TRUE(scoped_vector.empty()); EXPECT_FALSE(scoped_vector_assign.empty()); EXPECT_TRUE(watcher.IsWatching(scoped_vector_assign.back())); @@ -273,10 +274,11 @@ class DeleteCounter { template <typename T> class PassThru { public: - explicit PassThru(ScopedVector<T> scoper) : scoper_(scoper.Pass()) {} + explicit PassThru(ScopedVector<T> scoper) + : scoper_(scoper.DEPRECATED_Pass()) {} ScopedVector<T> Run() { - return scoper_.Pass(); + return scoper_.DEPRECATED_Pass(); } private: @@ -288,7 +290,7 @@ TEST(ScopedVectorTest, Passed) { ScopedVector<DeleteCounter> deleter_vector; deleter_vector.push_back(new DeleteCounter(&deletes)); EXPECT_EQ(0, deletes); - PassThru<DeleteCounter> pass_thru(deleter_vector.Pass()); + PassThru<DeleteCounter> pass_thru(deleter_vector.DEPRECATED_Pass()); EXPECT_EQ(0, deletes); ScopedVector<DeleteCounter> result = pass_thru.Run(); EXPECT_EQ(0, deletes); diff --git a/webrtc/system_wrappers/source/thread.cc b/webrtc/system_wrappers/source/thread.cc deleted file mode 100644 index 7da1e3d591..0000000000 --- a/webrtc/system_wrappers/source/thread.cc +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2011 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. - */ - -#include "webrtc/system_wrappers/include/thread_wrapper.h" - -#if defined(_WIN32) -#include "webrtc/system_wrappers/source/thread_win.h" -#else -#include "webrtc/system_wrappers/source/thread_posix.h" -#endif - -namespace webrtc { - -#if defined(_WIN32) -typedef ThreadWindows ThreadType; -#else -typedef ThreadPosix ThreadType; -#endif - -rtc::scoped_ptr<ThreadWrapper> ThreadWrapper::CreateThread( - ThreadRunFunction func, void* obj, const char* thread_name) { - return rtc::scoped_ptr<ThreadWrapper>( - new ThreadType(func, obj, thread_name)).Pass(); -} - -} // namespace webrtc diff --git a/webrtc/system_wrappers/source/thread_posix.cc b/webrtc/system_wrappers/source/thread_posix.cc deleted file mode 100644 index 32ab13c780..0000000000 --- a/webrtc/system_wrappers/source/thread_posix.cc +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2012 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. - */ - -#include "webrtc/system_wrappers/source/thread_posix.h" - -#include <algorithm> - -#include <errno.h> -#include <unistd.h> -#ifdef WEBRTC_LINUX -#include <linux/unistd.h> -#include <sched.h> -#include <sys/types.h> -#endif - -#include "webrtc/base/checks.h" -#include "webrtc/base/platform_thread.h" -#include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/sleep.h" -#include "webrtc/system_wrappers/include/trace.h" - -namespace webrtc { -namespace { -struct ThreadAttributes { - ThreadAttributes() { pthread_attr_init(&attr); } - ~ThreadAttributes() { pthread_attr_destroy(&attr); } - pthread_attr_t* operator&() { return &attr; } - pthread_attr_t attr; -}; -} // namespace - -int ConvertToSystemPriority(ThreadPriority priority, int min_prio, - int max_prio) { - RTC_DCHECK(max_prio - min_prio > 2); - const int top_prio = max_prio - 1; - const int low_prio = min_prio + 1; - - switch (priority) { - case kLowPriority: - return low_prio; - case kNormalPriority: - // The -1 ensures that the kHighPriority is always greater or equal to - // kNormalPriority. - return (low_prio + top_prio - 1) / 2; - case kHighPriority: - return std::max(top_prio - 2, low_prio); - case kHighestPriority: - return std::max(top_prio - 1, low_prio); - case kRealtimePriority: - return top_prio; - } - RTC_DCHECK(false); - return low_prio; -} - -// static -void* ThreadPosix::StartThread(void* param) { - static_cast<ThreadPosix*>(param)->Run(); - return 0; -} - -ThreadPosix::ThreadPosix(ThreadRunFunction func, void* obj, - const char* thread_name) - : run_function_(func), - obj_(obj), - stop_event_(false, false), - name_(thread_name ? thread_name : "webrtc"), - thread_(0) { - RTC_DCHECK(name_.length() < 64); -} - -uint32_t ThreadWrapper::GetThreadId() { - return rtc::CurrentThreadId(); -} - -ThreadPosix::~ThreadPosix() { - RTC_DCHECK(thread_checker_.CalledOnValidThread()); -} - -// TODO(pbos): Make Start void, calling code really doesn't support failures -// here. -bool ThreadPosix::Start() { - RTC_DCHECK(thread_checker_.CalledOnValidThread()); - RTC_DCHECK(!thread_) << "Thread already started?"; - - ThreadAttributes attr; - // Set the stack stack size to 1M. - pthread_attr_setstacksize(&attr, 1024 * 1024); - RTC_CHECK_EQ(0, pthread_create(&thread_, &attr, &StartThread, this)); - return true; -} - -bool ThreadPosix::Stop() { - RTC_DCHECK(thread_checker_.CalledOnValidThread()); - if (!thread_) - return true; - - stop_event_.Set(); - RTC_CHECK_EQ(0, pthread_join(thread_, nullptr)); - thread_ = 0; - - return true; -} - -bool ThreadPosix::SetPriority(ThreadPriority priority) { - RTC_DCHECK(thread_checker_.CalledOnValidThread()); - if (!thread_) - return false; -#if defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX) - // TODO(tommi): Switch to the same mechanism as Chromium uses for - // changing thread priorities. - return true; -#else -#ifdef WEBRTC_THREAD_RR - const int policy = SCHED_RR; -#else - const int policy = SCHED_FIFO; -#endif - const int min_prio = sched_get_priority_min(policy); - const int max_prio = sched_get_priority_max(policy); - if (min_prio == -1 || max_prio == -1) { - WEBRTC_TRACE(kTraceError, kTraceUtility, -1, - "unable to retreive min or max priority for threads"); - return false; - } - - if (max_prio - min_prio <= 2) - return false; - - sched_param param; - param.sched_priority = ConvertToSystemPriority(priority, min_prio, max_prio); - if (pthread_setschedparam(thread_, policy, ¶m) != 0) { - WEBRTC_TRACE( - kTraceError, kTraceUtility, -1, "unable to set thread priority"); - return false; - } - - return true; -#endif // defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX) -} - -void ThreadPosix::Run() { - if (!name_.empty()) { - // Setting the thread name may fail (harmlessly) if running inside a - // sandbox. Ignore failures if they happen. - rtc::SetCurrentThreadName(name_.substr(0, 63).c_str()); - } - - // It's a requirement that for successful thread creation that the run - // function be called at least once (see RunFunctionIsCalled unit test), - // so to fullfill that requirement, we use a |do| loop and not |while|. - do { - if (!run_function_(obj_)) - break; - } while (!stop_event_.Wait(0)); -} - -} // namespace webrtc diff --git a/webrtc/system_wrappers/source/thread_posix.h b/webrtc/system_wrappers/source/thread_posix.h deleted file mode 100644 index bcdd732f86..0000000000 --- a/webrtc/system_wrappers/source/thread_posix.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2012 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 WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_ -#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_ - -#include "webrtc/base/event.h" -#include "webrtc/base/scoped_ptr.h" -#include "webrtc/base/thread_checker.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" - -#include <pthread.h> - -namespace webrtc { - -int ConvertToSystemPriority(ThreadPriority priority, int min_prio, - int max_prio); - -class ThreadPosix : public ThreadWrapper { - public: - ThreadPosix(ThreadRunFunction func, void* obj, const char* thread_name); - ~ThreadPosix() override; - - // From ThreadWrapper. - bool Start() override; - bool Stop() override; - - bool SetPriority(ThreadPriority priority) override; - - private: - static void* StartThread(void* param); - - void Run(); - - rtc::ThreadChecker thread_checker_; - ThreadRunFunction const run_function_; - void* const obj_; - rtc::Event stop_event_; - const std::string name_; - - pthread_t thread_; -}; - -} // namespace webrtc - -#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_POSIX_H_ diff --git a/webrtc/system_wrappers/source/thread_posix_unittest.cc b/webrtc/system_wrappers/source/thread_posix_unittest.cc deleted file mode 100644 index edfb14502e..0000000000 --- a/webrtc/system_wrappers/source/thread_posix_unittest.cc +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2012 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. - */ - -#include "webrtc/system_wrappers/source/thread_posix.h" - -#include "testing/gtest/include/gtest/gtest.h" - -TEST(ThreadTestPosix, PrioritySettings) { - // API assumes that max_prio - min_prio > 2. Test the extreme case. - const int kMinPrio = -1; - const int kMaxPrio = 2; - - int last_priority = kMinPrio; - for (int priority = webrtc::kLowPriority; - priority <= webrtc::kRealtimePriority; ++priority) { - int system_priority = webrtc::ConvertToSystemPriority( - static_cast<webrtc::ThreadPriority>(priority), kMinPrio, kMaxPrio); - EXPECT_GT(system_priority, kMinPrio); - EXPECT_LT(system_priority, kMaxPrio); - EXPECT_GE(system_priority, last_priority); - last_priority = system_priority; - } -} diff --git a/webrtc/system_wrappers/source/thread_unittest.cc b/webrtc/system_wrappers/source/thread_unittest.cc deleted file mode 100644 index c8e180ba32..0000000000 --- a/webrtc/system_wrappers/source/thread_unittest.cc +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2012 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. - */ - -#include "webrtc/system_wrappers/include/thread_wrapper.h" - -#include "testing/gtest/include/gtest/gtest.h" -#include "webrtc/base/scoped_ptr.h" -#include "webrtc/system_wrappers/include/sleep.h" - -namespace webrtc { - -// Function that does nothing, and reports success. -bool NullRunFunction(void* obj) { - SleepMs(0); // Hand over timeslice, prevents busy looping. - return true; -} - -TEST(ThreadTest, StartStop) { - rtc::scoped_ptr<ThreadWrapper> thread = ThreadWrapper::CreateThread( - &NullRunFunction, nullptr, "ThreadTest"); - ASSERT_TRUE(thread->Start()); - EXPECT_TRUE(thread->Stop()); -} - -// Function that sets a boolean. -bool SetFlagRunFunction(void* obj) { - bool* obj_as_bool = static_cast<bool*>(obj); - *obj_as_bool = true; - SleepMs(0); // Hand over timeslice, prevents busy looping. - return true; -} - -TEST(ThreadTest, RunFunctionIsCalled) { - bool flag = false; - rtc::scoped_ptr<ThreadWrapper> thread = ThreadWrapper::CreateThread( - &SetFlagRunFunction, &flag, "RunFunctionIsCalled"); - ASSERT_TRUE(thread->Start()); - - // At this point, the flag may be either true or false. - EXPECT_TRUE(thread->Stop()); - - // We expect the thread to have run at least once. - EXPECT_TRUE(flag); -} - -} // namespace webrtc diff --git a/webrtc/system_wrappers/source/thread_win.cc b/webrtc/system_wrappers/source/thread_win.cc deleted file mode 100644 index c42196722e..0000000000 --- a/webrtc/system_wrappers/source/thread_win.cc +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2011 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. - */ - -#include "webrtc/system_wrappers/source/thread_win.h" - -#include <process.h> -#include <stdio.h> -#include <windows.h> - -#include "webrtc/base/checks.h" -#include "webrtc/base/platform_thread.h" -#include "webrtc/system_wrappers/include/trace.h" - -namespace webrtc { -namespace { -void CALLBACK RaiseFlag(ULONG_PTR param) { - *reinterpret_cast<bool*>(param) = true; -} -} - -ThreadWindows::ThreadWindows(ThreadRunFunction func, void* obj, - const char* thread_name) - : run_function_(func), - obj_(obj), - stop_(false), - thread_(NULL), - name_(thread_name ? thread_name : "webrtc") { - RTC_DCHECK(func); -} - -ThreadWindows::~ThreadWindows() { - RTC_DCHECK(main_thread_.CalledOnValidThread()); - RTC_DCHECK(!thread_); -} - -// static -uint32_t ThreadWrapper::GetThreadId() { - return GetCurrentThreadId(); -} - -// static -DWORD WINAPI ThreadWindows::StartThread(void* param) { - static_cast<ThreadWindows*>(param)->Run(); - return 0; -} - -bool ThreadWindows::Start() { - RTC_DCHECK(main_thread_.CalledOnValidThread()); - RTC_DCHECK(!thread_); - - stop_ = false; - - // See bug 2902 for background on STACK_SIZE_PARAM_IS_A_RESERVATION. - // Set the reserved stack stack size to 1M, which is the default on Windows - // and Linux. - DWORD thread_id; - thread_ = ::CreateThread(NULL, 1024 * 1024, &StartThread, this, - STACK_SIZE_PARAM_IS_A_RESERVATION, &thread_id); - if (!thread_ ) { - RTC_DCHECK(false) << "CreateThread failed"; - return false; - } - - return true; -} - -bool ThreadWindows::Stop() { - RTC_DCHECK(main_thread_.CalledOnValidThread()); - if (thread_) { - // Set stop_ to |true| on the worker thread. - QueueUserAPC(&RaiseFlag, thread_, reinterpret_cast<ULONG_PTR>(&stop_)); - WaitForSingleObject(thread_, INFINITE); - CloseHandle(thread_); - thread_ = nullptr; - } - - return true; -} - -bool ThreadWindows::SetPriority(ThreadPriority priority) { - RTC_DCHECK(main_thread_.CalledOnValidThread()); - return thread_ && SetThreadPriority(thread_, priority); -} - -void ThreadWindows::Run() { - if (!name_.empty()) - rtc::SetCurrentThreadName(name_.c_str()); - - do { - // The interface contract of Start/Stop is that for a successfull call to - // Start, there should be at least one call to the run function. So we - // call the function before checking |stop_|. - if (!run_function_(obj_)) - break; - // Alertable sleep to permit RaiseFlag to run and update |stop_|. - SleepEx(0, true); - } while (!stop_); -} - -} // namespace webrtc diff --git a/webrtc/system_wrappers/source/thread_win.h b/webrtc/system_wrappers/source/thread_win.h deleted file mode 100644 index 34edd6d6c0..0000000000 --- a/webrtc/system_wrappers/source/thread_win.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2011 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 WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_ -#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_ - -#include "webrtc/system_wrappers/include/thread_wrapper.h" - -#include <windows.h> - -#include "webrtc/base/thread_checker.h" - -namespace webrtc { - -class ThreadWindows : public ThreadWrapper { - public: - ThreadWindows(ThreadRunFunction func, void* obj, const char* thread_name); - ~ThreadWindows() override; - - bool Start() override; - bool Stop() override; - - bool SetPriority(ThreadPriority priority) override; - - protected: - void Run(); - - private: - static DWORD WINAPI StartThread(void* param); - - ThreadRunFunction const run_function_; - void* const obj_; - bool stop_; - HANDLE thread_; - const std::string name_; - rtc::ThreadChecker main_thread_; -}; - -} // namespace webrtc - -#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WIN_H_ diff --git a/webrtc/system_wrappers/source/tick_util.cc b/webrtc/system_wrappers/source/tick_util.cc index bc8fcfe91b..8d94289417 100644 --- a/webrtc/system_wrappers/source/tick_util.cc +++ b/webrtc/system_wrappers/source/tick_util.cc @@ -14,33 +14,79 @@ namespace webrtc { -bool TickTime::use_fake_clock_ = false; -int64_t TickTime::fake_ticks_ = 0; +int64_t TickTime::MillisecondTimestamp() { + return TicksToMilliseconds(TickTime::Now().Ticks()); +} -void TickTime::UseFakeClock(int64_t start_millisecond) { - use_fake_clock_ = true; - fake_ticks_ = MillisecondsToTicks(start_millisecond); +int64_t TickTime::MicrosecondTimestamp() { + return TicksToMicroseconds(TickTime::Now().Ticks()); } -void TickTime::AdvanceFakeClock(int64_t milliseconds) { - assert(use_fake_clock_); - fake_ticks_ += MillisecondsToTicks(milliseconds); +int64_t TickTime::MillisecondsToTicks(const int64_t ms) { +#if _WIN32 + return ms; +#elif defined(WEBRTC_LINUX) + return ms * 1000000LL; +#elif defined(WEBRTC_MAC) + // TODO(pbos): Fix unsafe use of static locals. + static double timebase_from_millisecond_fract = 0.0; + if (timebase_from_millisecond_fract == 0.0) { + mach_timebase_info_data_t timebase; + (void)mach_timebase_info(&timebase); + timebase_from_millisecond_fract = (timebase.denom * 1e6) / timebase.numer; + } + return ms * timebase_from_millisecond_fract; +#else + return ms * 1000LL; +#endif } -int64_t TickTime::QueryOsForTicks() { - TickTime result; +int64_t TickTime::TicksToMilliseconds(const int64_t ticks) { #if _WIN32 - // TODO(wu): Remove QueryPerformanceCounter implementation. -#ifdef USE_QUERY_PERFORMANCE_COUNTER - // QueryPerformanceCounter returns the value from the TSC which is - // incremented at the CPU frequency. The algorithm used requires - // the CPU frequency to be constant. Technology like speed stepping - // which has variable CPU frequency will therefore yield unpredictable, - // incorrect time estimations. - LARGE_INTEGER qpcnt; - QueryPerformanceCounter(&qpcnt); - result.ticks_ = qpcnt.QuadPart; + return ticks; +#elif defined(WEBRTC_LINUX) + return ticks / 1000000LL; +#elif defined(WEBRTC_MAC) + // TODO(pbos): Fix unsafe use of static locals. + static double timebase_microsecond_fract = 0.0; + if (timebase_microsecond_fract == 0.0) { + mach_timebase_info_data_t timebase; + (void)mach_timebase_info(&timebase); + timebase_microsecond_fract = timebase.numer / (timebase.denom * 1e6); + } + return ticks * timebase_microsecond_fract; #else + return ticks; +#endif +} + +int64_t TickTime::TicksToMicroseconds(const int64_t ticks) { +#if _WIN32 + return ticks * 1000LL; +#elif defined(WEBRTC_LINUX) + return ticks / 1000LL; +#elif defined(WEBRTC_MAC) + // TODO(pbos): Fix unsafe use of static locals. + static double timebase_microsecond_fract = 0.0; + if (timebase_microsecond_fract == 0.0) { + mach_timebase_info_data_t timebase; + (void)mach_timebase_info(&timebase); + timebase_microsecond_fract = timebase.numer / (timebase.denom * 1e3); + } + return ticks * timebase_microsecond_fract; +#else + return ticks; +#endif +} + +// Gets the native system tick count. The actual unit, resolution, and epoch +// varies by platform: +// Windows: Milliseconds of uptime with rollover count in the upper 32-bits. +// Linux/Android: Nanoseconds since the Unix epoch. +// Mach (Mac/iOS): "absolute" time since first call. +// Unknown POSIX: Microseconds since the Unix epoch. +int64_t TickTime::QueryOsForTicks() { +#if _WIN32 static volatile LONG last_time_get_time = 0; static volatile int64_t num_wrap_time_get_time = 0; volatile LONG* last_time_get_time_ptr = &last_time_get_time; @@ -53,11 +99,11 @@ int64_t TickTime::QueryOsForTicks() { // 0x0fffffff ~3.1 days, the code will not take that long to execute // so it must have been a wrap around. if (old > 0xf0000000 && now < 0x0fffffff) { + // TODO(pbos): Fix unsafe use of static locals. num_wrap_time_get_time++; } } - result.ticks_ = now + (num_wrap_time_get_time << 32); -#endif + return now + (num_wrap_time_get_time << 32); #elif defined(WEBRTC_LINUX) struct timespec ts; // TODO(wu): Remove CLOCK_REALTIME implementation. @@ -66,33 +112,24 @@ int64_t TickTime::QueryOsForTicks() { #else clock_gettime(CLOCK_MONOTONIC, &ts); #endif - result.ticks_ = 1000000000LL * static_cast<int64_t>(ts.tv_sec) + - static_cast<int64_t>(ts.tv_nsec); + return 1000000000LL * ts.tv_sec + ts.tv_nsec; #elif defined(WEBRTC_MAC) - static mach_timebase_info_data_t timebase; - if (timebase.denom == 0) { - // Get the timebase if this is the first time we run. - // Recommended by Apple's QA1398. - kern_return_t retval = mach_timebase_info(&timebase); - if (retval != KERN_SUCCESS) { - // TODO(wu): Implement RTC_CHECK for all the platforms. Then replace this - // with a RTC_CHECK_EQ(retval, KERN_SUCCESS); -#ifndef WEBRTC_IOS - asm("int3"); -#else - __builtin_trap(); -#endif // WEBRTC_IOS - } + // Return absolute time as an offset from the first call to this function, so + // that we can do floating-point (double) operations on it without losing + // precision. This holds true until the elapsed time is ~11 days, + // at which point we'll start to lose some precision, though not enough to + // matter for millisecond accuracy for another couple years after that. + // TODO(pbos): Fix unsafe use of static locals. + static uint64_t timebase_start = 0; + if (timebase_start == 0) { + timebase_start = mach_absolute_time(); } - // Use timebase to convert absolute time tick units into nanoseconds. - result.ticks_ = mach_absolute_time() * timebase.numer / timebase.denom; + return mach_absolute_time() - timebase_start; #else struct timeval tv; gettimeofday(&tv, NULL); - result.ticks_ = 1000000LL * static_cast<int64_t>(tv.tv_sec) + - static_cast<int64_t>(tv.tv_usec); + return 1000000LL * tv.tv_sec + tv.tv_usec; #endif - return result.ticks_; } } // namespace webrtc diff --git a/webrtc/system_wrappers/source/trace_impl.cc b/webrtc/system_wrappers/source/trace_impl.cc index ffe79b9862..5029f5ab6e 100644 --- a/webrtc/system_wrappers/source/trace_impl.cc +++ b/webrtc/system_wrappers/source/trace_impl.cc @@ -16,6 +16,7 @@ #include <string.h> #include "webrtc/base/atomicops.h" +#include "webrtc/base/platform_thread.h" #ifdef _WIN32 #include "webrtc/system_wrappers/source/trace_win.h" #else @@ -76,7 +77,7 @@ TraceImpl::~TraceImpl() { } int32_t TraceImpl::AddThreadId(char* trace_message) const { - uint32_t thread_id = ThreadWrapper::GetThreadId(); + uint32_t thread_id = rtc::CurrentThreadId(); // Messages is 12 characters. return sprintf(trace_message, "%10u; ", thread_id); } diff --git a/webrtc/system_wrappers/source/trace_impl.h b/webrtc/system_wrappers/source/trace_impl.h index ed49d9d0aa..c6d81d5b0b 100644 --- a/webrtc/system_wrappers/source/trace_impl.h +++ b/webrtc/system_wrappers/source/trace_impl.h @@ -16,7 +16,7 @@ #include "webrtc/system_wrappers/include/event_wrapper.h" #include "webrtc/system_wrappers/include/file_wrapper.h" #include "webrtc/system_wrappers/include/static_instance.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/system_wrappers/include/trace.h" namespace webrtc { diff --git a/webrtc/system_wrappers/system_wrappers.gyp b/webrtc/system_wrappers/system_wrappers.gyp index f66437b37a..507fc45311 100644 --- a/webrtc/system_wrappers/system_wrappers.gyp +++ b/webrtc/system_wrappers/system_wrappers.gyp @@ -28,7 +28,6 @@ 'include/data_log.h', 'include/data_log_c.h', 'include/data_log_impl.h', - 'include/event_tracer.h', 'include/event_wrapper.h', 'include/field_trial.h', 'include/file_wrapper.h', @@ -36,6 +35,7 @@ 'include/logcat_trace_context.h', 'include/logging.h', 'include/metrics.h', + 'include/ntp_time.h', 'include/ref_count.h', 'include/rtp_to_ntp.h', 'include/rw_lock_wrapper.h', @@ -45,7 +45,6 @@ 'include/static_instance.h', 'include/stl_util.h', 'include/stringize_macros.h', - 'include/thread_wrapper.h', 'include/tick_util.h', 'include/timestamp_extrapolator.h', 'include/trace.h', @@ -77,7 +76,6 @@ 'source/event_timer_posix.h', 'source/event_timer_win.cc', 'source/event_timer_win.h', - 'source/event_tracer.cc', 'source/file_impl.cc', 'source/file_impl.h', 'source/logcat_trace_context.cc', @@ -93,11 +91,6 @@ 'source/sleep.cc', 'source/sort.cc', 'source/tick_util.cc', - 'source/thread.cc', - 'source/thread_posix.cc', - 'source/thread_posix.h', - 'source/thread_win.cc', - 'source/thread_win.h', 'source/timestamp_extrapolator.cc', 'source/trace_impl.cc', 'source/trace_impl.h', @@ -206,13 +199,11 @@ 'sources': [ 'source/metrics_default.cc', ], - 'dependencies': [ - 'system_wrappers', - ] }, { 'target_name': 'system_wrappers_default', 'type': 'static_library', 'dependencies': [ + 'system_wrappers', 'field_trial_default', 'metrics_default', ] diff --git a/webrtc/system_wrappers/system_wrappers_tests.gyp b/webrtc/system_wrappers/system_wrappers_tests.gyp index da2fe7432f..a0ae14d6cf 100644 --- a/webrtc/system_wrappers/system_wrappers_tests.gyp +++ b/webrtc/system_wrappers/system_wrappers_tests.gyp @@ -15,6 +15,7 @@ 'dependencies': [ '<(DEPTH)/testing/gtest.gyp:gtest', '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers', + '<(webrtc_root)/test/test.gyp:histogram', '<(webrtc_root)/test/test.gyp:test_support_main', ], 'sources': [ @@ -23,19 +24,18 @@ 'source/clock_unittest.cc', 'source/condition_variable_unittest.cc', 'source/critical_section_unittest.cc', - 'source/event_tracer_unittest.cc', 'source/logging_unittest.cc', 'source/data_log_unittest.cc', 'source/data_log_unittest_disabled.cc', 'source/data_log_helpers_unittest.cc', 'source/data_log_c_helpers_unittest.c', 'source/data_log_c_helpers_unittest.h', + 'source/metrics_unittest.cc', + 'source/ntp_time_unittest.cc', 'source/rtp_to_ntp_unittest.cc', 'source/scoped_vector_unittest.cc', 'source/stringize_macros_unittest.cc', 'source/stl_util_unittest.cc', - 'source/thread_unittest.cc', - 'source/thread_posix_unittest.cc', ], 'conditions': [ ['enable_data_logging==1', { @@ -43,9 +43,6 @@ }, { 'sources!': [ 'source/data_log_unittest.cc', ], }], - ['os_posix==0', { - 'sources!': [ 'source/thread_posix_unittest.cc', ], - }], ['OS=="android"', { 'dependencies': [ '<(DEPTH)/testing/android/native_test.gyp:native_test_native_code', |