mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-04 14:08:37 +00:00
vm::var replaced, atomic_op simplified
This commit is contained in:
parent
c598fe7aa9
commit
ec68e012f9
9 changed files with 165 additions and 258 deletions
|
|
@ -61,14 +61,6 @@ template<> struct atomic_op_result_t<void>
|
|||
}
|
||||
};
|
||||
|
||||
struct break_never_t
|
||||
{
|
||||
template<typename RT> inline bool operator()(const atomic_op_result_t<RT>&) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T> union _atomic_base
|
||||
{
|
||||
using type = std::remove_cv_t<T>;
|
||||
|
|
@ -152,7 +144,7 @@ public:
|
|||
}
|
||||
|
||||
// perform an atomic operation on data (callable object version, first arg is a reference to atomic type)
|
||||
template<typename Break_if = break_never_t, typename F, typename... Args> auto atomic_op(F func, Args&&... args) volatile -> decltype(func(std::declval<T&>(), args...))
|
||||
template<typename F, typename... Args> auto atomic_op(F func, Args&&... args) volatile -> decltype(func(std::declval<T&>(), args...))
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
|
|
@ -165,16 +157,15 @@ public:
|
|||
// call atomic op for the local copy of the old value and save the return value of the function
|
||||
atomic_op_result_t<std::result_of_t<F(T&, Args...)>> result(func, to_type(_new), args...);
|
||||
|
||||
// 1) check return value using callable object of Break_if type, return if condition met
|
||||
// 2) atomically compare value with `old`, replace with `_new` and return on success
|
||||
if (Break_if()(result) || sync_bool_compare_and_swap(&sub_data, old, _new)) return result.move();
|
||||
// atomically compare value with `old`, replace with `_new` and return on success
|
||||
if (sync_bool_compare_and_swap(&sub_data, old, _new)) return result.move();
|
||||
}
|
||||
}
|
||||
|
||||
// perform an atomic operation on data (member function version)
|
||||
template<typename Break_if = break_never_t, typename CT, typename RT, typename... FArgs, typename... Args, typename = std::enable_if_t<std::is_same<T, CT>::value>> auto atomic_op(RT(CT::* func)(FArgs...), Args&&... args) volatile -> decltype((std::declval<T&>().*func)(args...))
|
||||
template<typename RT, typename... FArgs, typename CT, typename... Args, typename = std::enable_if_t<std::is_same<T, CT>::value>> auto atomic_op(RT(CT::* func)(FArgs...), Args&&... args) volatile -> decltype((std::declval<T&>().*func)(args...))
|
||||
{
|
||||
return atomic_op<Break_if>(std::mem_fn(func), std::forward<Args>(args)...);
|
||||
return atomic_op(std::mem_fn(func), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// atomic bitwise OR, returns previous data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue