Mega-cleanup for atomic_t<> and named bit-sets bs_t<>

Remove "atomic operator" classes
Remove test, test_and_set, test_and_reset, test_and_complement global functions
Simplify atomic_t<> with constexpr if, remove some garbage
Redesign bs_t<> to use class, mark its methods constexpr
Implement atomic_bs_t<> for optimizations
Remove unused __bitwise_ops concept (should be in other header anyway)
Bitsets can now be tested via safe bool conversion
This commit is contained in:
Nekotekina
2018-09-03 21:40:36 +03:00
parent a6d06b2e20
commit 8abe6489ed
23 changed files with 538 additions and 1024 deletions
+223 -326
View File
File diff suppressed because it is too large Load Diff
+19 -19
View File
@@ -799,34 +799,34 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
#ifdef _WIN32
DWORD access = 0;
if (test(mode & fs::read)) access |= GENERIC_READ;
if (test(mode & fs::write)) access |= DELETE | (test(mode & fs::append) ? FILE_APPEND_DATA : GENERIC_WRITE);
if (mode & fs::read) access |= GENERIC_READ;
if (mode & fs::write) access |= DELETE | (mode & fs::append ? FILE_APPEND_DATA : GENERIC_WRITE);
DWORD disp = 0;
if (test(mode & fs::create))
if (mode & fs::create)
{
disp =
test(mode & fs::excl) ? CREATE_NEW :
test(mode & fs::trunc) ? CREATE_ALWAYS : OPEN_ALWAYS;
mode & fs::excl ? CREATE_NEW :
mode & fs::trunc ? CREATE_ALWAYS : OPEN_ALWAYS;
}
else
{
if (test(mode & fs::excl))
if (mode & fs::excl)
{
g_tls_error = error::inval;
return;
}
disp = test(mode & fs::trunc) ? TRUNCATE_EXISTING : OPEN_EXISTING;
disp = mode & fs::trunc ? TRUNCATE_EXISTING : OPEN_EXISTING;
}
DWORD share = 0;
if (!test(mode, fs::unread) || !test(mode & fs::write))
if (!(mode & fs::unread) || !(mode & fs::write))
{
share |= FILE_SHARE_READ;
}
if (!test(mode, fs::lock + fs::unread) || !test(mode & fs::write))
if (!(mode & (fs::lock + fs::unread)) || !(mode & fs::write))
{
share |= FILE_SHARE_WRITE | FILE_SHARE_DELETE;
}
@@ -949,18 +949,18 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
#else
int flags = 0;
if (test(mode & fs::read) && test(mode & fs::write)) flags |= O_RDWR;
else if (test(mode & fs::read)) flags |= O_RDONLY;
else if (test(mode & fs::write)) flags |= O_WRONLY;
if (mode & fs::read && mode & fs::write) flags |= O_RDWR;
else if (mode & fs::read) flags |= O_RDONLY;
else if (mode & fs::write) flags |= O_WRONLY;
if (test(mode & fs::append)) flags |= O_APPEND;
if (test(mode & fs::create)) flags |= O_CREAT;
if (test(mode & fs::trunc) && !test(mode, fs::lock + fs::unread)) flags |= O_TRUNC;
if (test(mode & fs::excl)) flags |= O_EXCL;
if (mode & fs::append) flags |= O_APPEND;
if (mode & fs::create) flags |= O_CREAT;
if (mode & fs::trunc && !(mode & (fs::lock + fs::unread))) flags |= O_TRUNC;
if (mode & fs::excl) flags |= O_EXCL;
int perm = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
if (test(mode & fs::write) && test(mode & fs::unread))
if (mode & fs::write && mode & fs::unread)
{
perm = 0;
}
@@ -973,14 +973,14 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
return;
}
if (test(mode & fs::write) && test(mode, fs::lock + fs::unread) && ::flock(fd, LOCK_EX | LOCK_NB) != 0)
if (mode & fs::write && mode & (fs::lock + fs::unread) && ::flock(fd, LOCK_EX | LOCK_NB) != 0)
{
g_tls_error = errno == EWOULDBLOCK ? fs::error::acces : to_error(errno);
::close(fd);
return;
}
if (test(mode & fs::trunc) && test(mode, fs::lock + fs::unread))
if (mode & fs::trunc && mode & (fs::lock + fs::unread))
{
// Postpone truncation in order to avoid using O_TRUNC on a locked file
::ftruncate(fd, 0);
+192 -543
View File
File diff suppressed because it is too large Load Diff
-36
View File
@@ -707,42 +707,6 @@ constexpr u32 size32(const T (&)[Size], const char* msg = nullptr)
return static_cast<u32>(Size);
}
template <typename T1, typename = std::enable_if_t<std::is_integral<T1>::value>>
constexpr bool test(const T1& value)
{
return value != 0;
}
template <typename T1, typename T2, typename = std::enable_if_t<std::is_integral<T1>::value && std::is_integral<T2>::value>>
constexpr bool test(const T1& lhs, const T2& rhs)
{
return (lhs & rhs) != 0;
}
template <typename T, typename T2, typename = std::enable_if_t<std::is_integral<T>::value && std::is_integral<T2>::value>>
inline bool test_and_set(T& lhs, const T2& rhs)
{
const bool result = (lhs & rhs) != 0;
lhs |= rhs;
return result;
}
template <typename T, typename T2, typename = std::enable_if_t<std::is_integral<T>::value && std::is_integral<T2>::value>>
inline bool test_and_reset(T& lhs, const T2& rhs)
{
const bool result = (lhs & rhs) != 0;
lhs &= ~rhs;
return result;
}
template <typename T, typename T2, typename = std::enable_if_t<std::is_integral<T>::value && std::is_integral<T2>::value>>
inline bool test_and_complement(T& lhs, const T2& rhs)
{
const bool result = (lhs & rhs) != 0;
lhs ^= rhs;
return result;
}
// Simplified hash algorithm for pointers. May be used in std::unordered_(map|set).
template <typename T, std::size_t Align = alignof(T)>
struct pointer_hash
+12 -11
View File
@@ -52,10 +52,10 @@ void cpu_thread::on_task()
g_tls_current_cpu_thread = this;
// Check thread status
while (!test(state, cpu_flag::exit + cpu_flag::dbg_global_stop))
while (!(state & (cpu_flag::exit + cpu_flag::dbg_global_stop)))
{
// Check stop status
if (!test(state & cpu_flag::stop))
if (!(state & cpu_flag::stop))
{
try
{
@@ -100,7 +100,8 @@ cpu_thread::cpu_thread(u32 id)
bool cpu_thread::check_state()
{
#ifdef WITH_GDB_DEBUGGER
if (test(state, cpu_flag::dbg_pause)) {
if (state & cpu_flag::dbg_pause)
{
fxm::get<GDBDebugServer>()->pause_from(this);
}
#endif
@@ -110,7 +111,7 @@ bool cpu_thread::check_state()
while (true)
{
if (test(state, cpu_flag::memory) && state.test_and_reset(cpu_flag::memory))
if (state & cpu_flag::memory && state.test_and_reset(cpu_flag::memory))
{
cpu_flag_memory = true;
@@ -121,17 +122,17 @@ bool cpu_thread::check_state()
}
}
if (test(state, cpu_flag::exit + cpu_flag::dbg_global_stop))
if (state & cpu_flag::exit + cpu_flag::dbg_global_stop)
{
return true;
}
if (test(state & cpu_flag::signal) && state.test_and_reset(cpu_flag::signal))
if (state & cpu_flag::signal && state.test_and_reset(cpu_flag::signal))
{
cpu_sleep_called = false;
}
if (!test(state, cpu_state_pause))
if (!(state & cpu_state_pause))
{
if (cpu_flag_memory)
{
@@ -140,7 +141,7 @@ bool cpu_thread::check_state()
break;
}
else if (!cpu_sleep_called && test(state, cpu_flag::suspend))
else if (!cpu_sleep_called && state & cpu_flag::suspend)
{
cpu_sleep();
cpu_sleep_called = true;
@@ -152,12 +153,12 @@ bool cpu_thread::check_state()
const auto state_ = state.load();
if (test(state_, cpu_flag::ret + cpu_flag::stop))
if (state_ & (cpu_flag::ret + cpu_flag::stop))
{
return true;
}
if (test(state_, cpu_flag::dbg_step))
if (state_ & cpu_flag::dbg_step)
{
state += cpu_flag::dbg_pause;
state -= cpu_flag::dbg_step;
@@ -168,7 +169,7 @@ bool cpu_thread::check_state()
void cpu_thread::test_state()
{
if (UNLIKELY(test(state)))
if (UNLIKELY(state))
{
if (check_state())
{
+1 -1
View File
@@ -37,7 +37,7 @@ public:
cpu_thread(u32 id);
// Public thread state
atomic_t<bs_t<cpu_flag>> state{+cpu_flag::stop};
atomic_bs_t<cpu_flag> state{+cpu_flag::stop};
// Process thread state, return true if the checker must return
bool check_state();
+2 -2
View File
@@ -148,7 +148,7 @@ error_code sys_lwcond_signal_all(ppu_thread& ppu, vm::ptr<sys_lwcond_t> lwcond)
}
ppu.test_state();
lwmutex->all_info += res;
lwmutex->all_info += +res;
return CELL_OK;
}
@@ -173,7 +173,7 @@ error_code sys_lwcond_signal_all(ppu_thread& ppu, vm::ptr<sys_lwcond_t> lwcond)
if (res > 0)
{
lwmutex->all_info += res;
lwmutex->all_info += +res;
res = CELL_OK;
}
+8 -8
View File
@@ -1051,7 +1051,7 @@ void ppu_module::analyse(u32 lib_toc, u32 entry)
}
// Get function limit
const u32 func_end = std::min<u32>(get_limit(func.addr + 1), test(func.attr, ppu_attr::known_size) ? func.addr + func.size : end);
const u32 func_end = std::min<u32>(get_limit(func.addr + 1), func.attr & ppu_attr::known_size ? func.addr + func.size : end);
// Block analysis workload
std::vector<std::reference_wrapper<std::pair<const u32, u32>>> block_queue;
@@ -1084,7 +1084,7 @@ void ppu_module::analyse(u32 lib_toc, u32 entry)
}
// TODO: lower priority?
if (test(func.attr, ppu_attr::no_size))
if (func.attr & ppu_attr::no_size)
{
// Get next function
const auto _next = fmap.lower_bound(func.blocks.crbegin()->first + 1);
@@ -1135,12 +1135,12 @@ void ppu_module::analyse(u32 lib_toc, u32 entry)
}
// Add next block if necessary
if ((is_call && !test(pfunc->attr, ppu_attr::no_return)) || (type == ppu_itype::BC && (op.bo & 0x14) != 0x14))
if ((is_call && !(pfunc->attr & ppu_attr::no_return)) || (type == ppu_itype::BC && (op.bo & 0x14) != 0x14))
{
add_block(_ptr.addr());
}
if (is_call && test(pfunc->attr, ppu_attr::no_return))
if (is_call && pfunc->attr & ppu_attr::no_return)
{
// Nothing
}
@@ -1201,7 +1201,7 @@ void ppu_module::analyse(u32 lib_toc, u32 entry)
if (jt_addr != jt_end && _ptr.addr() == jt_addr)
{
// Acknowledge jumptable detection failure
if (!test(func.attr, ppu_attr::no_size))
if (!(func.attr & ppu_attr::no_size))
{
LOG_WARNING(PPU, "[0x%x] Jump table not found! 0x%x-0x%x", func.addr, jt_addr, jt_end);
}
@@ -1235,7 +1235,7 @@ void ppu_module::analyse(u32 lib_toc, u32 entry)
block.second = _ptr.addr() - block.first;
break;
}
else if (type == ppu_itype::STDU && test(func.attr, ppu_attr::no_size) && (op.opcode == *_ptr || *_ptr == ppu_instructions::BLR()))
else if (type == ppu_itype::STDU && func.attr & ppu_attr::no_size && (op.opcode == *_ptr || *_ptr == ppu_instructions::BLR()))
{
// Hack
LOG_SUCCESS(PPU, "[0x%x] Instruction repetition: 0x%08x", iaddr, op.opcode);
@@ -1254,7 +1254,7 @@ void ppu_module::analyse(u32 lib_toc, u32 entry)
}
// Finalization: determine function size
if (!test(func.attr, ppu_attr::known_size))
if (!(func.attr & ppu_attr::known_size))
{
const auto last = func.blocks.crbegin();
@@ -1320,7 +1320,7 @@ void ppu_module::analyse(u32 lib_toc, u32 entry)
}
// Finalization: decrease known function size (TODO)
if (test(func.attr, ppu_attr::known_size))
if (func.attr & ppu_attr::known_size)
{
const auto last = func.blocks.crbegin();
+1 -1
View File
@@ -1167,7 +1167,7 @@ void ppu_load_exec(const ppu_exec_object& elf)
if (info.size < sizeof(process_param_t))
{
LOG_WARNING(LOADER, "Bad process_param size! [0x%x : 0x%x]", info.size, SIZE_32(process_param_t));
LOG_WARNING(LOADER, "Bad process_param size! [0x%x : 0x%x]", info.size, sizeof(process_param_t));
}
if (info.magic != 0x13bcc5f6)
+5 -5
View File
@@ -607,7 +607,7 @@ void ppu_thread::exec_task()
{
if (g_cfg.core.ppu_decoder == ppu_decoder_type::llvm)
{
while (!test(state, cpu_flag::ret + cpu_flag::exit + cpu_flag::stop + cpu_flag::dbg_global_stop))
while (!(state & (cpu_flag::ret + cpu_flag::exit + cpu_flag::stop + cpu_flag::dbg_global_stop)))
{
reinterpret_cast<ppu_function_t>(static_cast<std::uintptr_t>(ppu_ref(cia)))(*this);
}
@@ -625,7 +625,7 @@ void ppu_thread::exec_task()
while (true)
{
if (UNLIKELY(test(state)))
if (UNLIKELY(state))
{
if (check_state()) return;
@@ -678,7 +678,7 @@ void ppu_thread::exec_task()
func2 = func4;
func3 = func5;
if (UNLIKELY(test(state)))
if (UNLIKELY(state))
{
break;
}
@@ -763,9 +763,9 @@ cmd64 ppu_thread::cmd_wait()
{
while (true)
{
if (UNLIKELY(test(state)))
if (UNLIKELY(state))
{
if (test(state, cpu_flag::stop + cpu_flag::exit))
if (state & (cpu_flag::stop + cpu_flag::exit))
{
return cmd64{};
}
+1 -1
View File
@@ -1183,7 +1183,7 @@ static void check_state_ret(SPUThread& _spu, void*, u8*)
static void check_state(SPUThread* _spu, spu_function_t _ret)
{
if (test(_spu->state) && _spu->check_state())
if (_spu->state && _spu->check_state())
{
_ret = &check_state_ret;
}
+3 -3
View File
@@ -490,7 +490,7 @@ std::vector<u32> spu_recompiler_base::block(const be_t<u32>* ls, u32 entry_point
}
}
if (test(af, vf::is_const))
if (af & vf::is_const)
{
const u32 target = spu_branch_target(av);
@@ -858,7 +858,7 @@ std::vector<u32> spu_recompiler_base::block(const be_t<u32>* ls, u32 entry_point
case spu_itype::HBR:
{
hbr_loc = spu_branch_target(pos, op.roh << 7 | op.rt);
hbr_tg = test(vflags[op.ra], vf::is_const) && !op.c ? values[op.ra] & 0x3fffc : -1;
hbr_tg = vflags[op.ra] & vf::is_const && !op.c ? values[op.ra] & 0x3fffc : -1;
break;
}
@@ -1017,7 +1017,7 @@ std::vector<u32> spu_recompiler_base::block(const be_t<u32>* ls, u32 entry_point
{
const u32 r2 = op.ra == 1 ? +op.rb : +op.ra;
if (test(vflags[r2], vf::is_const) && (values[r2] % 16) == 0)
if (vflags[r2] & vf::is_const && (values[r2] % 16) == 0)
{
break;
}
+20 -17
View File
@@ -521,7 +521,7 @@ void SPUThread::cpu_task()
if (jit)
{
while (LIKELY(!test(state) || !check_state()))
while (LIKELY(!state || !check_state()))
{
jit_dispatcher[pc / 4](*this, vm::_ptr<u8>(offset), nullptr);
}
@@ -547,7 +547,7 @@ void SPUThread::cpu_task()
while (true)
{
if (UNLIKELY(test(state)))
if (UNLIKELY(state))
{
if (check_state()) return;
@@ -594,7 +594,7 @@ void SPUThread::cpu_task()
func2 = func4;
func3 = func5;
if (UNLIKELY(test(state)))
if (UNLIKELY(state))
{
break;
}
@@ -1093,7 +1093,7 @@ void SPUThread::do_mfc(bool wait)
if (args.cmd & MFC_LIST_MASK)
{
if (!test(ch_stall_mask, mask))
if (!(ch_stall_mask & mask))
{
if (do_list_transfer(args))
{
@@ -1160,7 +1160,7 @@ bool SPUThread::process_mfc_cmd(spu_mfc_cmd args)
// Stall infinitely if MFC queue is full
while (UNLIKELY(mfc_size >= 16))
{
if (test(state, cpu_flag::stop))
if (state & cpu_flag::stop)
{
return false;
}
@@ -1193,7 +1193,7 @@ bool SPUThread::process_mfc_cmd(spu_mfc_cmd args)
while (rdata == data && vm::reservation_acquire(raddr, 128) == rtime)
{
if (test(state, cpu_flag::stop))
if (state & cpu_flag::stop)
{
break;
}
@@ -1400,7 +1400,7 @@ bool SPUThread::process_mfc_cmd(spu_mfc_cmd args)
{
if (LIKELY(args.size <= 0x4000))
{
if (LIKELY(do_dma_check(args) && !test(ch_stall_mask, 1u << args.tag)))
if (LIKELY(do_dma_check(args) && !(ch_stall_mask & 1u << args.tag)))
{
if (LIKELY(do_list_transfer(args)))
{
@@ -1558,7 +1558,7 @@ s64 SPUThread::get_ch_value(u32 ch)
while (!channel.try_pop(out))
{
if (test(state, cpu_flag::stop))
if (state & cpu_flag::stop)
{
return -1;
}
@@ -1596,7 +1596,7 @@ s64 SPUThread::get_ch_value(u32 ch)
return out;
}
if (test(state & cpu_flag::stop))
if (state & cpu_flag::stop)
{
return -1;
}
@@ -1700,7 +1700,7 @@ s64 SPUThread::get_ch_value(u32 ch)
while (res = get_events(), !res)
{
if (test(state, cpu_flag::stop + cpu_flag::dbg_global_stop))
if (state & (cpu_flag::stop + cpu_flag::dbg_global_stop))
{
return -1;
}
@@ -1713,7 +1713,7 @@ s64 SPUThread::get_ch_value(u32 ch)
while (res = get_events(true), !res)
{
if (test(state & cpu_flag::stop))
if (state & cpu_flag::stop)
{
return -1;
}
@@ -1753,7 +1753,7 @@ bool SPUThread::set_ch_value(u32 ch, u32 value)
{
while (!ch_out_intr_mbox.try_push(value))
{
if (test(state & cpu_flag::stop))
if (state & cpu_flag::stop)
{
return false;
}
@@ -1899,7 +1899,7 @@ bool SPUThread::set_ch_value(u32 ch, u32 value)
{
while (!ch_out_mbox.try_push(value))
{
if (test(state & cpu_flag::stop))
if (state & cpu_flag::stop)
{
return false;
}
@@ -2005,8 +2005,11 @@ bool SPUThread::set_ch_value(u32 ch, u32 value)
case MFC_WrListStallAck:
{
// Reset stall status for specified tag
if (::test_and_reset(ch_stall_mask, 1u << value))
const u32 tag_mask = 1u << value;
if (ch_stall_mask & tag_mask)
{
ch_stall_mask &= ~tag_mask;
do_mfc(true);
}
@@ -2085,7 +2088,7 @@ bool SPUThread::stop_and_signal(u32 code)
// HACK: wait for executable code
while (!_ref<u32>(pc))
{
if (test(state & cpu_flag::stop))
if (state & cpu_flag::stop)
{
return false;
}
@@ -2141,7 +2144,7 @@ bool SPUThread::stop_and_signal(u32 code)
// Check group status, wait if necessary
while (group->run_state >= SPU_THREAD_GROUP_STATUS_WAITING && group->run_state <= SPU_THREAD_GROUP_STATUS_SUSPENDED)
{
if (test(state & cpu_flag::stop))
if (state & cpu_flag::stop)
{
return false;
}
@@ -2210,7 +2213,7 @@ bool SPUThread::stop_and_signal(u32 code)
while (true)
{
if (test(state & cpu_flag::stop))
if (state & cpu_flag::stop)
{
return false;
}
+3 -3
View File
@@ -1014,13 +1014,13 @@ void lv2_obj::sleep_timeout(named_thread& thread, u64 timeout)
auto state = ppu->state.fetch_op([&](auto& val)
{
if (!test(val, cpu_flag::signal))
if (!(val & cpu_flag::signal))
{
val += cpu_flag::suspend;
}
});
if (test(state, cpu_flag::signal))
if (state & cpu_flag::signal)
{
LOG_TRACE(PPU, "sleep() failed (signaled)");
return;
@@ -1156,7 +1156,7 @@ void lv2_obj::schedule_all()
{
const auto target = g_ppu[i];
if (test(target->state, cpu_flag::suspend))
if (target->state & cpu_flag::suspend)
{
LOG_TRACE(PPU, "schedule(): %s", target->id);
target->state ^= (cpu_flag::signal + cpu_flag::suspend);
+2 -2
View File
@@ -275,7 +275,7 @@ error_code sys_fs_open(vm::cptr<char> path, s32 flags, vm::ptr<u32> fd, s32 mode
open_mode = {}; // error
}
if (!test(open_mode))
if (!open_mode)
{
fmt::throw_exception("sys_fs_open(%s): Invalid or unimplemented flags: %#o" HERE, path, flags);
}
@@ -307,7 +307,7 @@ error_code sys_fs_open(vm::cptr<char> path, s32 flags, vm::ptr<u32> fd, s32 mode
if (!file)
{
if (test(open_mode & fs::excl) && fs::g_tls_error == fs::error::exist)
if (open_mode & fs::excl && fs::g_tls_error == fs::error::exist)
{
return not_an_error(CELL_EEXIST);
}
+1 -1
View File
@@ -95,7 +95,7 @@ error_code _sys_interrupt_thread_establish(vm::ptr<u32> ih, u32 intrtag, u32 int
}
// If interrupt thread is running, it's already established on another interrupt tag
if (!test(it->state & cpu_flag::stop))
if (!(it->state & cpu_flag::stop))
{
error = CELL_EAGAIN;
return result;
+29 -29
View File
@@ -105,7 +105,7 @@ static void network_clear_queue(ppu_thread& ppu)
if (sock.queue.empty())
{
sock.events = {};
sock.events.store({});
}
});
}
@@ -180,11 +180,11 @@ extern void network_thread_init()
events += lv2_socket::poll::error;
#endif
if (test(events))
if (events)
{
semaphore_lock lock(socklist[i]->mutex);
for (auto it = socklist[i]->queue.begin(); test(events) && it != socklist[i]->queue.end();)
for (auto it = socklist[i]->queue.begin(); events && it != socklist[i]->queue.end();)
{
if (it->second(events))
{
@@ -197,7 +197,7 @@ extern void network_thread_init()
if (socklist[i]->queue.empty())
{
socklist[i]->events = {};
socklist[i]->events.store({});
}
}
}
@@ -226,10 +226,10 @@ extern void network_thread_init()
#ifdef _WIN32
verify(HERE), 0 == WSAEventSelect(socklist[i]->socket, _eventh, FD_READ | FD_ACCEPT | FD_CLOSE | FD_WRITE | FD_CONNECT);
#else
fds[i].fd = test(events) ? socklist[i]->socket : -1;
fds[i].fd = events ? socklist[i]->socket : -1;
fds[i].events =
(test(events, lv2_socket::poll::read) ? POLLIN : 0) |
(test(events, lv2_socket::poll::write) ? POLLOUT : 0) |
(events & lv2_socket::poll::read ? POLLIN : 0) |
(events & lv2_socket::poll::write ? POLLOUT : 0) |
0;
fds[i].revents = 0;
#endif
@@ -278,7 +278,7 @@ s32 sys_net_bnet_accept(ppu_thread& ppu, s32 s, vm::ptr<sys_net_sockaddr> addr,
{
semaphore_lock lock(sock.mutex);
//if (!test(sock.events, lv2_socket::poll::read))
//if (!(sock.events & lv2_socket::poll::read))
{
#ifdef _WIN32
sock.ev_set &= ~FD_ACCEPT;
@@ -302,7 +302,7 @@ s32 sys_net_bnet_accept(ppu_thread& ppu, s32 s, vm::ptr<sys_net_sockaddr> addr,
sock.events += lv2_socket::poll::read;
sock.queue.emplace_back(ppu.id, [&](bs_t<lv2_socket::poll> events) -> bool
{
if (test(events, lv2_socket::poll::read))
if (events & lv2_socket::poll::read)
{
#ifdef _WIN32
sock.ev_set &= ~FD_ACCEPT;
@@ -472,7 +472,7 @@ s32 sys_net_bnet_connect(ppu_thread& ppu, s32 s, vm::ptr<sys_net_sockaddr> addr,
sock.events += lv2_socket::poll::write;
sock.queue.emplace_back(u32{0}, [&sock](bs_t<lv2_socket::poll> events) -> bool
{
if (test(events, lv2_socket::poll::write))
if (events & lv2_socket::poll::write)
{
#ifdef _WIN32
sock.ev_set &= ~FD_CONNECT;
@@ -503,7 +503,7 @@ s32 sys_net_bnet_connect(ppu_thread& ppu, s32 s, vm::ptr<sys_net_sockaddr> addr,
sock.events += lv2_socket::poll::write;
sock.queue.emplace_back(ppu.id, [&](bs_t<lv2_socket::poll> events) -> bool
{
if (test(events, lv2_socket::poll::write))
if (events & lv2_socket::poll::write)
{
#ifdef _WIN32
sock.ev_set &= ~FD_CONNECT;
@@ -886,7 +886,7 @@ s32 sys_net_bnet_recvfrom(ppu_thread& ppu, s32 s, vm::ptr<void> buf, u32 len, s3
{
semaphore_lock lock(sock.mutex);
//if (!test(sock.events, lv2_socket::poll::read))
//if (!(sock.events & lv2_socket::poll::read))
{
#ifdef _WIN32
if (!(native_flags & MSG_PEEK)) sock.ev_set &= ~FD_READ;
@@ -910,7 +910,7 @@ s32 sys_net_bnet_recvfrom(ppu_thread& ppu, s32 s, vm::ptr<void> buf, u32 len, s3
sock.events += lv2_socket::poll::read;
sock.queue.emplace_back(ppu.id, [&](bs_t<lv2_socket::poll> events) -> bool
{
if (test(events, lv2_socket::poll::read))
if (events & lv2_socket::poll::read)
{
#ifdef _WIN32
if (!(native_flags & MSG_PEEK)) sock.ev_set &= ~FD_READ;
@@ -1039,7 +1039,7 @@ s32 sys_net_bnet_sendto(ppu_thread& ppu, s32 s, vm::cptr<void> buf, u32 len, s32
{
semaphore_lock lock(sock.mutex);
//if (!test(sock.events, lv2_socket::poll::write))
//if (!(sock.events & lv2_socket::poll::write))
{
#ifdef _WIN32
sock.ev_set &= ~FD_WRITE;
@@ -1063,7 +1063,7 @@ s32 sys_net_bnet_sendto(ppu_thread& ppu, s32 s, vm::cptr<void> buf, u32 len, s32
sock.events += lv2_socket::poll::write;
sock.queue.emplace_back(ppu.id, [&](bs_t<lv2_socket::poll> events) -> bool
{
if (test(events, lv2_socket::poll::write))
if (events & lv2_socket::poll::write)
{
#ifdef _WIN32
sock.ev_set &= ~FD_WRITE;
@@ -1517,13 +1517,13 @@ s32 sys_net_bnet_poll(ppu_thread& ppu, vm::ptr<sys_net_pollfd> fds, s32 nfds, s3
sock->events += selected;
sock->queue.emplace_back(ppu.id, [sock, selected, fds, i, &signaled, &ppu](bs_t<lv2_socket::poll> events)
{
if (test(events, selected))
if (events & selected)
{
if (test(events, selected & lv2_socket::poll::read))
if (events & selected & lv2_socket::poll::read)
fds[i].revents |= SYS_NET_POLLIN;
if (test(events, selected & lv2_socket::poll::write))
if (events & selected & lv2_socket::poll::write)
fds[i].revents |= SYS_NET_POLLOUT;
if (test(events, selected & lv2_socket::poll::error))
if (events & selected & lv2_socket::poll::error)
fds[i].revents |= SYS_NET_POLLERR;
signaled++;
@@ -1615,7 +1615,7 @@ s32 sys_net_bnet_select(ppu_thread& ppu, s32 nfds, vm::ptr<sys_net_fd_set> readf
//if (exceptfds && exceptfds->bit(i))
// selected += lv2_socket::poll::error;
if (test(selected))
if (selected)
{
selected += lv2_socket::poll::error;
}
@@ -1628,9 +1628,9 @@ s32 sys_net_bnet_select(ppu_thread& ppu, s32 nfds, vm::ptr<sys_net_fd_set> readf
{
#ifdef _WIN32
bool sig = false;
if (sock->ev_set & (FD_READ | FD_ACCEPT | FD_CLOSE) && test(selected, lv2_socket::poll::read))
if (sock->ev_set & (FD_READ | FD_ACCEPT | FD_CLOSE) && selected & lv2_socket::poll::read)
sig = true, rread.set(i);
if (sock->ev_set & (FD_WRITE | FD_CONNECT) && test(selected, lv2_socket::poll::write))
if (sock->ev_set & (FD_WRITE | FD_CONNECT) && selected & lv2_socket::poll::write)
sig = true, rwrite.set(i);
if (sig)
@@ -1639,9 +1639,9 @@ s32 sys_net_bnet_select(ppu_thread& ppu, s32 nfds, vm::ptr<sys_net_fd_set> readf
}
#else
_fds[i].fd = sock->socket;
if (test(selected, lv2_socket::poll::read))
if (selected & lv2_socket::poll::read)
_fds[i].events |= POLLIN;
if (test(selected, lv2_socket::poll::write))
if (selected & lv2_socket::poll::write)
_fds[i].events |= POLLOUT;
#endif
}
@@ -1691,7 +1691,7 @@ s32 sys_net_bnet_select(ppu_thread& ppu, s32 nfds, vm::ptr<sys_net_fd_set> readf
//if (exceptfds && exceptfds->bit(i))
// selected += lv2_socket::poll::error;
if (test(selected))
if (selected)
{
selected += lv2_socket::poll::error;
}
@@ -1707,13 +1707,13 @@ s32 sys_net_bnet_select(ppu_thread& ppu, s32 nfds, vm::ptr<sys_net_fd_set> readf
sock->events += selected;
sock->queue.emplace_back(ppu.id, [sock, selected, i, &rread, &rwrite, &rexcept, &signaled, &ppu](bs_t<lv2_socket::poll> events)
{
if (test(events, selected))
if (events & selected)
{
if (test(selected, lv2_socket::poll::read) && test(events, lv2_socket::poll::read + lv2_socket::poll::error))
if (selected & lv2_socket::poll::read && events & (lv2_socket::poll::read + lv2_socket::poll::error))
rread.set(i);
if (test(selected, lv2_socket::poll::write) && test(events, lv2_socket::poll::write + lv2_socket::poll::error))
if (selected & lv2_socket::poll::write && events & (lv2_socket::poll::write + lv2_socket::poll::error))
rwrite.set(i);
//if (test(events, selected & lv2_socket::poll::error))
//if (events & (selected & lv2_socket::poll::error))
// rexcept.set(i);
signaled++;
+1 -1
View File
@@ -335,7 +335,7 @@ struct lv2_socket final
socket_type socket;
// Events selected for polling
atomic_t<bs_t<poll>> events{};
atomic_bs_t<poll> events{};
// Non-blocking IO option
s32 so_nbio = 0;
+2 -2
View File
@@ -114,7 +114,7 @@ namespace vm
*ptr = nullptr;
ptr = nullptr;
if (test(cpu.state, cpu_flag::memory))
if (cpu.state & cpu_flag::memory)
{
cpu.state -= cpu_flag::memory;
}
@@ -221,7 +221,7 @@ namespace vm
{
while (cpu_thread* ptr = lock)
{
if (test(ptr->state, cpu_flag::dbg_global_stop + cpu_flag::exit))
if (ptr->state & (cpu_flag::dbg_global_stop + cpu_flag::exit))
{
break;
}
+4 -4
View File
@@ -243,8 +243,8 @@ public:
// Load program headers
std::vector<phdr_t> _phdrs;
if (!test(opts, elf_opt::no_programs))
if (!(opts & elf_opt::no_programs))
{
_phdrs.resize(header.e_phnum);
stream.seek(offset + header.e_phoff);
@@ -252,7 +252,7 @@ public:
return set_error(elf_error::stream_phdrs);
}
if (!test(opts, elf_opt::no_sections))
if (!(opts & elf_opt::no_sections))
{
shdrs.resize(header.e_shnum);
stream.seek(offset + header.e_shoff);
@@ -268,7 +268,7 @@ public:
static_cast<phdr_t&>(progs.back()) = hdr;
if (!test(opts, elf_opt::no_data))
if (!(opts & elf_opt::no_data))
{
progs.back().bin.resize(hdr.p_filesz);
stream.seek(offset + hdr.p_offset);

Some files were not shown because too many files have changed in this diff Show More