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

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

Issue 1436153002: Apply clang-format with Chromium-style without column limit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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) 2007, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) 3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 21 matching lines...) Expand all
32 32
33 #include "wtf/Allocator.h" 33 #include "wtf/Allocator.h"
34 #include "wtf/Atomics.h" 34 #include "wtf/Atomics.h"
35 #include "wtf/DynamicAnnotations.h" 35 #include "wtf/DynamicAnnotations.h"
36 #include "wtf/Noncopyable.h" 36 #include "wtf/Noncopyable.h"
37 #include "wtf/WTFExport.h" 37 #include "wtf/WTFExport.h"
38 38
39 namespace WTF { 39 namespace WTF {
40 40
41 class WTF_EXPORT ThreadSafeRefCountedBase { 41 class WTF_EXPORT ThreadSafeRefCountedBase {
42 WTF_MAKE_NONCOPYABLE(ThreadSafeRefCountedBase); 42 WTF_MAKE_NONCOPYABLE(ThreadSafeRefCountedBase);
43 USING_FAST_MALLOC(ThreadSafeRefCountedBase); 43 USING_FAST_MALLOC(ThreadSafeRefCountedBase);
44 public: 44
45 ThreadSafeRefCountedBase(int initialRefCount = 1) 45 public:
46 : m_refCount(initialRefCount) 46 ThreadSafeRefCountedBase(int initialRefCount = 1)
47 { 47 : m_refCount(initialRefCount) {
48 }
49
50 void ref() {
51 atomicIncrement(&m_refCount);
52 }
53
54 bool hasOneRef() {
55 return refCount() == 1;
56 }
57
58 int refCount() const {
59 return static_cast<int const volatile&>(m_refCount);
60 }
61
62 protected:
63 // Returns whether the pointer should be freed or not.
64 bool derefBase() {
65 WTF_ANNOTATE_HAPPENS_BEFORE(&m_refCount);
66 if (atomicDecrement(&m_refCount) <= 0) {
67 WTF_ANNOTATE_HAPPENS_AFTER(&m_refCount);
68 return true;
48 } 69 }
70 return false;
71 }
49 72
50 void ref() 73 private:
51 { 74 int m_refCount;
52 atomicIncrement(&m_refCount);
53 }
54
55 bool hasOneRef()
56 {
57 return refCount() == 1;
58 }
59
60 int refCount() const
61 {
62 return static_cast<int const volatile &>(m_refCount);
63 }
64
65 protected:
66 // Returns whether the pointer should be freed or not.
67 bool derefBase()
68 {
69 WTF_ANNOTATE_HAPPENS_BEFORE(&m_refCount);
70 if (atomicDecrement(&m_refCount) <= 0) {
71 WTF_ANNOTATE_HAPPENS_AFTER(&m_refCount);
72 return true;
73 }
74 return false;
75 }
76
77 private:
78 int m_refCount;
79 }; 75 };
80 76
81 template<class T> class ThreadSafeRefCounted : public ThreadSafeRefCountedBase { 77 template <class T>
82 public: 78 class ThreadSafeRefCounted : public ThreadSafeRefCountedBase {
83 void deref() 79 public:
84 { 80 void deref() {
85 if (derefBase()) 81 if (derefBase())
86 delete static_cast<T*>(this); 82 delete static_cast<T*>(this);
87 } 83 }
88 84
89 protected: 85 protected:
90 ThreadSafeRefCounted() 86 ThreadSafeRefCounted() {
91 { 87 }
92 }
93 }; 88 };
94 89
95 } // namespace WTF 90 } // namespace WTF
96 91
97 using WTF::ThreadSafeRefCounted; 92 using WTF::ThreadSafeRefCounted;
98 93
99 #endif // ThreadSafeRefCounted_h 94 #endif // ThreadSafeRefCounted_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/ThreadRestrictionVerifier.h ('k') | third_party/WebKit/Source/wtf/ThreadSpecific.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698