Delete static_instance.h and fix_interlocked_exchange_pointer_win.h
Unused since the deletion of the WEBRTC_TRACE facility. Bug: webrtc:5118 Change-Id: Iad03a90a05c734ae867eb8a0265f65ae008486a4 Reviewed-on: https://webrtc-review.googlesource.com/6321 Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org> Reviewed-by: Henrik Grunell <henrikg@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20166}
This commit is contained in:
parent
ca95748c73
commit
779d3657ef
@ -11,7 +11,6 @@
|
|||||||
#include "rtc_base/event_tracer.h"
|
#include "rtc_base/event_tracer.h"
|
||||||
|
|
||||||
#include "rtc_base/trace_event.h"
|
#include "rtc_base/trace_event.h"
|
||||||
#include "system_wrappers/include/static_instance.h"
|
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|||||||
@ -21,12 +21,10 @@ rtc_static_library("system_wrappers") {
|
|||||||
"include/cpu_info.h",
|
"include/cpu_info.h",
|
||||||
"include/event_wrapper.h",
|
"include/event_wrapper.h",
|
||||||
"include/file_wrapper.h",
|
"include/file_wrapper.h",
|
||||||
"include/fix_interlocked_exchange_pointer_win.h",
|
|
||||||
"include/ntp_time.h",
|
"include/ntp_time.h",
|
||||||
"include/rtp_to_ntp_estimator.h",
|
"include/rtp_to_ntp_estimator.h",
|
||||||
"include/rw_lock_wrapper.h",
|
"include/rw_lock_wrapper.h",
|
||||||
"include/sleep.h",
|
"include/sleep.h",
|
||||||
"include/static_instance.h",
|
|
||||||
"include/timestamp_extrapolator.h",
|
"include/timestamp_extrapolator.h",
|
||||||
"source/aligned_malloc.cc",
|
"source/aligned_malloc.cc",
|
||||||
"source/atomic32_win.cc",
|
"source/atomic32_win.cc",
|
||||||
|
|||||||
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Various inline functions and macros to fix compilation of 32 bit target
|
|
||||||
// on MSVC with /Wp64 flag enabled.
|
|
||||||
|
|
||||||
// The original code can be found here:
|
|
||||||
// http://src.chromium.org/svn/trunk/src/base/fix_wp64.h
|
|
||||||
|
|
||||||
#ifndef SYSTEM_WRAPPERS_SOURCE_FIX_INTERLOCKED_EXCHANGE_POINTER_WINDOWS_H_
|
|
||||||
#define SYSTEM_WRAPPERS_SOURCE_FIX_INTERLOCKED_EXCHANGE_POINTER_WINDOWS_H_
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
// Platform SDK fixes when building with /Wp64 for a 32 bits target.
|
|
||||||
#if !defined(_WIN64) && defined(_Wp64)
|
|
||||||
|
|
||||||
#ifdef InterlockedExchangePointer
|
|
||||||
#undef InterlockedExchangePointer
|
|
||||||
// The problem is that the macro provided for InterlockedExchangePointer() is
|
|
||||||
// doing a (LONG) C-style cast that triggers invariably the warning C4312 when
|
|
||||||
// building on 32 bits.
|
|
||||||
inline void* InterlockedExchangePointer(void* volatile* target, void* value) {
|
|
||||||
return reinterpret_cast<void*>(static_cast<LONG_PTR>(InterlockedExchange(
|
|
||||||
reinterpret_cast<volatile LONG*>(target),
|
|
||||||
static_cast<LONG>(reinterpret_cast<LONG_PTR>(value)))));
|
|
||||||
}
|
|
||||||
#endif // #ifdef InterlockedExchangePointer
|
|
||||||
|
|
||||||
#endif // #if !defined(_WIN64) && defined(_Wp64)
|
|
||||||
|
|
||||||
#endif // SYSTEM_WRAPPERS_SOURCE_FIX_INTERLOCKED_EXCHANGE_POINTER_WINDOWS_H_
|
|
||||||
@ -1,147 +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 SYSTEM_WRAPPERS_INCLUDE_STATIC_INSTANCE_H_
|
|
||||||
#define SYSTEM_WRAPPERS_INCLUDE_STATIC_INSTANCE_H_
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include "rtc_base/criticalsection.h"
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include "system_wrappers/include/fix_interlocked_exchange_pointer_win.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace webrtc {
|
|
||||||
|
|
||||||
enum CountOperation {
|
|
||||||
kRelease,
|
|
||||||
kAddRef,
|
|
||||||
kAddRefNoCreate
|
|
||||||
};
|
|
||||||
enum CreateOperation {
|
|
||||||
kInstanceExists,
|
|
||||||
kCreate,
|
|
||||||
kDestroy
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
// Construct On First Use idiom. Avoids
|
|
||||||
// "static initialization order fiasco".
|
|
||||||
static T* GetStaticInstance(CountOperation count_operation) {
|
|
||||||
// TODO (hellner): use atomic wrapper instead.
|
|
||||||
static volatile long instance_count = 0;
|
|
||||||
static T* volatile instance = NULL;
|
|
||||||
CreateOperation state = kInstanceExists;
|
|
||||||
#ifndef _WIN32
|
|
||||||
static rtc::CriticalSection crit_sect;
|
|
||||||
rtc::CritScope lock(&crit_sect);
|
|
||||||
|
|
||||||
if (count_operation ==
|
|
||||||
kAddRefNoCreate && instance_count == 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (count_operation ==
|
|
||||||
kAddRef ||
|
|
||||||
count_operation == kAddRefNoCreate) {
|
|
||||||
instance_count++;
|
|
||||||
if (instance_count == 1) {
|
|
||||||
state = kCreate;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
instance_count--;
|
|
||||||
if (instance_count == 0) {
|
|
||||||
state = kDestroy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (state == kCreate) {
|
|
||||||
instance = T::CreateInstance();
|
|
||||||
} else if (state == kDestroy) {
|
|
||||||
T* old_instance = instance;
|
|
||||||
instance = NULL;
|
|
||||||
// The state will not change past this point. Release the critical
|
|
||||||
// section while deleting the object in case it would be blocking on
|
|
||||||
// access back to this object. (This is the case for the tracing class
|
|
||||||
// since the thread owned by the tracing class also traces).
|
|
||||||
// TODO(hellner): this is a bit out of place but here goes, de-couple
|
|
||||||
// thread implementation with trace implementation.
|
|
||||||
crit_sect.Leave();
|
|
||||||
if (old_instance) {
|
|
||||||
delete old_instance;
|
|
||||||
}
|
|
||||||
// Re-acquire the lock since the scoped critical section will release
|
|
||||||
// it.
|
|
||||||
crit_sect.Enter();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#else // _WIN32
|
|
||||||
if (count_operation ==
|
|
||||||
kAddRefNoCreate && instance_count == 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (count_operation == kAddRefNoCreate) {
|
|
||||||
if (1 == InterlockedIncrement(&instance_count)) {
|
|
||||||
// The instance has been destroyed by some other thread. Rollback.
|
|
||||||
InterlockedDecrement(&instance_count);
|
|
||||||
assert(false);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
// Sanity to catch corrupt state.
|
|
||||||
if (instance == NULL) {
|
|
||||||
assert(false);
|
|
||||||
InterlockedDecrement(&instance_count);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
} else if (count_operation == kAddRef) {
|
|
||||||
if (instance_count == 0) {
|
|
||||||
state = kCreate;
|
|
||||||
} else {
|
|
||||||
if (1 == InterlockedIncrement(&instance_count)) {
|
|
||||||
// InterlockedDecrement because reference count should not be
|
|
||||||
// updated just yet (that's done when the instance is created).
|
|
||||||
InterlockedDecrement(&instance_count);
|
|
||||||
state = kCreate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
int new_value = InterlockedDecrement(&instance_count);
|
|
||||||
if (new_value == 0) {
|
|
||||||
state = kDestroy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state == kCreate) {
|
|
||||||
// Create instance and let whichever thread finishes first assign its
|
|
||||||
// local copy to the global instance. All other threads reclaim their
|
|
||||||
// local copy.
|
|
||||||
T* new_instance = T::CreateInstance();
|
|
||||||
if (1 == InterlockedIncrement(&instance_count)) {
|
|
||||||
InterlockedExchangePointer(reinterpret_cast<void * volatile*>(&instance),
|
|
||||||
new_instance);
|
|
||||||
} else {
|
|
||||||
InterlockedDecrement(&instance_count);
|
|
||||||
if (new_instance) {
|
|
||||||
delete static_cast<T*>(new_instance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (state == kDestroy) {
|
|
||||||
T* old_value = static_cast<T*>(InterlockedExchangePointer(
|
|
||||||
reinterpret_cast<void * volatile*>(&instance), NULL));
|
|
||||||
if (old_value) {
|
|
||||||
delete static_cast<T*>(old_value);
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif // #ifndef _WIN32
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namspace webrtc
|
|
||||||
|
|
||||||
#endif // SYSTEM_WRAPPERS_INCLUDE_STATIC_INSTANCE_H_
|
|
||||||
Loading…
x
Reference in New Issue
Block a user