Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

atomic_ptr rewritten #9341

Merged
merged 5 commits into from Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Utilities/Config.cpp
Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions Utilities/Config.h
Expand Up @@ -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>
Expand Down Expand Up @@ -393,15 +393,15 @@ namespace cfg
{
const std::string m_name;

stx::atomic_cptr<std::string> m_value;
atomic_ptr<std::string> m_value;

public:
std::string def;

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))
{
}
Expand All @@ -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();

Expand Down Expand Up @@ -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;
}
};
Expand Down
16 changes: 10 additions & 6 deletions Utilities/Thread.cpp
Expand Up @@ -1786,7 +1786,9 @@ static void signal_handler(int sig, siginfo_t* info, void* uct) noexcept

if (IsDebuggerPresent())
{
__asm("int3;");
// Convert to SIGTRAP
raise(SIGTRAP);
return;
}

report_fatal_error(msg);
Expand Down Expand Up @@ -2010,7 +2012,10 @@ u64 thread_base::finalize(thread_state result_state) noexcept

atomic_wait_engine::set_wait_callback(nullptr);

// Return true if need to delete thread object (no)
// Avoid race with the destructor
const u64 _self = m_thread;

// Set result state (errored or finalized)
const bool ok = 0 == (3 & ~m_sync.fetch_op([&](u64& v)
{
v &= -4;
Expand All @@ -2020,8 +2025,7 @@ u64 thread_base::finalize(thread_state result_state) noexcept
// Signal waiting threads
m_sync.notify_all(2);

// No detached thread supported atm
return m_thread;
return _self;
}

thread_base::native_entry thread_base::finalize(u64 _self) noexcept
Expand Down Expand Up @@ -2242,7 +2246,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]]
{
Expand All @@ -2254,7 +2258,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))
{
}

