Homebrew atomic_ptr rewritten (util/shared_ptr.hpp)

It's analogous to C++20 atomic std::shared_ptr

The following things brought into global namespace:
single_ptr
shared_ptr
atomic_ptr
make_single
This commit is contained in:
Nekotekina 2020-11-26 12:30:51 +03:00
parent bd90e3e37f
commit b5d498ffda
15 changed files with 732 additions and 597 deletions

View file

@ -380,7 +380,7 @@ void cfg::_bool::from_default()
void cfg::string::from_default()
{
m_value = m_value.make(def);
m_value = def;
}
void cfg::set_entry::from_default()

View file

@ -4,7 +4,7 @@
#include "Utilities/StrFmt.h"
#include "util/logs.hpp"
#include "util/atomic.hpp"
#include "util/shared_cptr.hpp"
#include "util/shared_ptr.hpp"
#include <utility>
#include <string>
@ -393,7 +393,7 @@ namespace cfg
{
const std::string m_name;
stx::atomic_cptr<std::string> m_value;
atomic_ptr<std::string> m_value;
public:
std::string def;
@ -401,7 +401,7 @@ namespace cfg
string(node* owner, std::string name, std::string def = {}, bool dynamic = false)
: _base(type::string, owner, name, dynamic)
, m_name(std::move(name))
, m_value(m_value.make(def))
, m_value(def)
, def(std::move(def))
{
}
@ -411,7 +411,7 @@ namespace cfg
return *m_value.load().get();
}
std::pair<const std::string&, stx::shared_cptr<std::string>> get() const
std::pair<const std::string&, shared_ptr<std::string>> get() const
{
auto v = m_value.load();
@ -440,7 +440,7 @@ namespace cfg
bool from_string(const std::string& value, bool /*dynamic*/ = false) override
{
m_value = m_value.make(value);
m_value = value;
return true;
}
};

View file

@ -2242,7 +2242,7 @@ std::string thread_ctrl::get_name_cached()
return {};
}
static thread_local stx::shared_cptr<std::string> name_cache;
static thread_local shared_ptr<std::string> name_cache;
if (!_this->m_tname.is_equal(name_cache)) [[unlikely]]
{
@ -2254,7 +2254,7 @@ std::string thread_ctrl::get_name_cached()
thread_base::thread_base(native_entry entry, std::string_view name)
: entry_point(entry)
, m_tname(stx::shared_cptr<std::string>::make(name))
, m_tname(make_single<std::string>(name))
{
}

View file

@ -2,7 +2,7 @@
#include "types.h"
#include "util/atomic.hpp"
#include "util/shared_cptr.hpp"
#include "util/shared_ptr.hpp"
#include <string>
#include <memory>
@ -110,7 +110,7 @@ private:
atomic_t<u64> m_sync{0};
// Thread name
stx::atomic_cptr<std::string> m_tname;
atomic_ptr<std::string> m_tname;
// Start thread
void start();
@ -191,14 +191,14 @@ public:
// Set current thread name (not recommended)
static void set_name(std::string_view name)
{
g_tls_this_thread->m_tname.store(stx::shared_cptr<std::string>::make(name));
g_tls_this_thread->m_tname.store(make_single<std::string>(name));
}
// Set thread name (not recommended)
template <typename T>
static void set_name(named_thread<T>& thread, std::string_view name)
{
static_cast<thread_base&>(thread).m_tname.store(stx::shared_cptr<std::string>::make(name));
static_cast<thread_base&>(thread).m_tname.store(make_single<std::string>(name));
}
template <typename T>