Update system_wrappers

Corresponds to upstream commit 524e9b043e7e86fd72353b987c9d5f6a1ebf83e1
This commit is contained in:
Arun Raghavan 2015-10-13 12:23:08 +05:30
parent c4fb4e38de
commit 5ae7a5d6cd
10 changed files with 423 additions and 266 deletions

View File

@ -0,0 +1,99 @@
//
// Copyright (c) 2013 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.
//
// Borrowed from
// https://code.google.com/p/gperftools/source/browse/src/base/thread_annotations.h
// but adapted for clang attributes instead of the gcc.
//
// This header file contains the macro definitions for thread safety
// annotations that allow the developers to document the locking policies
// of their multi-threaded code. The annotations can also help program
// analysis tools to identify potential thread safety issues.
#ifndef BASE_THREAD_ANNOTATIONS_H_
#define BASE_THREAD_ANNOTATIONS_H_
#if defined(__clang__) && (!defined(SWIG))
#define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
#else
#define THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op
#endif
// Document if a shared variable/field needs to be protected by a lock.
// GUARDED_BY allows the user to specify a particular lock that should be
// held when accessing the annotated variable, while GUARDED_VAR only
// indicates a shared variable should be guarded (by any lock). GUARDED_VAR
// is primarily used when the client cannot express the name of the lock.
#define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
#define GUARDED_VAR THREAD_ANNOTATION_ATTRIBUTE__(guarded)
// Document if the memory location pointed to by a pointer should be guarded
// by a lock when dereferencing the pointer. Similar to GUARDED_VAR,
// PT_GUARDED_VAR is primarily used when the client cannot express the name
// of the lock. Note that a pointer variable to a shared memory location
// could itself be a shared variable. For example, if a shared global pointer
// q, which is guarded by mu1, points to a shared memory location that is
// guarded by mu2, q should be annotated as follows:
// int *q GUARDED_BY(mu1) PT_GUARDED_BY(mu2);
#define PT_GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(point_to_guarded_by(x))
#define PT_GUARDED_VAR THREAD_ANNOTATION_ATTRIBUTE__(point_to_guarded)
// Document the acquisition order between locks that can be held
// simultaneously by a thread. For any two locks that need to be annotated
// to establish an acquisition order, only one of them needs the annotation.
// (i.e. You don't have to annotate both locks with both ACQUIRED_AFTER
// and ACQUIRED_BEFORE.)
#define ACQUIRED_AFTER(x) THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(x))
#define ACQUIRED_BEFORE(x) THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(x))
// The following three annotations document the lock requirements for
// functions/methods.
// Document if a function expects certain locks to be held before it is called
#define EXCLUSIVE_LOCKS_REQUIRED(...) \
THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(__VA_ARGS__))
#define SHARED_LOCKS_REQUIRED(...) \
THREAD_ANNOTATION_ATTRIBUTE__(shared_locks_required(__VA_ARGS__))
// Document the locks acquired in the body of the function. These locks
// cannot be held when calling this function (as google3's Mutex locks are
// non-reentrant).
#define LOCKS_EXCLUDED(x) THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(x))
// Document the lock the annotated function returns without acquiring it.
#define LOCK_RETURNED(x) THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
// Document if a class/type is a lockable type (such as the Mutex class).
#define LOCKABLE THREAD_ANNOTATION_ATTRIBUTE__(lockable)
// Document if a class is a scoped lockable type (such as the MutexLock class).
#define SCOPED_LOCKABLE THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
// The following annotations specify lock and unlock primitives.
#define EXCLUSIVE_LOCK_FUNCTION(...) \
THREAD_ANNOTATION_ATTRIBUTE__(exclusive_lock_function(__VA_ARGS__))
#define SHARED_LOCK_FUNCTION(...) \
THREAD_ANNOTATION_ATTRIBUTE__(shared_lock_function(__VA_ARGS__))
#define EXCLUSIVE_TRYLOCK_FUNCTION(...) \
THREAD_ANNOTATION_ATTRIBUTE__(exclusive_trylock_function(__VA_ARGS__))
#define SHARED_TRYLOCK_FUNCTION(...) \
THREAD_ANNOTATION_ATTRIBUTE__(shared_trylock_function(__VA_ARGS__))
#define UNLOCK_FUNCTION(...) \
THREAD_ANNOTATION_ATTRIBUTE__(unlock_function(__VA_ARGS__))
// An escape hatch for thread safety analysis to ignore the annotated function.
#define NO_THREAD_SAFETY_ANALYSIS \
THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
#endif // BASE_THREAD_ANNOTATIONS_H_

