summaryrefslogtreecommitdiffstats
path: root/ppapi/utility
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-17 20:37:20 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-17 20:37:20 +0000
commitd89fd35048c164c5bdd0b9d0ae54a88867f04713 (patch)
tree565a384496ca850811ee27eb91c49c16dd43799c /ppapi/utility
parent1e79b936b48990615039bb215bc8e26c595a1304 (diff)
downloadchromium_src-d89fd35048c164c5bdd0b9d0ae54a88867f04713.zip
chromium_src-d89fd35048c164c5bdd0b9d0ae54a88867f04713.tar.gz
chromium_src-d89fd35048c164c5bdd0b9d0ae54a88867f04713.tar.bz2
Fix line endings.
TBR=viettrungluu@chromium.org Review URL: https://chromiumcodereview.appspot.com/10704254 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147085 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/utility')
-rw-r--r--ppapi/utility/completion_callback_factory_thread_traits.h356
-rw-r--r--ppapi/utility/threading/lock.cc98
-rw-r--r--ppapi/utility/threading/lock.h168
3 files changed, 311 insertions, 311 deletions
diff --git a/ppapi/utility/completion_callback_factory_thread_traits.h b/ppapi/utility/completion_callback_factory_thread_traits.h
index 2242b5c..cda3dc0 100644
--- a/ppapi/utility/completion_callback_factory_thread_traits.h
+++ b/ppapi/utility/completion_callback_factory_thread_traits.h
@@ -1,178 +1,178 @@
-// Copyright (c) 2012 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.
-
-#ifndef PPAPI_UTILITY_THREAD_SAFE_THREAD_TRAITS_H_
-#define PPAPI_UTILITY_THREAD_SAFE_THREAD_TRAITS_H_
-
-#include "ppapi/cpp/logging.h"
-#include "ppapi/cpp/module.h"
-#include "ppapi/utility/threading/lock.h"
-
-/// @file
-/// Defines the traits structures for thread-safety of a completion callback
-/// factory. We provide thread-safe and non-thread-safe version. The thread-safe
-/// version is always correct (if you follow the thread usage rules of the
-/// callback factory), but if you know your object will only be used on one
-/// thread, you can uses the non-thread-safe version.
-///
-/// The traits defines three nested classes to perform reference counting,
-/// locks, and scoped locking.
-
-namespace pp {
-
-/// The thread-safe version of thread traits. Using this class as the "traits"
-/// template argument to a completion callback factory will make it "somewhat
-/// thread-friendly." It will allow you to create completion callbacks from
-/// background threads and post them to another thread to run.
-///
-/// Care still must be taken to ensure that the completion callbacks are
-/// executed on the same thread that the factory is destroyed on to avoid a
-/// race on destruction.
-///
-/// Implementation note: this uses a lock instead of atomic add instructions.
-/// The number of platforms we need to support right now makes atomic
-/// operations unwieldy for this case that we don't actually use that often.
-/// As a further optimization, we can add support for this later.
-class ThreadSafeThreadTraits {
- public:
- class RefCount {
- public:
- /// Default constructor. In debug mode, this checks that the object is being
- /// created on the main thread.
- RefCount() : ref_(0) {
- }
-
- /// AddRef() increments the reference counter.
- ///
- /// @return An int32_t with the incremented reference counter.
- int32_t AddRef() {
- AutoLock lock(lock_);
- return ++ref_;
- }
-
- /// Release() decrements the reference counter.
- ///
- /// @return An int32_t with the decremeneted reference counter.
- int32_t Release() {
- AutoLock lock(lock_);
- PP_DCHECK(ref_ > 0);
- return --ref_;
- }
-
- private:
- Lock lock_;
- int32_t ref_;
- };
-
- typedef pp::Lock Lock;
- typedef pp::AutoLock AutoLock;
-};
-
-/// The non-thread-safe version of thread traits. Using this class as the
-/// "traits" template argument to a completion callback factory will make it
-/// not thread-safe but with potential extra performance.
-class NonThreadSafeThreadTraits {
- public:
- /// A simple reference counter that is not thread-safe.
- ///
- /// <strong>Note:</strong> in Debug mode, it checks that it is either called
- /// on the main thread, or always called on another thread.
- class RefCount {
- public:
- /// Default constructor. In debug mode, this checks that the object is being
- /// created on the main thread.
- RefCount() : ref_(0) {
-#ifndef NDEBUG
- is_main_thread_ = Module::Get()->core()->IsMainThread();
-#endif
- }
-
- /// Destructor.
- ~RefCount() {
- PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
- }
-
- /// AddRef() increments the reference counter.
- ///
- /// @return An int32_t with the incremented reference counter.
- int32_t AddRef() {
- PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
- return ++ref_;
- }
-
- /// Release() decrements the reference counter.
- ///
- /// @return An int32_t with the decremeneted reference counter.
- int32_t Release() {
- PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
- return --ref_;
- }
-
- private:
- int32_t ref_;
-#ifndef NDEBUG
- bool is_main_thread_;
-#endif
- };
-
- /// A simple object that acts like a lock but does nothing.
- ///
- /// MStrong>Note:</strong> in Debug mode, it checks that it is either
- /// called on the main thread, or always called on another thread. It also
- /// asserts that the caller does not recursively lock.
- class Lock {
- public:
- Lock() {
-#ifndef NDEBUG
- is_main_thread_ = Module::Get()->core()->IsMainThread();
- lock_held_ = false;
-#endif
- }
-
- ~Lock() {
- PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
- }
-
- /// Acquires the fake "lock". This does nothing except perform checks in
- /// debug mode.
- void Acquire() {
-#ifndef NDEBUG
- PP_DCHECK(!lock_held_);
- lock_held_ = true;
-#endif
- }
-
- /// Releases the fake "lock". This does nothing except perform checks in
- /// debug mode.
- void Release() {
-#ifndef NDEBUG
- PP_DCHECK(lock_held_);
- lock_held_ = false;
-#endif
- }
-
- private:
-#ifndef NDEBUG
- bool is_main_thread_;
- bool lock_held_;
-#endif
- };
-
- class AutoLock {
- public:
- explicit AutoLock(Lock& lock) : lock_(lock) {
- lock_.Acquire();
- }
- ~AutoLock() {
- lock_.Release();
- }
-
- private:
- Lock& lock_;
- };
-};
-
-} // namespace pp
-
-#endif // PPAPI_UTILITY_THREAD_SAFE_THREAD_TRAITS_H_
+// Copyright (c) 2012 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.
+
+#ifndef PPAPI_UTILITY_THREAD_SAFE_THREAD_TRAITS_H_
+#define PPAPI_UTILITY_THREAD_SAFE_THREAD_TRAITS_H_
+
+#include "ppapi/cpp/logging.h"
+#include "ppapi/cpp/module.h"
+#include "ppapi/utility/threading/lock.h"
+
+/// @file
+/// Defines the traits structures for thread-safety of a completion callback
+/// factory. We provide thread-safe and non-thread-safe version. The thread-safe
+/// version is always correct (if you follow the thread usage rules of the
+/// callback factory), but if you know your object will only be used on one
+/// thread, you can uses the non-thread-safe version.
+///
+/// The traits defines three nested classes to perform reference counting,
+/// locks, and scoped locking.
+
+namespace pp {
+
+/// The thread-safe version of thread traits. Using this class as the "traits"
+/// template argument to a completion callback factory will make it "somewhat
+/// thread-friendly." It will allow you to create completion callbacks from
+/// background threads and post them to another thread to run.
+///
+/// Care still must be taken to ensure that the completion callbacks are
+/// executed on the same thread that the factory is destroyed on to avoid a
+/// race on destruction.
+///
+/// Implementation note: this uses a lock instead of atomic add instructions.
+/// The number of platforms we need to support right now makes atomic
+/// operations unwieldy for this case that we don't actually use that often.
+/// As a further optimization, we can add support for this later.
+class ThreadSafeThreadTraits {
+ public:
+ class RefCount {
+ public:
+ /// Default constructor. In debug mode, this checks that the object is being
+ /// created on the main thread.
+ RefCount() : ref_(0) {
+ }
+
+ /// AddRef() increments the reference counter.
+ ///
+ /// @return An int32_t with the incremented reference counter.
+ int32_t AddRef() {
+ AutoLock lock(lock_);
+ return ++ref_;
+ }
+
+ /// Release() decrements the reference counter.
+ ///
+ /// @return An int32_t with the decremeneted reference counter.
+ int32_t Release() {
+ AutoLock lock(lock_);
+ PP_DCHECK(ref_ > 0);
+ return --ref_;
+ }
+
+ private:
+ Lock lock_;
+ int32_t ref_;
+ };
+
+ typedef pp::Lock Lock;
+ typedef pp::AutoLock AutoLock;
+};
+
+/// The non-thread-safe version of thread traits. Using this class as the
+/// "traits" template argument to a completion callback factory will make it
+/// not thread-safe but with potential extra performance.
+class NonThreadSafeThreadTraits {
+ public:
+ /// A simple reference counter that is not thread-safe.
+ ///
+ /// <strong>Note:</strong> in Debug mode, it checks that it is either called
+ /// on the main thread, or always called on another thread.
+ class RefCount {
+ public:
+ /// Default constructor. In debug mode, this checks that the object is being
+ /// created on the main thread.
+ RefCount() : ref_(0) {
+#ifndef NDEBUG
+ is_main_thread_ = Module::Get()->core()->IsMainThread();
+#endif
+ }
+
+ /// Destructor.
+ ~RefCount() {
+ PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
+ }
+
+ /// AddRef() increments the reference counter.
+ ///
+ /// @return An int32_t with the incremented reference counter.
+ int32_t AddRef() {
+ PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
+ return ++ref_;
+ }
+
+ /// Release() decrements the reference counter.
+ ///
+ /// @return An int32_t with the decremeneted reference counter.
+ int32_t Release() {
+ PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
+ return --ref_;
+ }
+
+ private:
+ int32_t ref_;
+#ifndef NDEBUG
+ bool is_main_thread_;
+#endif
+ };
+
+ /// A simple object that acts like a lock but does nothing.
+ ///
+ /// MStrong>Note:</strong> in Debug mode, it checks that it is either
+ /// called on the main thread, or always called on another thread. It also
+ /// asserts that the caller does not recursively lock.
+ class Lock {
+ public:
+ Lock() {
+#ifndef NDEBUG
+ is_main_thread_ = Module::Get()->core()->IsMainThread();
+ lock_held_ = false;
+#endif
+ }
+
+ ~Lock() {
+ PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
+ }
+
+ /// Acquires the fake "lock". This does nothing except perform checks in
+ /// debug mode.
+ void Acquire() {
+#ifndef NDEBUG
+ PP_DCHECK(!lock_held_);
+ lock_held_ = true;
+#endif
+ }
+
+ /// Releases the fake "lock". This does nothing except perform checks in
+ /// debug mode.
+ void Release() {
+#ifndef NDEBUG
+ PP_DCHECK(lock_held_);
+ lock_held_ = false;
+#endif
+ }
+
+ private:
+#ifndef NDEBUG
+ bool is_main_thread_;
+ bool lock_held_;
+#endif
+ };
+
+ class AutoLock {
+ public:
+ explicit AutoLock(Lock& lock) : lock_(lock) {
+ lock_.Acquire();
+ }
+ ~AutoLock() {
+ lock_.Release();
+ }
+
+ private:
+ Lock& lock_;
+ };
+};
+
+} // namespace pp
+
+#endif // PPAPI_UTILITY_THREAD_SAFE_THREAD_TRAITS_H_
diff --git a/ppapi/utility/threading/lock.cc b/ppapi/utility/threading/lock.cc
index 12cbd08..ee4bad7 100644
--- a/ppapi/utility/threading/lock.cc
+++ b/ppapi/utility/threading/lock.cc
@@ -1,49 +1,49 @@
-// Copyright (c) 2012 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.
-
-#include "ppapi/utility/threading/lock.h"
-
-namespace pp {
-
-#ifdef WIN32 // Windows implementation for native plugins.
-
-Lock::Lock() {
- // The second parameter is the spin count; for short-held locks it avoids the
- // contending thread from going to sleep which helps performance greatly.
- ::InitializeCriticalSectionAndSpinCount(&os_lock_, 2000);
-}
-
-Lock::~Lock() {
- ::DeleteCriticalSection(&os_lock_);
-}
-
-void Lock::Acquire() {
- ::EnterCriticalSection(&os_lock_);
-}
-
-void Lock::Release() {
- ::LeaveCriticalSection(&os_lock_);
-}
-
-#else // Posix implementation.
-
-Lock::Lock() {
- pthread_mutex_init(&os_lock_, NULL);
-}
-
-Lock::~Lock() {
- pthread_mutex_destroy(&os_lock_);
-}
-
-void Lock::Acquire() {
- pthread_mutex_lock(&os_lock_);
-}
-
-void Lock::Release() {
- pthread_mutex_unlock(&os_lock_);
-}
-
-#endif
-
-} // namespace pp
+// Copyright (c) 2012 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.
+
+#include "ppapi/utility/threading/lock.h"
+
+namespace pp {
+
+#ifdef WIN32 // Windows implementation for native plugins.
+
+Lock::Lock() {
+ // The second parameter is the spin count; for short-held locks it avoids the
+ // contending thread from going to sleep which helps performance greatly.
+ ::InitializeCriticalSectionAndSpinCount(&os_lock_, 2000);
+}
+
+Lock::~Lock() {
+ ::DeleteCriticalSection(&os_lock_);
+}
+
+void Lock::Acquire() {
+ ::EnterCriticalSection(&os_lock_);
+}
+
+void Lock::Release() {
+ ::LeaveCriticalSection(&os_lock_);
+}
+
+#else // Posix implementation.
+
+Lock::Lock() {
+ pthread_mutex_init(&os_lock_, NULL);
+}
+
+Lock::~Lock() {
+ pthread_mutex_destroy(&os_lock_);
+}
+
+void Lock::Acquire() {
+ pthread_mutex_lock(&os_lock_);
+}
+
+void Lock::Release() {
+ pthread_mutex_unlock(&os_lock_);
+}
+
+#endif
+
+} // namespace pp
diff --git a/ppapi/utility/threading/lock.h b/ppapi/utility/threading/lock.h
index 71a9876..f3bfe4a 100644
--- a/ppapi/utility/threading/lock.h
+++ b/ppapi/utility/threading/lock.h
@@ -1,84 +1,84 @@
-// Copyright (c) 2012 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.
-
-#ifndef PPAPI_UTILITY_THREADING_LOCK_H_
-#define PPAPI_UTILITY_THREADING_LOCK_H_
-
-#ifdef WIN32
-#include <windows.h>
-#else
-#include <pthread.h>
-#endif
-
-namespace pp {
-
-/// A simple wrapper around a platform-specific lock. See also AutoLock.
-class Lock {
- public:
- /// Creates a lock in the "not held" state.
- Lock();
-
- /// Destroys the lock.
- ~Lock();
-
- /// Acquires the lock, blocking if it's already held by a different thread.
- /// The lock must not already be held on the current thread (i.e. recursive
- /// locks are not supported).
- ///
- /// Most callers should consider using an AutoLock instead to automatically
- /// acquire and release the lock.
- void Acquire();
-
- /// Releases the lock. This must be paired with a call to Acquire().
- void Release();
-
- private:
-#if defined(WIN32)
- typedef CRITICAL_SECTION OSLockType;
-#else
- typedef pthread_mutex_t OSLockType;
-#endif
-
- OSLockType os_lock_;
-
- // Copy and assign not supported.
- Lock(const Lock&);
- Lock& operator=(const Lock&);
-};
-
-/// A helper class that scopes holding a lock.
-///
-/// @code
-/// class MyClass {
-/// public:
-/// void DoSomething() {
-/// pp::AutoLock lock(lock_);
-/// ...do something with the lock held...
-/// }
-///
-/// private:
-/// pp::Lock lock_;
-/// };
-/// @endcode
-class AutoLock {
- public:
- explicit AutoLock(Lock& lock) : lock_(lock) {
- lock_.Acquire();
- }
-
- ~AutoLock() {
- lock_.Release();
- }
-
- private:
- Lock& lock_;
-
- // Copy and assign not supported.
- AutoLock(const AutoLock&);
- AutoLock& operator=(const AutoLock&);
-};
-
-} // namespace pp
-
-#endif // PPAPI_UTILITY_THREADING_LOCK_H_
+// Copyright (c) 2012 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.
+
+#ifndef PPAPI_UTILITY_THREADING_LOCK_H_
+#define PPAPI_UTILITY_THREADING_LOCK_H_
+
+#ifdef WIN32
+#include <windows.h>
+#else
+#include <pthread.h>
+#endif
+
+namespace pp {
+
+/// A simple wrapper around a platform-specific lock. See also AutoLock.
+class Lock {
+ public:
+ /// Creates a lock in the "not held" state.
+ Lock();
+
+ /// Destroys the lock.
+ ~Lock();
+
+ /// Acquires the lock, blocking if it's already held by a different thread.
+ /// The lock must not already be held on the current thread (i.e. recursive
+ /// locks are not supported).
+ ///
+ /// Most callers should consider using an AutoLock instead to automatically
+ /// acquire and release the lock.
+ void Acquire();
+
+ /// Releases the lock. This must be paired with a call to Acquire().
+ void Release();
+
+ private:
+#if defined(WIN32)
+ typedef CRITICAL_SECTION OSLockType;
+#else
+ typedef pthread_mutex_t OSLockType;
+#endif
+
+ OSLockType os_lock_;
+
+ // Copy and assign not supported.
+ Lock(const Lock&);
+ Lock& operator=(const Lock&);
+};
+
+/// A helper class that scopes holding a lock.
+///
+/// @code
+/// class MyClass {
+/// public:
+/// void DoSomething() {
+/// pp::AutoLock lock(lock_);
+/// ...do something with the lock held...
+/// }
+///
+/// private:
+/// pp::Lock lock_;
+/// };
+/// @endcode
+class AutoLock {
+ public:
+ explicit AutoLock(Lock& lock) : lock_(lock) {
+ lock_.Acquire();
+ }
+
+ ~AutoLock() {
+ lock_.Release();
+ }
+
+ private:
+ Lock& lock_;
+
+ // Copy and assign not supported.
+ AutoLock(const AutoLock&);
+ AutoLock& operator=(const AutoLock&);
+};
+
+} // namespace pp
+
+#endif // PPAPI_UTILITY_THREADING_LOCK_H_