From 26e36b3a9d7b49d46ecfa69b447482251acba8ac Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 24 Jan 2024 16:53:38 +0300 Subject: Turn libodb repository into package for muti-package repository --- libodb/odb/details/shared-ptr/base.hxx | 131 +++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 libodb/odb/details/shared-ptr/base.hxx (limited to 'libodb/odb/details/shared-ptr/base.hxx') diff --git a/libodb/odb/details/shared-ptr/base.hxx b/libodb/odb/details/shared-ptr/base.hxx new file mode 100644 index 0000000..8cd4c86 --- /dev/null +++ b/libodb/odb/details/shared-ptr/base.hxx @@ -0,0 +1,131 @@ +// file : odb/details/shared-ptr/base.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_DETAILS_SHARED_PTR_BASE_HXX +#define ODB_DETAILS_SHARED_PTR_BASE_HXX + +#include + +#include // ODB_CXX11, ODB_NOTHROW_NOEXCEPT + +#include +#include // std::size_t + +#ifdef ODB_CXX11 +#include +#endif + +#include +#include + +namespace odb +{ + namespace details + { + struct share + { + explicit + share (char id); + + bool + operator== (share) const; + + private: + char id_; + }; + + extern LIBODB_EXPORT share shared; + extern LIBODB_EXPORT share exclusive; + } +} + +#ifdef ODB_CXX11 +LIBODB_EXPORT void* +operator new (std::size_t, odb::details::share); +#else +LIBODB_EXPORT void* +operator new (std::size_t, odb::details::share) throw (std::bad_alloc); +#endif + +LIBODB_EXPORT void +operator delete (void*, odb::details::share) ODB_NOTHROW_NOEXCEPT; + +namespace odb +{ + namespace details + { + class LIBODB_EXPORT shared_base + { + public: + shared_base (); + shared_base (const shared_base&); + shared_base& + operator= (const shared_base&); + + void + _inc_ref (); + + bool + _dec_ref (); + + std::size_t + _ref_count () const; + +#ifdef ODB_CXX11 + void* + operator new (std::size_t); + + void* + operator new (std::size_t, share); +#else + void* + operator new (std::size_t) throw (std::bad_alloc); + + void* + operator new (std::size_t, share) throw (std::bad_alloc); +#endif + + void + operator delete (void*, share) ODB_NOTHROW_NOEXCEPT; + + void + operator delete (void*) ODB_NOTHROW_NOEXCEPT; + + struct refcount_callback + { + void* arg; + + // Return true if the object should be deleted, false otherwise. + // + bool (*zero_counter) (void*); + }; + + protected: +#ifdef ODB_CXX11 + std::atomic counter_; +#else + std::size_t counter_; +#endif + refcount_callback* callback_; + }; + + template + inline X* + inc_ref (X*); + + template + inline void + dec_ref (X*); + + template + inline std::size_t + ref_count (const X*); + } +} + +#include +#include + +#include + +#endif // ODB_DETAILS_SHARED_PTR_BASE_HXX -- cgit v1.1