[lldb] Remove some dead code from SharingPtr.h

These classes are not used.
This commit is contained in:
Pavel Labath 2020-01-31 15:45:16 +01:00
parent df71000d7d
commit b8966de73f
1 changed files with 0 additions and 245 deletions

View File

@ -359,251 +359,6 @@ SharingPtr<T> const_pointer_cast(const SharingPtr<U> &r) {
return SharingPtr<T>(r, const_cast<T *>(r.get()));
}
template <class T> class LoggingSharingPtr : public SharingPtr<T> {
typedef SharingPtr<T> base;
public:
typedef void (*Callback)(void *, const LoggingSharingPtr &, bool action);
// action: false means increment just happened
// true means decrement is about to happen
LoggingSharingPtr() : cb_(0), baton_(nullptr) {}
LoggingSharingPtr(Callback cb, void *baton) : cb_(cb), baton_(baton) {
if (cb_)
cb_(baton_, *this, false);
}
template <class Y>
LoggingSharingPtr(Y *p) : base(p), cb_(0), baton_(nullptr) {}
template <class Y>
LoggingSharingPtr(Y *p, Callback cb, void *baton)
: base(p), cb_(cb), baton_(baton) {
if (cb_)
cb_(baton_, *this, false);
}
~LoggingSharingPtr() {
if (cb_)
cb_(baton_, *this, true);
}
LoggingSharingPtr(const LoggingSharingPtr &p)
: base(p), cb_(p.cb_), baton_(p.baton_) {
if (cb_)
cb_(baton_, *this, false);
}
LoggingSharingPtr &operator=(const LoggingSharingPtr &p) {
if (cb_)
cb_(baton_, *this, true);
base::operator=(p);
cb_ = p.cb_;
baton_ = p.baton_;
if (cb_)
cb_(baton_, *this, false);
return *this;
}
void reset() {
if (cb_)
cb_(baton_, *this, true);
base::reset();
}
template <class Y> void reset(Y *p) {
if (cb_)
cb_(baton_, *this, true);
base::reset(p);
if (cb_)
cb_(baton_, *this, false);
}
void SetCallback(Callback cb, void *baton) {
cb_ = cb;
baton_ = baton;
}
void ClearCallback() {
cb_ = 0;
baton_ = 0;
}
private:
Callback cb_;
void *baton_;
};
template <class T> class IntrusiveSharingPtr;
template <class T> class ReferenceCountedBase {
public:
explicit ReferenceCountedBase() : shared_owners_(-1) {}
void add_shared();
void release_shared();
long use_count() const { return shared_owners_ + 1; }
protected:
long shared_owners_;
friend class IntrusiveSharingPtr<T>;
private:
ReferenceCountedBase(const ReferenceCountedBase &) = delete;
ReferenceCountedBase &operator=(const ReferenceCountedBase &) = delete;
};
template <class T> void lldb_private::ReferenceCountedBase<T>::add_shared() {
#ifdef _MSC_VER
_InterlockedIncrement(&shared_owners_);
#else
++shared_owners_;
#endif
}
template <class T>
void lldb_private::ReferenceCountedBase<T>::release_shared() {
#ifdef _MSC_VER
if (_InterlockedDecrement(&shared_owners_) == -1)
#else
if (--shared_owners_ == -1)
#endif
delete static_cast<T *>(this);
}
template <class T>
class ReferenceCountedBaseVirtual : public imp::shared_count {
public:
explicit ReferenceCountedBaseVirtual() : imp::shared_count(-1) {}
~ReferenceCountedBaseVirtual() override = default;
void on_zero_shared() override;
};
template <class T> void ReferenceCountedBaseVirtual<T>::on_zero_shared() {}
template <typename T> class IntrusiveSharingPtr {
public:
typedef T element_type;
explicit IntrusiveSharingPtr() : ptr_(0) {}
explicit IntrusiveSharingPtr(T *ptr) : ptr_(ptr) { add_shared(); }
IntrusiveSharingPtr(const IntrusiveSharingPtr &rhs) : ptr_(rhs.ptr_) {
add_shared();
}
template <class X>
IntrusiveSharingPtr(const IntrusiveSharingPtr<X> &rhs) : ptr_(rhs.get()) {
add_shared();
}
IntrusiveSharingPtr &operator=(const IntrusiveSharingPtr &rhs) {
reset(rhs.get());
return *this;
}
template <class X>
IntrusiveSharingPtr &operator=(const IntrusiveSharingPtr<X> &rhs) {
reset(rhs.get());
return *this;
}
IntrusiveSharingPtr &operator=(T *ptr) {
reset(ptr);
return *this;
}
~IntrusiveSharingPtr() {
release_shared();
ptr_ = nullptr;
}
T &operator*() const { return *ptr_; }
T *operator->() const { return ptr_; }
T *get() const { return ptr_; }
explicit operator bool() const { return ptr_ != 0; }
void swap(IntrusiveSharingPtr &rhs) {
std::swap(ptr_, rhs.ptr_);
#if defined(ENABLE_SP_LOGGING)
track_sp(this, ptr_, use_count());
track_sp(&rhs, rhs.ptr_, rhs.use_count());
#endif
}
void reset(T *ptr = nullptr) { IntrusiveSharingPtr(ptr).swap(*this); }
long use_count() const {
if (ptr_)
return ptr_->use_count();
return 0;
}
bool unique() const { return use_count() == 1; }
private:
element_type *ptr_;
void add_shared() {
if (ptr_) {
ptr_->add_shared();
#if defined(ENABLE_SP_LOGGING)
track_sp(this, ptr_, ptr_->use_count());
#endif
}
}
void release_shared() {
if (ptr_) {
#if defined(ENABLE_SP_LOGGING)
track_sp(this, nullptr, ptr_->use_count() - 1);
#endif
ptr_->release_shared();
}
}
};
template <class T, class U>
inline bool operator==(const IntrusiveSharingPtr<T> &lhs,
const IntrusiveSharingPtr<U> &rhs) {
return lhs.get() == rhs.get();
}
template <class T, class U>
inline bool operator!=(const IntrusiveSharingPtr<T> &lhs,
const IntrusiveSharingPtr<U> &rhs) {
return lhs.get() != rhs.get();
}
template <class T, class U>
inline bool operator==(const IntrusiveSharingPtr<T> &lhs, U *rhs) {
return lhs.get() == rhs;
}
template <class T, class U>
inline bool operator!=(const IntrusiveSharingPtr<T> &lhs, U *rhs) {
return lhs.get() != rhs;
}
template <class T, class U>
inline bool operator==(T *lhs, const IntrusiveSharingPtr<U> &rhs) {
return lhs == rhs.get();
}
template <class T, class U>
inline bool operator!=(T *lhs, const IntrusiveSharingPtr<U> &rhs) {
return lhs != rhs.get();
}
} // namespace lldb_private
#endif // utility_SharingPtr_h_