atomic.hpp: add atomic_t<bool> specialization

May be required in future, plus adds/hides some methods.
This commit is contained in:
Nekotekina 2020-12-06 16:32:56 +03:00
parent eb66302907
commit 24e4e329ed
6 changed files with 96 additions and 6 deletions

View file

@ -639,7 +639,7 @@ s32 cellCameraIsOpen(s32 dev_num)
std::lock_guard lock(g_camera->mutex);
return g_camera->is_open;
return g_camera->is_open.load();
}
s32 cellCameraIsStarted(s32 dev_num)
@ -665,7 +665,7 @@ s32 cellCameraIsStarted(s32 dev_num)
std::lock_guard lock(g_camera->mutex);
return g_camera->is_streaming;
return g_camera->is_streaming.load();
}
error_code cellCameraGetAttribute(s32 dev_num, s32 attrib, vm::ptr<u32> arg1, vm::ptr<u32> arg2)

View file

@ -192,7 +192,7 @@ error_code cellOskDialogLoadAsync(u32 container, vm::ptr<CellOskDialogParam> dia
});
// wait for check callback
while (done == false)
while (!done)
{
std::this_thread::yield();
}

View file

@ -40,7 +40,7 @@ namespace gl
{
for (auto&& job : m_work_queue.pop_all())
{
if (m_context_ready.compare_and_swap_test(false, true))
if (!m_context_ready.test_and_set())
{
// Bind context on first use
m_context_bind_func(m_context);

View file

@ -212,7 +212,7 @@ void GLGSRender::flip(const rsx::display_flip_info_t& info)
if (image_to_flip)
{
if (m_frame->screenshot_toggle == true)
if (m_frame->screenshot_toggle)
{
m_frame->screenshot_toggle = false;

View file

@ -645,7 +645,7 @@ void VKGSRender::flip(const rsx::display_flip_info_t& info)
direct_fbo->release();
}
if (m_frame->screenshot_toggle == true)
if (m_frame->screenshot_toggle)
{
m_frame->screenshot_toggle = false;

View file

@ -1629,3 +1629,93 @@ public:
}
}
};
template <std::size_t Align>
class atomic_t<bool, Align> : private atomic_t<uchar, Align>
{
using base = atomic_t<uchar, Align>;
public:
static constexpr std::size_t align = Align;
using simple_type = bool;
atomic_t() noexcept = default;
atomic_t(const atomic_t&) = delete;
atomic_t& operator =(const atomic_t&) = delete;
constexpr atomic_t(bool value) noexcept
: base(value)
{
}
bool load() const noexcept
{
return base::load() != 0;
}
operator bool() const noexcept
{
return base::load() != 0;
}
bool observe() const noexcept
{
return base::observe() != 0;
}
void store(bool value)
{
base::store(value);
}
bool operator =(bool value)
{
base::store(value);
return value;
}
void release(bool value)
{
base::release(value);
}
bool exchange(bool value)
{
return base::exchange(value) != 0;
}
bool test_and_set()
{
return base::exchange(1) != 0;
}
bool test_and_reset()
{
return base::exchange(0) != 0;
}
bool test_and_invert()
{
return base::fetch_xor(1) != 0;
}
// Timeout is discouraged
template <atomic_wait::op Flags = atomic_wait::op::eq>
void wait(bool old_value, atomic_wait_timeout timeout = atomic_wait_timeout::inf) const noexcept
{
base::template wait<Flags>(old_value, 1, timeout);
}
void notify_one() noexcept
{
base::notify_one(1);
}
void notify_all() noexcept
{
base::notify_all(1);
}
};