View File

@ -0,0 +1,224 @@
# 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.
import("//build/config/android/config.gni")
import("../build/webrtc.gni")
static_library("system_wrappers") {
sources = [
"interface/aligned_array.h",
"interface/aligned_malloc.h",
"interface/atomic32.h",
"interface/clock.h",
"interface/condition_variable_wrapper.h",
"interface/cpu_features_wrapper.h",
"interface/cpu_info.h",
"interface/critical_section_wrapper.h",
"interface/data_log.h",
"interface/data_log_c.h",
"interface/data_log_impl.h",
"interface/event_tracer.h",
"interface/event_wrapper.h",
"interface/field_trial.h",
"interface/file_wrapper.h",
"interface/fix_interlocked_exchange_pointer_win.h",
"interface/logging.h",
"interface/metrics.h",
"interface/ref_count.h",
"interface/rtp_to_ntp.h",
"interface/rw_lock_wrapper.h",
"interface/scoped_vector.h",
"interface/sleep.h",
"interface/sort.h",
"interface/static_instance.h",
"interface/stl_util.h",
"interface/stringize_macros.h",
"interface/thread_wrapper.h",
"interface/tick_util.h",
"interface/timestamp_extrapolator.h",
"interface/trace.h",
"interface/trace_event.h",
"interface/utf_util_win.h",
"source/aligned_malloc.cc",
"source/atomic32_mac.cc",
"source/atomic32_win.cc",
"source/clock.cc",
"source/condition_variable.cc",
"source/condition_variable_event_win.cc",
"source/condition_variable_event_win.h",
"source/condition_variable_native_win.cc",
"source/condition_variable_native_win.h",
"source/condition_variable_posix.cc",
"source/condition_variable_posix.h",
"source/cpu_features.cc",
"source/cpu_info.cc",
"source/critical_section.cc",
"source/critical_section_posix.cc",
"source/critical_section_posix.h",
"source/critical_section_win.cc",
"source/critical_section_win.h",
"source/data_log_c.cc",
"source/event.cc",
"source/event_timer_posix.cc",
"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",
"source/rtp_to_ntp.cc",
"source/rw_lock.cc",
"source/rw_lock_generic.cc",
"source/rw_lock_generic.h",
"source/rw_lock_posix.cc",
"source/rw_lock_posix.h",
"source/rw_lock_win.cc",
"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",
"source/trace_impl.h",
"source/trace_posix.cc",
"source/trace_posix.h",
"source/trace_win.cc",
"source/trace_win.h",
]
configs += [ "..:common_config" ]
public_configs = [ "..:common_inherited_config" ]
if (rtc_enable_data_logging) {
sources += [ "source/data_log.cc" ]
} else {
sources += [ "source/data_log_no_op.cc" ]
}
defines = []
libs = []
deps = [
"..:webrtc_common",
]
if (is_android) {
sources += [
"interface/logcat_trace_context.h",
"source/logcat_trace_context.cc",
]
defines += [
"WEBRTC_THREAD_RR",
# TODO(leozwang): Investigate CLOCK_REALTIME and CLOCK_MONOTONIC
# support on Android. Keep WEBRTC_CLOCK_TYPE_REALTIME for now,
# remove it after I verify that CLOCK_MONOTONIC is fully functional
# with condition and event functions in system_wrappers.
"WEBRTC_CLOCK_TYPE_REALTIME",
]
deps += [ ":cpu_features_android" ]
libs += [ "log" ]
}
if (is_linux) {
defines += [
"WEBRTC_THREAD_RR",
# TODO(andrew): can we select this automatically?
# Define this if the Linux system does not support CLOCK_MONOTONIC.
#"WEBRTC_CLOCK_TYPE_REALTIME",
]
libs += [ "rt" ]
}
if (!is_mac && !is_ios) {
sources += [ "source/atomic32_posix.cc" ]
}
if (is_ios || is_mac) {
defines += [
"WEBRTC_THREAD_RR",
"WEBRTC_CLOCK_TYPE_REALTIME",
]
}
if (is_ios) {
sources += [ "source/atomic32_mac.cc" ]
}
if (is_win) {
libs += [ "winmm.lib" ]
cflags = [
"/wd4267", # size_t to int truncation.
"/wd4334", # Ignore warning on shift operator promotion.
]
}
deps += [ "../base:rtc_base_approved" ]
}
source_set("field_trial_default") {
sources = [
"interface/field_trial_default.h",
"source/field_trial_default.cc",
]
configs += [ "..:common_config" ]
public_configs = [ "..:common_inherited_config" ]
deps = [
":system_wrappers",
]
}
source_set("metrics_default") {
sources = [
"source/metrics_default.cc",
]
configs += [ "..:common_config" ]
public_configs = [ "..:common_inherited_config" ]
deps = [
":system_wrappers",
]
}
source_set("system_wrappers_default") {
configs += [ "..:common_config" ]
public_configs = [ "..:common_inherited_config" ]
deps = [
":field_trial_default",
":metrics_default",
]
}
if (is_android) {
source_set("cpu_features_android") {
sources = [
"source/cpu_features_android.c",
]
configs += [ "..:common_config" ]
public_configs = [ "..:common_inherited_config" ]
deps = [
"//third_party/android_tools:cpu_features",
]
}
}

