mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-03 21:41:26 +12:00
Improve DYNAMIC_IMPORT
Don't call get_proc_address every time if if failed. Also rename Utilities/dynamic_library.h to util/dyn_lib.hpp
This commit is contained in:
parent
cdaa8cb5c4
commit
bd5253047b
7 changed files with 27 additions and 23 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "util/atomic.hpp"
|
#include "util/atomic.hpp"
|
||||||
#include "dynamic_library.h"
|
#include "util/dyn_lib.hpp"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
|
|
|
@ -40,11 +40,11 @@ target_sources(rpcs3_emu PRIVATE
|
||||||
../util/yaml.cpp
|
../util/yaml.cpp
|
||||||
../util/cereal.cpp
|
../util/cereal.cpp
|
||||||
../util/vm_native.cpp
|
../util/vm_native.cpp
|
||||||
|
../util/dyn_lib.cpp
|
||||||
../../Utilities/bin_patch.cpp
|
../../Utilities/bin_patch.cpp
|
||||||
../../Utilities/cheat_info.cpp
|
../../Utilities/cheat_info.cpp
|
||||||
../../Utilities/cond.cpp
|
../../Utilities/cond.cpp
|
||||||
../../Utilities/Config.cpp
|
../../Utilities/Config.cpp
|
||||||
../../Utilities/dynamic_library.cpp
|
|
||||||
../../Utilities/File.cpp
|
../../Utilities/File.cpp
|
||||||
../../Utilities/JIT.cpp
|
../../Utilities/JIT.cpp
|
||||||
../../Utilities/LUrlParser.cpp
|
../../Utilities/LUrlParser.cpp
|
||||||
|
|
|
@ -141,7 +141,9 @@
|
||||||
<ClCompile Include="..\Utilities\cond.cpp">
|
<ClCompile Include="..\Utilities\cond.cpp">
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\Utilities\dynamic_library.cpp" />
|
<ClCompile Include="util\dyn_lib.cpp">
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\Utilities\JIT.cpp">
|
<ClCompile Include="..\Utilities\JIT.cpp">
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -527,7 +529,6 @@
|
||||||
<ClInclude Include="..\Utilities\cond.h" />
|
<ClInclude Include="..\Utilities\cond.h" />
|
||||||
<ClInclude Include="..\Utilities\CRC.h" />
|
<ClInclude Include="..\Utilities\CRC.h" />
|
||||||
<ClInclude Include="..\Utilities\date_time.h" />
|
<ClInclude Include="..\Utilities\date_time.h" />
|
||||||
<ClInclude Include="..\Utilities\dynamic_library.h" />
|
|
||||||
<ClInclude Include="..\Utilities\geometry.h" />
|
<ClInclude Include="..\Utilities\geometry.h" />
|
||||||
<ClInclude Include="..\Utilities\hash.h" />
|
<ClInclude Include="..\Utilities\hash.h" />
|
||||||
<ClInclude Include="..\Utilities\JIT.h" />
|
<ClInclude Include="..\Utilities\JIT.h" />
|
||||||
|
@ -540,6 +541,7 @@
|
||||||
<ClInclude Include="util\fixed_typemap.hpp" />
|
<ClInclude Include="util\fixed_typemap.hpp" />
|
||||||
<ClInclude Include="util\init_mutex.hpp" />
|
<ClInclude Include="util\init_mutex.hpp" />
|
||||||
<ClInclude Include="util\logs.hpp" />
|
<ClInclude Include="util\logs.hpp" />
|
||||||
|
<ClInclude Include="..\Utilities\dyn_lib.hpp" />
|
||||||
<ClInclude Include="..\Utilities\File.h" />
|
<ClInclude Include="..\Utilities\File.h" />
|
||||||
<ClInclude Include="..\Utilities\Config.h" />
|
<ClInclude Include="..\Utilities\Config.h" />
|
||||||
<ClInclude Include="..\Utilities\rXml.h" />
|
<ClInclude Include="..\Utilities\rXml.h" />
|
||||||
|
|
|
@ -734,7 +734,7 @@
|
||||||
<ClCompile Include="Emu\IdManager.cpp">
|
<ClCompile Include="Emu\IdManager.cpp">
|
||||||
<Filter>Emu</Filter>
|
<Filter>Emu</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\Utilities\dynamic_library.cpp">
|
<ClCompile Include="util\dyn_lib.cpp">
|
||||||
<Filter>Utilities</Filter>
|
<Filter>Utilities</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\Utilities\version.cpp">
|
<ClCompile Include="..\Utilities\version.cpp">
|
||||||
|
@ -1561,7 +1561,7 @@
|
||||||
<ClInclude Include="Emu\RSX\rsx_cache.h">
|
<ClInclude Include="Emu\RSX\rsx_cache.h">
|
||||||
<Filter>Emu\GPU\RSX</Filter>
|
<Filter>Emu\GPU\RSX</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\Utilities\dynamic_library.h">
|
<ClInclude Include="util\dyn_lib.hpp">
|
||||||
<Filter>Utilities</Filter>
|
<Filter>Utilities</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\Utilities\version.h">
|
<ClInclude Include="..\Utilities\version.h">
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "Utilities/sema.h"
|
#include "Utilities/sema.h"
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include "Utilities/dynamic_library.h"
|
#include "util/dyn_lib.hpp"
|
||||||
DYNAMIC_IMPORT("ntdll.dll", NtQueryTimerResolution, NTSTATUS(PULONG MinimumResolution, PULONG MaximumResolution, PULONG CurrentResolution));
|
DYNAMIC_IMPORT("ntdll.dll", NtQueryTimerResolution, NTSTATUS(PULONG MinimumResolution, PULONG MaximumResolution, PULONG CurrentResolution));
|
||||||
DYNAMIC_IMPORT("ntdll.dll", NtSetTimerResolution, NTSTATUS(ULONG DesiredResolution, BOOLEAN SetResolution, PULONG CurrentResolution));
|
DYNAMIC_IMPORT("ntdll.dll", NtSetTimerResolution, NTSTATUS(ULONG DesiredResolution, BOOLEAN SetResolution, PULONG CurrentResolution));
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "dynamic_library.h"
|
#include "dyn_lib.hpp"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
|
@ -53,40 +53,42 @@ namespace utils
|
||||||
template <typename R, typename... Args>
|
template <typename R, typename... Args>
|
||||||
struct dynamic_import<R(Args...)>
|
struct dynamic_import<R(Args...)>
|
||||||
{
|
{
|
||||||
R (*ptr)(Args...);
|
atomic_t<std::uintptr_t> ptr;
|
||||||
const char* const lib;
|
const char* const lib;
|
||||||
const char* const name;
|
const char* const name;
|
||||||
|
|
||||||
// Constant initialization
|
// Constant initialization
|
||||||
constexpr dynamic_import(const char* lib, const char* name)
|
constexpr dynamic_import(const char* lib, const char* name) noexcept
|
||||||
: ptr(nullptr)
|
: ptr(-1)
|
||||||
, lib(lib)
|
, lib(lib)
|
||||||
, name(name)
|
, name(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void init()
|
void init() noexcept
|
||||||
{
|
{
|
||||||
if (!ptr)
|
ptr.release(reinterpret_cast<std::uintptr_t>(get_proc_address(lib, name)));
|
||||||
{
|
|
||||||
// TODO: atomic
|
|
||||||
ptr = reinterpret_cast<R (*)(Args...)>(get_proc_address(lib, name));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
operator bool()
|
operator bool() noexcept
|
||||||
|
{
|
||||||
|
if (ptr == umax) [[unlikely]]
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
return ptr;
|
return ptr != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Caller
|
// Caller
|
||||||
R operator()(Args... args)
|
R operator()(Args... args) noexcept
|
||||||
|
{
|
||||||
|
if (ptr == umax) [[unlikely]]
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
return ptr(args...);
|
return reinterpret_cast<R (*)(Args...)>(ptr.load())(args...);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue