aboutsummaryrefslogtreecommitdiff
path: root/src/system_wrappers/interface
diff options
context:
space:
mode:
Diffstat (limited to 'src/system_wrappers/interface')
-rw-r--r--src/system_wrappers/interface/atomic32.h65
-rw-r--r--src/system_wrappers/interface/atomic32_wrapper.h55
-rw-r--r--src/system_wrappers/interface/compile_assert.h21
-rw-r--r--src/system_wrappers/interface/fix_interlocked_exchange_pointer_win.h35
-rw-r--r--src/system_wrappers/interface/ref_count.h6
-rw-r--r--src/system_wrappers/interface/sleep.h24
-rw-r--r--src/system_wrappers/interface/static_instance.h8
-rw-r--r--src/system_wrappers/interface/thread_wrapper.h17
-rw-r--r--src/system_wrappers/interface/tick_util.h33
-rw-r--r--src/system_wrappers/interface/trace.h7
10 files changed, 192 insertions, 79 deletions
diff --git a/src/system_wrappers/interface/atomic32.h b/src/system_wrappers/interface/atomic32.h
new file mode 100644
index 0000000000..e2b12589d7
--- /dev/null
+++ b/src/system_wrappers/interface/atomic32.h
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+
+// Atomic, system independent 32-bit integer. Unless you know what you're
+// doing, use locks instead! :-)
+//
+// Note: uses full memory barriers.
+// Note: assumes 32-bit (or higher) system
+#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ATOMIC32_H_
+#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ATOMIC32_H_
+
+#include <cstddef>
+
+#include "common_types.h"
+#include "constructor_magic.h"
+
+namespace webrtc {
+
+// 32 bit atomic variable. Note that this class relies on the compiler to
+// align the 32 bit value correctly (on a 32 bit boundary), so as long as you're
+// not doing things like reinterpret_cast over some custom allocated memory
+// without being careful with alignment, you should be fine.
+class Atomic32
+{
+public:
+ Atomic32(WebRtc_Word32 initialValue = 0);
+ ~Atomic32();
+
+ // Prefix operator!
+ WebRtc_Word32 operator++();
+ WebRtc_Word32 operator--();
+
+ WebRtc_Word32 operator+=(WebRtc_Word32 value);
+ WebRtc_Word32 operator-=(WebRtc_Word32 value);
+
+ // Sets the value atomically to newValue if the value equals compare value.
+ // The function returns true if the exchange happened.
+ bool CompareExchange(WebRtc_Word32 newValue, WebRtc_Word32 compareValue);
+ WebRtc_Word32 Value() const;
+
+private:
+ // Disable the + and - operator since it's unclear what these operations
+ // should do.
+ Atomic32 operator+(const Atomic32& other);
+ Atomic32 operator-(const Atomic32& other);
+
+ // Checks if |_value| is 32bit aligned.
+ inline bool Is32bitAligned() const {
+ return (reinterpret_cast<ptrdiff_t>(&_value) & 3) == 0;
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(Atomic32);
+
+ WebRtc_Word32 _value;
+};
+} // namespace webrtc
+
+#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ATOMIC32_H_
diff --git a/src/system_wrappers/interface/atomic32_wrapper.h b/src/system_wrappers/interface/atomic32_wrapper.h
deleted file mode 100644
index 40862fb492..0000000000
--- a/src/system_wrappers/interface/atomic32_wrapper.h
+++ /dev/null
@@ -1,55 +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.
- */
-
-// Atomic system independant 32-bit integer.
-// Note: uses full memory barriers.
-// Note: assumes 32-bit (or higher) system
-#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ATOMIC32_WRAPPER_H_
-#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ATOMIC32_WRAPPER_H_
-
-#include "common_types.h"
-
-namespace webrtc {
-class Atomic32Impl;
-class Atomic32Wrapper
-{
-public:
- Atomic32Wrapper(WebRtc_Word32 initialValue = 0);
- ~Atomic32Wrapper();
-
- // Prefix operator!
- WebRtc_Word32 operator++();
- WebRtc_Word32 operator--();
-
- Atomic32Wrapper& operator=(const Atomic32Wrapper& rhs);
- Atomic32Wrapper& operator=(WebRtc_Word32 rhs);
-
- WebRtc_Word32 operator+=(WebRtc_Word32 rhs);
- WebRtc_Word32 operator-=(WebRtc_Word32 rhs);
-
- // Sets the value atomically to newValue if the value equals compare value.
- // The function returns true if the exchange happened.
- bool CompareExchange(WebRtc_Word32 newValue, WebRtc_Word32 compareValue);
- WebRtc_Word32 Value() const;
-private:
- // Disable the + and - operator since it's unclear what these operations
- // should do.
- Atomic32Wrapper operator+(const Atomic32Wrapper& rhs);
- Atomic32Wrapper operator-(const Atomic32Wrapper& rhs);
-
- WebRtc_Word32& operator++(int);
- WebRtc_Word32& operator--(int);
-
- // Cheshire cat to hide the implementation (faster than
- // using virtual functions)
- Atomic32Impl& _impl;
-};
-} // namespace webrtc
-#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ATOMIC32_WRAPPER_H_
diff --git a/src/system_wrappers/interface/compile_assert.h b/src/system_wrappers/interface/compile_assert.h
new file mode 100644
index 0000000000..4feda86c3a
--- /dev/null
+++ b/src/system_wrappers/interface/compile_assert.h
@@ -0,0 +1,21 @@
+/*
+ * 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_INTERFACE_COMPILE_ASSERT_H_
+#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_
+
+/* Use this macro to verify at compile time that certain restrictions are met.
+ * The argument is the boolean expression to evaluate.
+ * Example:
+ * COMPILE_ASSERT(sizeof(foo) < 128);
+*/
+#define COMPILE_ASSERT(expression) switch(0){case 0: case expression:;}
+
+#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_
diff --git a/src/system_wrappers/interface/fix_interlocked_exchange_pointer_win.h b/src/system_wrappers/interface/fix_interlocked_exchange_pointer_win.h
new file mode 100644
index 0000000000..d85c724729
--- /dev/null
+++ b/src/system_wrappers/interface/fix_interlocked_exchange_pointer_win.h
@@ -0,0 +1,35 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file under third_party_mods/chromium directory of
+// source tree or at
+// http://src.chromium.org/viewvc/chrome/trunk/src/LICENSE
+
+// 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 WEBRTC_SYSTEM_WRAPPERS_SOURCE_FIX_INTERLOCKED_EXCHANGE_POINTER_WINDOWS_H_
+#define WEBRTC_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 // WEBRTC_SYSTEM_WRAPPERS_SOURCE_FIX_INTERLOCKED_EXCHANGE_POINTER_WINDOWS_H_
diff --git a/src/system_wrappers/interface/ref_count.h b/src/system_wrappers/interface/ref_count.h
index f90b0b3609..5112bd9037 100644
--- a/src/system_wrappers/interface/ref_count.h
+++ b/src/system_wrappers/interface/ref_count.h
@@ -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
@@ -11,7 +11,7 @@
#ifndef SYSTEM_WRAPPERS_INTERFACE_REF_COUNT_H_
#define SYSTEM_WRAPPERS_INTERFACE_REF_COUNT_H_
-#include "system_wrappers/interface/atomic32_wrapper.h"
+#include "system_wrappers/interface/atomic32.h"
namespace webrtc {
@@ -74,7 +74,7 @@ class RefCountImpl : public T {
}
protected:
- Atomic32Wrapper ref_count_;
+ Atomic32 ref_count_;
};
} // namespace webrtc
diff --git a/src/system_wrappers/interface/sleep.h b/src/system_wrappers/interface/sleep.h
new file mode 100644
index 0000000000..c0205bf085
--- /dev/null
+++ b/src/system_wrappers/interface/sleep.h
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+// An OS-independent sleep function.
+
+#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_SLEEP_H_
+#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_SLEEP_H_
+
+namespace webrtc {
+
+// This function sleeps for the specified number of milliseconds.
+// It may return early if the thread is woken by some other event,
+// such as the delivery of a signal on Unix.
+void SleepMs(int msecs);
+
+} // namespace webrtc
+
+#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_SLEEP_H_
diff --git a/src/system_wrappers/interface/static_instance.h b/src/system_wrappers/interface/static_instance.h
index 8fe91cc3e4..b670f969c9 100644
--- a/src/system_wrappers/interface/static_instance.h
+++ b/src/system_wrappers/interface/static_instance.h
@@ -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
@@ -128,10 +128,8 @@ static T* GetStaticInstance(CountOperation count_operation) {
// local copy.
T* new_instance = T::CreateInstance();
if (1 == InterlockedIncrement(&instance_count)) {
- T* old_value = static_cast<T*> (InterlockedExchangePointer(
- reinterpret_cast<void* volatile*>(&instance), new_instance));
- assert(old_value == NULL);
- assert(instance);
+ InterlockedExchangePointer(reinterpret_cast<void* volatile*>(&instance),
+ new_instance);
} else {
InterlockedDecrement(&instance_count);
if (new_instance) {
diff --git a/src/system_wrappers/interface/thread_wrapper.h b/src/system_wrappers/interface/thread_wrapper.h
index 72a06e8bdd..030ac8a6f7 100644
--- a/src/system_wrappers/interface/thread_wrapper.h
+++ b/src/system_wrappers/interface/thread_wrapper.h
@@ -16,6 +16,9 @@
#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_THREAD_WRAPPER_H_
#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_THREAD_WRAPPER_H_
+#include "common_types.h"
+#include "typedefs.h"
+
namespace webrtc {
// Object that will be passed by the spawned thread when it enters the callback
// function.
@@ -51,9 +54,12 @@ public:
// threadName NULL terminated thread name, will be visable in the Windows
// debugger.
static ThreadWrapper* CreateThread(ThreadRunFunction func = 0,
- ThreadObj obj= 0,
- ThreadPriority prio = kNormalPriority,
- const char* threadName = 0);
+ ThreadObj obj= 0,
+ ThreadPriority prio = kNormalPriority,
+ const char* threadName = 0);
+
+ // Get the current thread's kernel thread ID.
+ static uint32_t GetThreadId();
// Non blocking termination of the spawned thread. Note that it is not safe
// to delete this class until the spawned thread has been reclaimed.
@@ -69,8 +75,9 @@ public:
// should be lower than (number of CPUs - 1). amountOfProcessors should be
// equal to the number of processors listed in processorNumbers
virtual bool SetAffinity(const int* /*processorNumbers*/,
- const unsigned int /*amountOfProcessors*/)
- {return false;}
+ const unsigned int /*amountOfProcessors*/) {
+ return false;
+ }
// 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.
diff --git a/src/system_wrappers/interface/tick_util.h b/src/system_wrappers/interface/tick_util.h
index e78e53d2e1..0cd85d0050 100644
--- a/src/system_wrappers/interface/tick_util.h
+++ b/src/system_wrappers/interface/tick_util.h
@@ -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
@@ -19,6 +19,9 @@
#include <mmsystem.h>
#elif WEBRTC_LINUX
#include <ctime>
+#elif WEBRTC_MAC
+#include <mach/mach_time.h>
+#include <string.h>
#else
#include <sys/time.h>
#include <time.h>
@@ -133,6 +136,7 @@ inline TickTime TickTime::Now()
{
TickTime result;
#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
@@ -164,12 +168,27 @@ inline TickTime TickTime::Now()
#endif
#elif defined(WEBRTC_LINUX)
struct timespec ts;
+ // TODO(wu): Remove CLOCK_REALTIME implementation.
#ifdef WEBRTC_CLOCK_TYPE_REALTIME
clock_gettime(CLOCK_REALTIME, &ts);
#else
clock_gettime(CLOCK_MONOTONIC, &ts);
#endif
result._ticks = 1000000000LL * static_cast<WebRtc_Word64>(ts.tv_sec) + static_cast<WebRtc_Word64>(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 CHECK similar to chrome for all the platforms.
+ // Then replace this with a CHECK(retval == KERN_SUCCESS);
+ asm("int3");
+ }
+ }
+ // Use timebase to convert absolute time tick units into nanoseconds.
+ result._ticks = mach_absolute_time() * timebase.numer / timebase.denom;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
@@ -189,7 +208,7 @@ inline WebRtc_Word64 TickTime::MillisecondTimestamp()
#else
return now._ticks;
#endif
-#elif WEBRTC_LINUX
+#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
return now._ticks / 1000000LL;
#else
return now._ticks / 1000LL;
@@ -208,7 +227,7 @@ inline WebRtc_Word64 TickTime::MicrosecondTimestamp()
#else
return now._ticks *1000LL;
#endif
-#elif WEBRTC_LINUX
+#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
return now._ticks / 1000LL;
#else
return now._ticks;
@@ -230,7 +249,7 @@ inline WebRtc_Word64 TickTime::MillisecondsToTicks(const WebRtc_Word64 ms)
#else
return ms;
#endif
-#elif WEBRTC_LINUX
+#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
return ms * 1000000LL;
#else
return ms * 1000LL;
@@ -247,7 +266,7 @@ inline WebRtc_Word64 TickTime::TicksToMilliseconds(const WebRtc_Word64 ticks)
#else
return ticks;
#endif
-#elif WEBRTC_LINUX
+#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
return ticks / 1000000LL;
#else
return ticks / 1000LL;
@@ -280,7 +299,7 @@ inline WebRtc_Word64 TickInterval::Milliseconds() const
// _interval is in ms
return _interval;
#endif
-#elif WEBRTC_LINUX
+#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
// _interval is in ns
return _interval / 1000000;
#else
@@ -300,7 +319,7 @@ inline WebRtc_Word64 TickInterval::Microseconds() const
// _interval is in ms
return _interval *1000LL;
#endif
-#elif WEBRTC_LINUX
+#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
// _interval is in ns
return _interval / 1000;
#else
diff --git a/src/system_wrappers/interface/trace.h b/src/system_wrappers/interface/trace.h
index 8330f7c4e1..f88d23f8a7 100644
--- a/src/system_wrappers/interface/trace.h
+++ b/src/system_wrappers/interface/trace.h
@@ -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
@@ -45,11 +45,11 @@ public:
// Sets the file name. If addFileCounter is false the same file will be
// reused when it fills up. If it's true a new file with incremented name
// will be used.
- static WebRtc_Word32 SetTraceFile(const WebRtc_Word8* fileName,
+ static WebRtc_Word32 SetTraceFile(const char* fileName,
const bool addFileCounter = false);
// Returns the name of the file that the trace is currently writing to.
- static WebRtc_Word32 TraceFile(WebRtc_Word8 fileName[1024]);
+ static WebRtc_Word32 TraceFile(char fileName[1024]);
// Registers callback to receive trace messages. TODO (hellner)
// why not use OutStream instead? Why is TraceCallback not defined in this
@@ -70,7 +70,6 @@ public:
const TraceModule module,
const WebRtc_Word32 id,
const char* msg, ...);
-
};
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_TRACE_H_