0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 20:13:05 +02:00
openvpn3/openvpn/common/rc.hpp
James Yonan 1fcf65fbda Started PKI tree for wrapping OpenSSL PKI objects.
Started SSL Context class.

Implemented dgram & stream buffer queues that can operate as
OpenSSL BIOs.

Reworked Frame class to make it more flexible.
2011-10-25 17:32:26 +00:00

48 lines
1.1 KiB
C++

/*
* A simple reference-counting garbage collection scheme that works
* with boost::intrusive_ptr. Simply inherit from RC to create an
* object that can be tracked with an intrusive_ptr.
*/
#ifndef OPENVPN_COMMON_RC_H
#define OPENVPN_COMMON_RC_H
#include <boost/noncopyable.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/smart_ptr/detail/atomic_count.hpp>
namespace openvpn {
typedef boost::detail::atomic_count thread_safe_refcount;
typedef long thread_unsafe_refcount;
template <typename RCImpl> // RCImpl = thread_safe_refcount or thread_unsafe_refcount
class RC : boost::noncopyable
{
public:
RC() : refcount_(0) {}
virtual ~RC() {}
private:
template <typename R> friend void intrusive_ptr_add_ref(R* p);
template <typename R> friend void intrusive_ptr_release(R* p);
RCImpl refcount_;
};
template <typename R>
inline void intrusive_ptr_add_ref(R *p)
{
++p->refcount_;
}
template <typename R>
inline void intrusive_ptr_release(R *p)
{
if (--p->refcount_ == 0)
delete p;
}
} // namespace openvpn
#endif // OPENVPN_COMMON_RC_H