Expand Down
8 changes: 4 additions & 4 deletions Utilities/Thread.h
Expand Up @@ -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>
Expand Down Expand Up @@ -110,7 +110,7 @@ class thread_base
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();
Expand Down Expand Up @@ -191,14 +191,14 @@ class thread_ctrl final
// 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>
Expand Down
1 change: 0 additions & 1 deletion rpcs3/Emu/CMakeLists.txt
Expand Up @@ -34,7 +34,6 @@ target_include_directories(rpcs3_emu
target_sources(rpcs3_emu PRIVATE
../util/atomic.cpp
../util/atomic2.cpp
../util/shared_cptr.cpp
../util/fixed_typemap.cpp
../util/logs.cpp
../util/yaml.cpp
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/PPUThread.cpp
Expand Up @@ -915,7 +915,7 @@ ppu_thread::ppu_thread(const ppu_thread_params& param, std::string_view name, u3
, joiner(detached != 0 ? ppu_join_status::detached : ppu_join_status::joinable)
, entry_func(param.entry)
, start_time(get_guest_system_time())
, ppu_tname(stx::shared_cptr<std::string>::make(name))
, ppu_tname(make_single<std::string>(name))
{
gpr[1] = stack_addr + stack_size - ppu_stack_start_offset;

Expand Down Expand Up @@ -1020,7 +1020,7 @@ void ppu_thread::fast_call(u32 addr, u32 rtoc)
{
const auto _this = static_cast<ppu_thread*>(get_current_cpu_thread());

static thread_local stx::shared_cptr<std::string> name_cache;
static thread_local shared_ptr<std::string> name_cache;

if (!_this->ppu_tname.is_equal(name_cache)) [[unlikely]]
{
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/PPUThread.h
Expand Up @@ -215,7 +215,7 @@ class ppu_thread : public cpu_thread
const char* last_function{}; // Sticky copy of current_function, is not cleared on function return

// Thread name
stx::atomic_cptr<std::string> ppu_tname;
atomic_ptr<std::string> ppu_tname;

u64 last_ftsc = 0;
u64 last_ftime = 0;
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/SPUThread.cpp
Expand Up @@ -1572,7 +1572,7 @@ void spu_thread::cpu_task()
{
const auto cpu = static_cast<spu_thread*>(get_current_cpu_thread());

static thread_local stx::shared_cptr<std::string> name_cache;
static thread_local shared_ptr<std::string> name_cache;

if (!cpu->spu_tname.is_equal(name_cache)) [[unlikely]]
{
Expand Down Expand Up @@ -1692,7 +1692,7 @@ spu_thread::spu_thread(lv2_spu_group* group, u32 index, std::string_view name, u
, group(group)
, option(option)
, lv2_id(lv2_id)
, spu_tname(stx::shared_cptr<std::string>::make(name))
, spu_tname(make_single<std::string>(name))
{
if (g_cfg.core.spu_decoder == spu_decoder_type::asmjit)
{
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/SPUThread.h
Expand Up @@ -747,7 +747,7 @@ class spu_thread : public cpu_thread
const u32 lv2_id; // The actual id that is used by syscalls

// Thread name
stx::atomic_cptr<std::string> spu_tname;
atomic_ptr<std::string> spu_tname;

std::unique_ptr<class spu_recompiler_base> jit; // Recompiler instance

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp
Expand Up @@ -548,7 +548,7 @@ error_code sys_ppu_thread_rename(ppu_thread& ppu, u32 thread_id, vm::cptr<char>
const auto pname = name.get_ptr();

// Make valid name
auto _name = stx::shared_cptr<std::string>::make(pname, std::find(pname, pname + max_size, '\0'));
auto _name = make_single<std::string>(pname, std::find(pname, pname + max_size, '\0'));

// thread_ctrl name is not changed (TODO)
sys_ppu_thread.warning(u8"sys_ppu_thread_rename(): Thread renamed to “%s”", *_name);
Expand Down
16 changes: 5 additions & 11 deletions rpcs3/Emu/System.cpp
Expand Up @@ -89,7 +89,7 @@ namespace

namespace atomic_wait
{
extern void parse_hashtable(bool(*cb)(u64 id, u16 refs, u32 ptr, u32 stats));
extern void parse_hashtable(bool(*cb)(u64 id, u32 refs, u64 ptr, u32 stats));
}

template<>
Expand Down Expand Up @@ -1919,19 +1919,13 @@ void Emulator::Stop(bool restart)
aw_colc = 0;
aw_used = 0;

atomic_wait::parse_hashtable([](u64 id, u16 refs, u32 ptr, u32 stats) -> bool
atomic_wait::parse_hashtable([](u64 id, u32 refs, u64 ptr, u32 maxc) -> bool
{
aw_refs += refs;
aw_refs += refs != 0;
aw_used += ptr != 0;

stats = (stats & 0xaaaaaaaa) / 2 + (stats & 0x55555555);
stats = (stats & 0xcccccccc) / 4 + (stats & 0x33333333);
stats = (stats & 0xf0f0f0f0) / 16 + (stats & 0xf0f0f0f);
stats = (stats & 0xff00ff00) / 256 + (stats & 0xff00ff);
stats = (stats >> 16) + (stats & 0xffff);

aw_colm = std::max<u64>(aw_colm, stats);
aw_colc += stats != 0;
aw_colm = std::max<u64>(aw_colm, maxc);
aw_colc += maxc != 0;

return false;
});
Expand Down
5 changes: 1 addition & 4 deletions rpcs3/emucore.vcxproj
Expand Up @@ -130,9 +130,6 @@
<ClCompile Include="util\cereal.cpp">
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="util\shared_cptr.cpp">
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="util\fixed_typemap.cpp">
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
Expand Down Expand Up @@ -778,7 +775,7 @@
<ClInclude Include="restore_new.h" />
<ClInclude Include="rpcs3_version.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="util\shared_cptr.hpp" />
<ClInclude Include="util\shared_ptr.hpp" />
<ClInclude Include="util\typeindices.hpp" />
<ClInclude Include="util\yaml.hpp" />
</ItemGroup>
Expand Down
8 changes: 1 addition & 7 deletions rpcs3/emucore.vcxproj.filters
Expand Up @@ -878,9 +878,6 @@
<ClCompile Include="util\cereal.cpp">
<Filter>Utilities</Filter>
</ClCompile>
<ClCompile Include="util\shared_cptr.cpp">
<Filter>Utilities</Filter>
</ClCompile>
<ClCompile Include="util\fixed_typemap.cpp">
<Filter>Utilities</Filter>
</ClCompile>
Expand Down Expand Up @@ -944,9 +941,6 @@
<ClCompile Include="util\logs.cpp">
<Filter>Utilities</Filter>
</ClCompile>
<ClCompile Include="util\shared_cptr.cpp">
<Filter>Utilities</Filter>
</ClCompile>
<ClCompile Include="Emu\Audio\FAudio\FAudioBackend.cpp">
<Filter>Emu\Audio\FAudio</Filter>
</ClCompile>
Expand Down Expand Up @@ -1837,7 +1831,7 @@
<ClInclude Include="util\logs.hpp">
<Filter>Utilities</Filter>
</ClInclude>
<ClInclude Include="util\shared_cptr.hpp">
<ClInclude Include="util\shared_ptr.hpp">
<Filter>Utilities</Filter>
</ClInclude>
<ClInclude Include="util\typeindices.hpp">
Expand Down