Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/WebKit/Source/wtf/ThreadRestrictionVerifier.h

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 26 matching lines...) Expand all
37 37
38 #include "wtf/Threading.h" 38 #include "wtf/Threading.h"
39 39
40 namespace WTF { 40 namespace WTF {
41 41
42 // Verifies that a class is used in a way that respects its lack of thread-safet y. 42 // Verifies that a class is used in a way that respects its lack of thread-safet y.
43 // The default mode is to verify that the object will only be used on a single t hread. The 43 // The default mode is to verify that the object will only be used on a single t hread. The
44 // thread gets captured when setShared(true) is called. 44 // thread gets captured when setShared(true) is called.
45 // The mode may be changed by calling useMutexMode (or turnOffVerification). 45 // The mode may be changed by calling useMutexMode (or turnOffVerification).
46 class ThreadRestrictionVerifier { 46 class ThreadRestrictionVerifier {
47 public: 47 public:
48 ThreadRestrictionVerifier() 48 ThreadRestrictionVerifier() : m_shared(false), m_owningThread(0) {}
49 : m_shared(false)
50 , m_owningThread(0)
51 {
52 }
53 49
54 // Indicates that the object may (or may not) be owned by more than one plac e. 50 // Indicates that the object may (or may not) be owned by more than one place.
55 void setShared(bool shared) 51 void setShared(bool shared) {
56 { 52 bool previouslyShared = m_shared;
57 bool previouslyShared = m_shared; 53 m_shared = shared;
58 m_shared = shared;
59 54
60 if (!m_shared) 55 if (!m_shared)
61 return; 56 return;
62 57
63 ASSERT_UNUSED(previouslyShared, shared != previouslyShared); 58 ASSERT_UNUSED(previouslyShared, shared != previouslyShared);
64 // Capture the current thread to verify that subsequent ref/deref happen on this thread. 59 // Capture the current thread to verify that subsequent ref/deref happen on this thread.
65 m_owningThread = currentThread(); 60 m_owningThread = currentThread();
66 } 61 }
67 62
68 // Is it OK to use the object at this moment on the current thread? 63 // Is it OK to use the object at this moment on the current thread?
69 bool isSafeToUse() const 64 bool isSafeToUse() const {
70 { 65 if (!m_shared)
71 if (!m_shared) 66 return true;
72 return true;
73 67
74 return m_owningThread == currentThread(); 68 return m_owningThread == currentThread();
75 } 69 }
76 70
77 private: 71 private:
78 bool m_shared; 72 bool m_shared;
79 73
80 // Used by SingleThreadVerificationMode 74 // Used by SingleThreadVerificationMode
81 ThreadIdentifier m_owningThread; 75 ThreadIdentifier m_owningThread;
82 }; 76 };
83
84 } 77 }
85 78
86 #endif // ENABLE(ASSERT) 79 #endif // ENABLE(ASSERT)
87 #endif // ThreadRestrictionVerifier_h 80 #endif // ThreadRestrictionVerifier_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/TerminatedArrayBuilder.h ('k') | third_party/WebKit/Source/wtf/ThreadSafeRefCounted.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698