~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/webkit/JavaScriptCore/wtf/RefCounted.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
// This base class holds the non-template methods and attributes.
30
30
// The RefCounted class inherits from it reducing the template bloat
31
31
// generated by the compiler (technique called template hoisting).
32
 
class RefCountedBase : Noncopyable {
 
32
class RefCountedBase {
33
33
public:
34
34
    void ref()
35
35
    {
49
49
    }
50
50
 
51
51
protected:
52
 
    RefCountedBase(int initialRefCount)
53
 
        : m_refCount(initialRefCount)
 
52
    RefCountedBase()
 
53
        : m_refCount(1)
54
54
#ifndef NDEBUG
55
55
        , m_deletionHasBegun(false)
56
56
#endif
57
57
    {
58
58
    }
59
59
 
60
 
    ~RefCountedBase() {}
 
60
    ~RefCountedBase()
 
61
    {
 
62
    }
61
63
 
62
64
    // Returns whether the pointer should be freed or not.
63
65
    bool derefBase()
75
77
        return false;
76
78
    }
77
79
 
78
 
protected:
 
80
    // Helper for generating JIT code. Please do not use for non-JIT purposes.
 
81
    int* addressOfCount()
 
82
    {
 
83
        return &m_refCount;
 
84
    }
 
85
 
 
86
#ifndef NDEBUG
 
87
    bool deletionHasBegun() const
 
88
    {
 
89
        return m_deletionHasBegun;
 
90
    }
 
91
#endif
 
92
 
 
93
private:
 
94
    template<class T>
 
95
    friend class CrossThreadRefCounted;
 
96
 
79
97
    int m_refCount;
80
98
#ifndef NDEBUG
81
99
    bool m_deletionHasBegun;
83
101
};
84
102
 
85
103
 
86
 
template<class T> class RefCounted : public RefCountedBase {
87
 
public:
88
 
    RefCounted(int initialRefCount = 1)
89
 
        : RefCountedBase(initialRefCount)
90
 
    {
91
 
    }
92
 
 
93
 
    void deref()
94
 
    {
95
 
        if (derefBase())
96
 
            delete static_cast<T*>(this);
97
 
    }
98
 
 
99
 
protected:
100
 
    ~RefCounted() {}
 
104
template<class T> class RefCounted : public RefCountedBase, public Noncopyable {
 
105
public:
 
106
    void deref()
 
107
    {
 
108
        if (derefBase())
 
109
            delete static_cast<T*>(this);
 
110
    }
 
111
 
 
112
protected:
 
113
    ~RefCounted()
 
114
    {
 
115
    }
 
116
};
 
117
 
 
118
template<class T> class RefCountedCustomAllocated : public RefCountedBase, public NoncopyableCustomAllocated {
 
119
public:
 
120
    void deref()
 
121
    {
 
122
        if (derefBase())
 
123
            delete static_cast<T*>(this);
 
124
    }
 
125
 
 
126
protected:
 
127
    ~RefCountedCustomAllocated()
 
128
    {
 
129
    }
101
130
};
102
131
 
103
132
} // namespace WTF
104
133
 
105
134
using WTF::RefCounted;
 
135
using WTF::RefCountedCustomAllocated;
106
136
 
107
137
#endif // RefCounted_h