View File

@ -10,15 +10,13 @@
// Parts of this file derived from Chromium's base/cpu.cc.
#include "cpu_features_wrapper.h"
#include "webrtc/system_wrappers/interface/cpu_features_wrapper.h"
#include "typedefs.h"
#if defined(WEBRTC_ARCH_X86_FAMILY)
#if defined(_MSC_VER)
#if defined(WEBRTC_ARCH_X86_FAMILY) && defined(_MSC_VER)
#include <intrin.h>
#endif
#endif
#include "webrtc/typedefs.h"
// No CPU feature is available => straight C path.
int GetCPUInfoNoASM(CPUFeature feature) {
@ -31,7 +29,7 @@ int GetCPUInfoNoASM(CPUFeature feature) {
// Intrinsic for "cpuid".
#if defined(__pic__) && defined(__i386__)
static inline void __cpuid(int cpu_info[4], int info_type) {
__asm__ volatile (
__asm__ volatile(
"mov %%ebx, %%edi\n"
"cpuid\n"
"xchg %%edi, %%ebx\n"
@ -40,7 +38,7 @@ static inline void __cpuid(int cpu_info[4], int info_type) {
}
#else
static inline void __cpuid(int cpu_info[4], int info_type) {
__asm__ volatile (
__asm__ volatile(
"cpuid\n"
: "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
: "a"(info_type));

View File

@ -9,19 +9,20 @@
*/
#if defined(_WIN32)
#include <windows.h>
#include "critical_section_windows.h"
#include <windows.h>
#include "webrtc/system_wrappers/source/critical_section_win.h"
#else
#include "critical_section_posix.h"
#include "webrtc/system_wrappers/source/critical_section_posix.h"
#endif
namespace webrtc {
CriticalSectionWrapper* CriticalSectionWrapper::CreateCriticalSection()
{
CriticalSectionWrapper* CriticalSectionWrapper::CreateCriticalSection() {
#ifdef _WIN32
return new CriticalSectionWindows();
return new CriticalSectionWindows();
#else
return new CriticalSectionPosix();
return new CriticalSectionPosix();
#endif
}
} // namespace webrtc
} // namespace webrtc

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
* 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
@ -8,31 +8,34 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "critical_section_posix.h"
// General note: return values for the various pthread synchronization APIs
// are explicitly ignored here. In Chromium, the same thing is done for release.
// However, in debugging, failure in these APIs are logged.
// TODO(henrike): add logging when pthread synchronization APIs are failing.
#include "webrtc/system_wrappers/source/critical_section_posix.h"
namespace webrtc {
CriticalSectionPosix::CriticalSectionPosix()
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&_mutex, &attr);
CriticalSectionPosix::CriticalSectionPosix() {
pthread_mutexattr_t attr;
(void) pthread_mutexattr_init(&attr);
(void) pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
(void) pthread_mutex_init(&mutex_, &attr);
}
CriticalSectionPosix::~CriticalSectionPosix()
{
pthread_mutex_destroy(&_mutex);
CriticalSectionPosix::~CriticalSectionPosix() {
(void) pthread_mutex_destroy(&mutex_);
}
void
CriticalSectionPosix::Enter()
{
pthread_mutex_lock(&_mutex);
CriticalSectionPosix::Enter() {
(void) pthread_mutex_lock(&mutex_);
}
void
CriticalSectionPosix::Leave()
{
pthread_mutex_unlock(&_mutex);
CriticalSectionPosix::Leave() {
(void) pthread_mutex_unlock(&mutex_);
}
} // namespace webrtc
} // namespace webrtc

View File

@ -11,25 +11,26 @@
#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_CRITICAL_SECTION_POSIX_H_
#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_CRITICAL_SECTION_POSIX_H_
#include "critical_section_wrapper.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include <pthread.h>
namespace webrtc {
class CriticalSectionPosix : public CriticalSectionWrapper
{
public:
CriticalSectionPosix();
virtual ~CriticalSectionPosix();
class CriticalSectionPosix : public CriticalSectionWrapper {
public:
CriticalSectionPosix();
virtual void Enter();
virtual void Leave();
~CriticalSectionPosix() override;
private:
pthread_mutex_t _mutex;
friend class ConditionVariablePosix;
void Enter() override;
void Leave() override;
private:
pthread_mutex_t mutex_;
friend class ConditionVariablePosix;
};
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_CRITICAL_SECTION_POSIX_H_
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_CRITICAL_SECTION_POSIX_H_

View File

@ -8,28 +8,26 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "critical_section_windows.h"
#include "webrtc/system_wrappers/source/critical_section_win.h"
namespace webrtc {
CriticalSectionWindows::CriticalSectionWindows()
{
InitializeCriticalSection(&crit);
CriticalSectionWindows::CriticalSectionWindows() {
InitializeCriticalSection(&crit);
}
CriticalSectionWindows::~CriticalSectionWindows()
{
DeleteCriticalSection(&crit);
CriticalSectionWindows::~CriticalSectionWindows() {
DeleteCriticalSection(&crit);
}
void
CriticalSectionWindows::Enter()
{
EnterCriticalSection(&crit);
CriticalSectionWindows::Enter() {
EnterCriticalSection(&crit);
}
void
CriticalSectionWindows::Leave()
{
LeaveCriticalSection(&crit);
CriticalSectionWindows::Leave() {
LeaveCriticalSection(&crit);
}
} // namespace webrtc
} // namespace webrtc

View File

@ -0,0 +1,38 @@
/*
* 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_CRITICAL_SECTION_WIN_H_
#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_CRITICAL_SECTION_WIN_H_
#include <windows.h>
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "webrtc/typedefs.h"
namespace webrtc {
class CriticalSectionWindows : public CriticalSectionWrapper {
public:
CriticalSectionWindows();
virtual ~CriticalSectionWindows();
virtual void Enter();
virtual void Leave();
private:
CRITICAL_SECTION crit;
friend class ConditionVariableEventWin;
friend class ConditionVariableNativeWin;
};
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_CRITICAL_SECTION_WIN_H_

View File

@ -1,36 +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_CRITICAL_SECTION_WINDOWS_H_
#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_CRITICAL_SECTION_WINDOWS_H_
#include "typedefs.h"
#include "critical_section_wrapper.h"
#include <windows.h>
namespace webrtc {
class CriticalSectionWindows : public CriticalSectionWrapper
{
public:
CriticalSectionWindows();
virtual ~CriticalSectionWindows();
virtual void Enter();
virtual void Leave();
private:
CRITICAL_SECTION crit;
friend class ConditionVariableWindows;
};
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_CRITICAL_SECTION_WINDOWS_H_

View File

@ -1,169 +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.
# TODO: Rename files to use *_linux.cpp etc. names, to automatically include relevant files. Remove conditions section.
{
'includes': [
'../../common_settings.gypi', # Common settings
],
'targets': [
{
'target_name': 'system_wrappers',
'type': '<(library)',
'include_dirs': [
'spreadsortlib',
'../interface',
],
'direct_dependent_settings': {
'include_dirs': [
'../interface',
],
},
'sources': [
'../interface/aligned_malloc.h',
'../interface/atomic32_wrapper.h',
'../interface/condition_variable_wrapper.h',
'../interface/cpu_wrapper.h',
'../interface/cpu_features_wrapper.h',
'../interface/critical_section_wrapper.h',
'../interface/data_log.h',
'../interface/data_log_c.h',
'../interface/data_log_impl.h',
'../interface/event_wrapper.h',
'../interface/file_wrapper.h',
'../interface/fix_interlocked_exchange_pointer_windows.h',
'../interface/list_wrapper.h',
'../interface/map_wrapper.h',
'../interface/ref_count.h',
'../interface/rw_lock_wrapper.h',
'../interface/scoped_ptr.h',
'../interface/scoped_refptr.h',
'../interface/sort.h',
'../interface/thread_wrapper.h',
'../interface/tick_util.h',
'../interface/trace.h',
'aligned_malloc.cc',
'atomic32.cc',
'atomic32_linux.h',
'atomic32_mac.h',
'atomic32_windows.h',
'condition_variable.cc',
'condition_variable_posix.h',
'condition_variable_windows.h',
'cpu.cc',
'cpu_linux.h',
'cpu_mac.h',
'cpu_windows.h',
'cpu_features.cc',
'critical_section.cc',
'critical_section_posix.h',
'critical_section_windows.h',
'data_log_c.cc',
'event.cc',
'event_posix.h',
'event_windows.h',
'file_impl.cc',
'file_impl.h',
'list_no_stl.cc',
'map.cc',
'rw_lock.cc',
'rw_lock_posix.h',
'rw_lock_windows.h',
'sort.cc',
'thread.cc',
'thread_posix.h',
'thread_windows.h',
'thread_windows_set_name.h',
'trace_impl.cc',
'trace_impl.h',
'trace_posix.h',
'trace_windows.h',
],
'conditions': [
['os_posix==1', {
'sources': [
'condition_variable_posix.cc',
'critical_section_posix.cc',
'event_posix.cc',
'rw_lock_posix.cc',
'thread_posix.cc',
'trace_posix.cc',
],
}],
['enable_data_logging==1', {
'sources': [
'data_log.cc',
],
},{
'sources': [
'data_log_dummy.cc',
],
},],
['OS=="linux"', {
'sources': [
'cpu_linux.cc',
],
'link_settings': {
'libraries': [
'-lrt',
],
},
}],
['OS=="mac"', {
'sources': [
'cpu_mac.cc',
],
'link_settings': {
'libraries': [
'$(SDKROOT)/System/Library/Frameworks/ApplicationServices.framework',
],
},
}],
['OS=="win"', {
'sources': [
'condition_variable_windows.cc',
'cpu_windows.cc',
'critical_section_windows.cc',
'event_windows.cc',
'rw_lock_windows.cc',
'thread_windows.cc',
'trace_windows.cc',
],
'link_settings': {
'libraries': [
'-lwinmm.lib',
],
},
}],
] # conditions
},
], # targets
'conditions': [
['build_with_chromium==0', {
'targets': [
{
'target_name': 'system_wrappersTest',
'type': 'executable',
'dependencies': [
'system_wrappers'
],
'sources': [
'../test/Test.cpp',
],
},
], # targets
}], # build_with_chromium
], # conditions
}
# Local Variables:
# tab-width:2
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=2 shiftwidth=2: