OLD | NEW |
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 USING_FAST_MALLOC(ThreadSafeRefCountedBase); | 43 USING_FAST_MALLOC(ThreadSafeRefCountedBase); |
44 | 44 |
45 public: | 45 public: |
46 ThreadSafeRefCountedBase(int initialRefCount = 1) | 46 ThreadSafeRefCountedBase(int initialRefCount = 1) |
47 : m_refCount(initialRefCount) {} | 47 : m_refCount(initialRefCount) {} |
48 | 48 |
49 void ref() { atomicIncrement(&m_refCount); } | 49 void ref() { atomicIncrement(&m_refCount); } |
50 | 50 |
51 bool hasOneRef() { return refCount() == 1; } | 51 bool hasOneRef() { return refCount() == 1; } |
52 | 52 |
53 int refCount() const { return static_cast<int const volatile&>(m_refCount); } | 53 int refCount() const { return acquireLoad(&m_refCount); } |
54 | 54 |
55 protected: | 55 protected: |
56 // Returns whether the pointer should be freed or not. | 56 // Returns whether the pointer should be freed or not. |
57 bool derefBase() { | 57 bool derefBase() { |
58 WTF_ANNOTATE_HAPPENS_BEFORE(&m_refCount); | 58 WTF_ANNOTATE_HAPPENS_BEFORE(&m_refCount); |
59 if (atomicDecrement(&m_refCount) <= 0) { | 59 if (atomicDecrement(&m_refCount) <= 0) { |
60 WTF_ANNOTATE_HAPPENS_AFTER(&m_refCount); | 60 WTF_ANNOTATE_HAPPENS_AFTER(&m_refCount); |
61 return true; | 61 return true; |
62 } | 62 } |
63 return false; | 63 return false; |
(...skipping 13 matching lines...) Expand all Loading... |
77 | 77 |
78 protected: | 78 protected: |
79 ThreadSafeRefCounted() {} | 79 ThreadSafeRefCounted() {} |
80 }; | 80 }; |
81 | 81 |
82 } // namespace WTF | 82 } // namespace WTF |
83 | 83 |
84 using WTF::ThreadSafeRefCounted; | 84 using WTF::ThreadSafeRefCounted; |
85 | 85 |
86 #endif // ThreadSafeRefCounted_h | 86 #endif // ThreadSafeRefCounted_h |
OLD | NEW |