Commit 5ae7a5d6 authored by Arun Raghavan's avatar Arun Raghavan
Browse files

Update system_wrappers

Corresponds to upstream commit 524e9b043e7e86fd72353b987c9d5f6a1ebf83e1
parent c4fb4e38
//
// 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_
# 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",
]
}
}
......@@ -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));
......
......@@ -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
/*
* 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
......@@ -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_
......@@ -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
......@@ -8,29 +8,31 @@
* 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_
#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_CRITICAL_SECTION_WIN_H_
#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_CRITICAL_SECTION_WIN_H_
#include "typedefs.h"
#include "critical_section_wrapper.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();
class CriticalSectionWindows : public CriticalSectionWrapper {
public:
CriticalSectionWindows();
virtual void Enter();
virtual void Leave();
virtual ~CriticalSectionWindows();
private:
CRITICAL_SECTION crit;
virtual void Enter();
virtual void Leave();
friend class ConditionVariableWindows;
private:
CRITICAL_SECTION crit;
friend class ConditionVariableEventWin;
friend class ConditionVariableNativeWin;
};
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_CRITICAL_SECTION_WINDOWS_H_
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_CRITICAL_SECTION_WIN_H_
# 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',
<