-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Intrusive pointer back reference infra
Changes to introduce intrusive pointer back reference infra to manage back reference pointers of the objects hold intrusive pointer reference. incorporating use of this infra for VRF intrusive ptr references to have better debug ability for VRF delete timeout crash Change-Id: I10d27af5a1f86067279ef788a8c99003dbc989f0 Closes-Bug: 1484796
- Loading branch information
Prabhjot Singh Sethi
committed
Aug 21, 2015
1 parent
680cd2c
commit a0716c7
Showing
19 changed files
with
156 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. | ||
*/ | ||
|
||
#ifndef SRC_BASE_INTRUSIVE_PTR_BACK_REF_H_ | ||
#define SRC_BASE_INTRUSIVE_PTR_BACK_REF_H_ | ||
|
||
#include <boost/intrusive_ptr.hpp> | ||
|
||
// IntrusivePtrRef Class is an extension to boost::intrusive_ptr | ||
// to provide additional functionality of making back reference | ||
// pointer available with callbacks intrusive_ptr_add_back_ref | ||
// and intrusive_ptr_del_back_ref, using which application using | ||
// IntrusivePtrRef can keep track of pointers who holds references | ||
// to the object | ||
|
||
// referrer, pair of base pointer and member pointer | ||
typedef std::pair<void*, void*> IntrusiveReferrer; | ||
|
||
template <class D> | ||
class IntrusivePtrRef : public boost::intrusive_ptr<D> { | ||
public: | ||
IntrusivePtrRef() : boost::intrusive_ptr<D>(), referrer_(NULL) { | ||
} | ||
|
||
IntrusivePtrRef(D *data) : boost::intrusive_ptr<D>(data), referrer_(NULL) { | ||
if (data) { | ||
intrusive_ptr_add_back_ref(IntrusiveReferrer(referrer_, this), data); | ||
} | ||
} | ||
|
||
IntrusivePtrRef(D *data, void *referrer) : boost::intrusive_ptr<D>(data), | ||
referrer_(referrer) { | ||
if (data) { | ||
intrusive_ptr_add_back_ref(IntrusiveReferrer(referrer, this), data); | ||
} | ||
} | ||
|
||
IntrusivePtrRef(IntrusivePtrRef const &rhs, void *referrer) | ||
: boost::intrusive_ptr<D>(rhs), referrer_(referrer) { | ||
if (this->get()) { | ||
intrusive_ptr_add_back_ref(IntrusiveReferrer(referrer, this), | ||
this->get()); | ||
} | ||
} | ||
|
||
virtual ~IntrusivePtrRef() { | ||
if (this->get()) { | ||
intrusive_ptr_del_back_ref(IntrusiveReferrer(referrer_, this), this->get()); | ||
} | ||
} | ||
|
||
IntrusivePtrRef & operator=(IntrusivePtrRef const &rhs) { | ||
IntrusivePtrRef(rhs, this).swap(*this); | ||
return *this; | ||
} | ||
|
||
IntrusivePtrRef & operator=(D *rhs) { | ||
IntrusivePtrRef(rhs, this).swap(*this); | ||
return *this; | ||
} | ||
|
||
void reset() { | ||
IntrusivePtrRef(NULL, this).swap(*this); | ||
} | ||
|
||
void reset(D *rhs) { | ||
IntrusivePtrRef(rhs, this).swap(*this); | ||
} | ||
|
||
void swap(IntrusivePtrRef &rhs) { | ||
// Trigger Base class swap to swap values | ||
boost::intrusive_ptr<D>::swap(rhs); | ||
|
||
// swap the referrer for this and rhs | ||
D *tmp = this->get(); | ||
if (tmp) { | ||
// change referrer for new value of IntrusivePtrRef | ||
intrusive_ptr_add_back_ref(IntrusiveReferrer(referrer_, this), tmp); | ||
intrusive_ptr_del_back_ref(IntrusiveReferrer(rhs.referrer_, &rhs), tmp); | ||
} | ||
tmp = rhs.get(); | ||
if (tmp) { | ||
// change referrer for new value of rhs | ||
intrusive_ptr_add_back_ref(IntrusiveReferrer(rhs.referrer_, &rhs), tmp); | ||
intrusive_ptr_del_back_ref(IntrusiveReferrer(referrer_, this), tmp); | ||
} | ||
} | ||
|
||
private: | ||
void *referrer_; | ||
}; | ||
|
||
#endif // SRC_BASE_INTRUSIVE_PTR_BACK_REF_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.