mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2024-11-25 00:53:43 +00:00
Adapt safe_ptr to build in this project
This commit is contained in:
parent
bc35e185e7
commit
5a2fd1e25e
2 changed files with 26 additions and 7 deletions
|
@ -3,6 +3,10 @@
|
|||
|
||||
#include <utility>
|
||||
|
||||
#if !defined(NDEBUG) && !defined(KAK_DEBUG)
|
||||
# define KAK_DEBUG
|
||||
#endif
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
||||
|
@ -122,4 +126,8 @@ struct RefCountable
|
|||
|
||||
}
|
||||
|
||||
#if defined(KAK_DEBUG)
|
||||
# undef KAK_DEBUG
|
||||
#endif
|
||||
|
||||
#endif // ref_ptr_hh_INCLUDED
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
|
||||
// #define SAFE_PTR_TRACK_CALLSTACKS
|
||||
|
||||
#include "assert.hh"
|
||||
#include "ref_ptr.hh"
|
||||
#include "backtrace.hh"
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
@ -15,6 +13,14 @@
|
|||
#include <algorithm>
|
||||
#endif
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#define kak_assert assert
|
||||
|
||||
#if !defined(NDEBUG) && !defined(KAK_DEBUG)
|
||||
# define KAK_DEBUG
|
||||
#endif
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
||||
|
@ -33,7 +39,7 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
friend void inc_ref_count(const SafeCountable* sc, void* ptr)
|
||||
friend void inc_ref_count(const SafeCountable* sc, void* /*ptr*/)
|
||||
{
|
||||
++sc->m_count;
|
||||
#ifdef SAFE_PTR_TRACK_CALLSTACKS
|
||||
|
@ -41,7 +47,7 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
friend void dec_ref_count(const SafeCountable* sc, void* ptr)
|
||||
friend void dec_ref_count(const SafeCountable* sc, void* /*ptr*/)
|
||||
{
|
||||
--sc->m_count;
|
||||
kak_assert(sc->m_count >= 0);
|
||||
|
@ -53,7 +59,7 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
friend void ref_ptr_moved(const SafeCountable* sc, void* from, void* to)
|
||||
friend void ref_ptr_moved(const SafeCountable* /*sc*/, void* /*from*/, void* /*to*/)
|
||||
{
|
||||
#ifdef SAFE_PTR_TRACK_CALLSTACKS
|
||||
auto it = std::find_if(sc->m_callstacks.begin(), sc->m_callstacks.end(),
|
||||
|
@ -77,10 +83,10 @@ private:
|
|||
mutable int m_count;
|
||||
#else
|
||||
[[gnu::always_inline]]
|
||||
friend void inc_ref_count(const SafeCountable* sc, void* ptr) {}
|
||||
friend void inc_ref_count(const SafeCountable* /*sc*/, void* /*ptr*/) {}
|
||||
|
||||
[[gnu::always_inline]]
|
||||
friend void dec_ref_count(const SafeCountable* sc, void* ptr) {}
|
||||
friend void dec_ref_count(const SafeCountable* /*sc*/, void* /*ptr*/) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -92,4 +98,9 @@ using SafePtr = RefPtr<T, PropagateConst<T, SafeCountable>>;
|
|||
|
||||
}
|
||||
|
||||
#if defined(KAK_DEBUG)
|
||||
# undef KAK_DEBUG
|
||||
#endif
|
||||
#undef kak_assert
|
||||
|
||||
#endif // safe_ptr_hh_INCLUDED
|
||||
|
|
Loading…
Reference in a new issue