ipc/chromium/src/base/non_thread_safe.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #ifndef BASE_NON_THREAD_SAFE_H__
michael@0 6 #define BASE_NON_THREAD_SAFE_H__
michael@0 7
michael@0 8 #include "base/platform_thread.h"
michael@0 9
michael@0 10 // A helper class used to help verify that methods of a class are
michael@0 11 // called from the same thread. One can inherit from this class and use
michael@0 12 // CalledOnValidThread() to verify.
michael@0 13 //
michael@0 14 // This is intended to be used with classes that appear to be thread safe, but
michael@0 15 // aren't. For example, a service or a singleton like the preferences system.
michael@0 16 //
michael@0 17 // Example:
michael@0 18 // class MyClass : public NonThreadSafe {
michael@0 19 // public:
michael@0 20 // void Foo() {
michael@0 21 // DCHECK(CalledOnValidThread());
michael@0 22 // ... (do stuff) ...
michael@0 23 // }
michael@0 24 // }
michael@0 25 //
michael@0 26 // In Release mode, CalledOnValidThread will always return true.
michael@0 27 //
michael@0 28 #ifndef NDEBUG
michael@0 29 class NonThreadSafe {
michael@0 30 public:
michael@0 31 NonThreadSafe();
michael@0 32 ~NonThreadSafe();
michael@0 33
michael@0 34 bool CalledOnValidThread() const;
michael@0 35
michael@0 36 private:
michael@0 37 PlatformThreadId valid_thread_id_;
michael@0 38 };
michael@0 39 #else
michael@0 40 // Do nothing in release mode.
michael@0 41 class NonThreadSafe {
michael@0 42 public:
michael@0 43 NonThreadSafe() {}
michael@0 44 ~NonThreadSafe() {}
michael@0 45
michael@0 46 bool CalledOnValidThread() const {
michael@0 47 return true;
michael@0 48 }
michael@0 49 };
michael@0 50 #endif // NDEBUG
michael@0 51
michael@0 52 #endif // BASE_NON_THREAD_SAFE_H__

mercurial