diff --git a/rtc_base/event_tracer_unittest.cc b/rtc_base/event_tracer_unittest.cc index 6e3075fe96..25b300b271 100644 --- a/rtc_base/event_tracer_unittest.cc +++ b/rtc_base/event_tracer_unittest.cc @@ -11,7 +11,6 @@ #include "rtc_base/event_tracer.h" #include "rtc_base/trace_event.h" -#include "system_wrappers/include/static_instance.h" #include "test/gtest.h" namespace { diff --git a/system_wrappers/BUILD.gn b/system_wrappers/BUILD.gn index 30ebc4742b..965f144aef 100644 --- a/system_wrappers/BUILD.gn +++ b/system_wrappers/BUILD.gn @@ -21,12 +21,10 @@ rtc_static_library("system_wrappers") { "include/cpu_info.h", "include/event_wrapper.h", "include/file_wrapper.h", - "include/fix_interlocked_exchange_pointer_win.h", "include/ntp_time.h", "include/rtp_to_ntp_estimator.h", "include/rw_lock_wrapper.h", "include/sleep.h", - "include/static_instance.h", "include/timestamp_extrapolator.h", "source/aligned_malloc.cc", "source/atomic32_win.cc", diff --git a/system_wrappers/include/fix_interlocked_exchange_pointer_win.h b/system_wrappers/include/fix_interlocked_exchange_pointer_win.h deleted file mode 100644 index a83fb4a4ad..0000000000 --- a/system_wrappers/include/fix_interlocked_exchange_pointer_win.h +++ /dev/null @@ -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 - -// 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(static_cast(InterlockedExchange( - reinterpret_cast(target), - static_cast(reinterpret_cast(value))))); -} -#endif // #ifdef InterlockedExchangePointer - -#endif // #if !defined(_WIN64) && defined(_Wp64) - -#endif // SYSTEM_WRAPPERS_SOURCE_FIX_INTERLOCKED_EXCHANGE_POINTER_WINDOWS_H_ diff --git a/system_wrappers/include/static_instance.h b/system_wrappers/include/static_instance.h deleted file mode 100644 index f773d5bc2a..0000000000 --- a/system_wrappers/include/static_instance.h +++ /dev/null @@ -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 - -#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 -// 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(&instance), - new_instance); - } else { - InterlockedDecrement(&instance_count); - if (new_instance) { - delete static_cast(new_instance); - } - } - } else if (state == kDestroy) { - T* old_value = static_cast(InterlockedExchangePointer( - reinterpret_cast(&instance), NULL)); - if (old_value) { - delete static_cast(old_value); - } - return NULL; - } -#endif // #ifndef _WIN32 - return instance; -} - -} // namspace webrtc - -#endif // SYSTEM_WRAPPERS_INCLUDE_STATIC_INSTANCE_H_