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

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

Issue 2386843002: reflow comments in wtf (Closed)
Patch Set: comments (heh!) Created 4 years, 2 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 21 matching lines...) Expand all
32 #define ThreadRestrictionVerifier_h 32 #define ThreadRestrictionVerifier_h
33 33
34 #include "wtf/Assertions.h" 34 #include "wtf/Assertions.h"
35 35
36 #if ENABLE(ASSERT) 36 #if ENABLE(ASSERT)
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
43 // The default mode is to verify that the object will only be used on a single t hread. The 43 // thread-safety. The default mode is to verify that the object will only be
44 // thread gets captured when setShared(true) is called. 44 // used on a single thread. The thread gets captured when setShared(true) is
45 // The mode may be changed by calling useMutexMode (or turnOffVerification). 45 // called. The mode may be changed by calling useMutexMode (or
46 // turnOffVerification).
46 class ThreadRestrictionVerifier { 47 class ThreadRestrictionVerifier {
47 public: 48 public:
48 ThreadRestrictionVerifier() : m_shared(false), m_owningThread(0) {} 49 ThreadRestrictionVerifier() : m_shared(false), m_owningThread(0) {}
49 50
50 void checkSafeToUse() const { 51 void checkSafeToUse() const {
51 // If this assert fires, it either indicates a thread safety issue or 52 // If this assert fires, it either indicates a thread safety issue or
52 // that the verification needs to change. 53 // that the verification needs to change.
53 ASSERT_WITH_SECURITY_IMPLICATION(isSafeToUse()); 54 ASSERT_WITH_SECURITY_IMPLICATION(isSafeToUse());
54 } 55 }
55 56
(...skipping 25 matching lines...) Expand all
81 private: 82 private:
82 // Indicates that the object may (or may not) be owned by more than one place. 83 // Indicates that the object may (or may not) be owned by more than one place.
83 void setShared(bool shared) { 84 void setShared(bool shared) {
84 bool previouslyShared = m_shared; 85 bool previouslyShared = m_shared;
85 m_shared = shared; 86 m_shared = shared;
86 87
87 if (!m_shared) 88 if (!m_shared)
88 return; 89 return;
89 90
90 ASSERT_UNUSED(previouslyShared, shared != previouslyShared); 91 ASSERT_UNUSED(previouslyShared, shared != previouslyShared);
91 // Capture the current thread to verify that subsequent ref/deref happen on this thread. 92 // Capture the current thread to verify that subsequent ref/deref happen on
93 // this thread.
92 m_owningThread = currentThread(); 94 m_owningThread = currentThread();
93 } 95 }
94 96
95 // Is it OK to use the object at this moment on the current thread? 97 // Is it OK to use the object at this moment on the current thread?
96 bool isSafeToUse() const { 98 bool isSafeToUse() const {
97 if (!m_shared) 99 if (!m_shared)
98 return true; 100 return true;
99 101
100 return m_owningThread == currentThread(); 102 return m_owningThread == currentThread();
101 } 103 }
102 104
103 bool m_shared; 105 bool m_shared;
104 106
105 ThreadIdentifier m_owningThread; 107 ThreadIdentifier m_owningThread;
106 }; 108 };
107 109
108 } // namespace WTF 110 } // namespace WTF
109 111
110 #endif // ENABLE(ASSERT) 112 #endif // ENABLE(ASSERT)
111 #endif // ThreadRestrictionVerifier_h 113 #endif // ThreadRestrictionVerifier_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/TerminatedArray.h ('k') | third_party/WebKit/Source/wtf/ThreadSpecific.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698