mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 19:15:09 +00:00
Kernel: Use a Lockable<bool> for sysctl booleans as well.
This commit is contained in:
parent
e78e032c19
commit
33d34d9b26
5 changed files with 29 additions and 15 deletions
|
@ -103,6 +103,12 @@ public:
|
||||||
Lock& lock() { return m_lock; }
|
Lock& lock() { return m_lock; }
|
||||||
T& resource() { return m_resource; }
|
T& resource() { return m_resource; }
|
||||||
|
|
||||||
|
T lock_and_copy()
|
||||||
|
{
|
||||||
|
LOCKER(m_lock);
|
||||||
|
return m_resource;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T m_resource;
|
T m_resource;
|
||||||
Lock m_lock;
|
Lock m_lock;
|
||||||
|
|
|
@ -560,7 +560,11 @@ static ByteBuffer read_sys_bool(InodeIdentifier inode_id)
|
||||||
auto& custom_data = *static_cast<const SysVariableData*>(inode.custom_data());
|
auto& custom_data = *static_cast<const SysVariableData*>(inode.custom_data());
|
||||||
ASSERT(custom_data.type == SysVariableData::Boolean);
|
ASSERT(custom_data.type == SysVariableData::Boolean);
|
||||||
ASSERT(custom_data.address);
|
ASSERT(custom_data.address);
|
||||||
buffer[0] = *reinterpret_cast<bool*>(custom_data.address) ? '1' : '0';
|
auto* lockable_bool = reinterpret_cast<Lockable<bool>*>(custom_data.address);
|
||||||
|
{
|
||||||
|
LOCKER(lockable_bool->lock());
|
||||||
|
buffer[0] = lockable_bool->resource() ? '1' : '0';
|
||||||
|
}
|
||||||
buffer[1] = '\n';
|
buffer[1] = '\n';
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
@ -572,14 +576,17 @@ static ssize_t write_sys_bool(InodeIdentifier inode_id, const ByteBuffer& data)
|
||||||
return { };
|
return { };
|
||||||
auto& inode = static_cast<ProcFSInode&>(*inode_ptr);
|
auto& inode = static_cast<ProcFSInode&>(*inode_ptr);
|
||||||
ASSERT(inode.custom_data());
|
ASSERT(inode.custom_data());
|
||||||
if (data.size() >= 1 && (data[0] == '0' || data[0] == '1')) {
|
if (data.is_empty() || !(data[0] == '0' || data[0] == '1'))
|
||||||
auto& custom_data = *static_cast<const SysVariableData*>(inode.custom_data());
|
return data.size();
|
||||||
ASSERT(custom_data.address);
|
|
||||||
bool new_value = data[0] == '1';
|
auto& custom_data = *static_cast<const SysVariableData*>(inode.custom_data());
|
||||||
*reinterpret_cast<bool*>(custom_data.address) = new_value;
|
auto* lockable_bool = reinterpret_cast<Lockable<bool>*>(custom_data.address);
|
||||||
if (custom_data.notify_callback)
|
{
|
||||||
custom_data.notify_callback();
|
LOCKER(lockable_bool->lock());
|
||||||
|
lockable_bool->resource() = data[0] == '1';
|
||||||
}
|
}
|
||||||
|
if (custom_data.notify_callback)
|
||||||
|
custom_data.notify_callback();
|
||||||
return data.size();
|
return data.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -618,7 +625,7 @@ static ssize_t write_sys_string(InodeIdentifier inode_id, const ByteBuffer& data
|
||||||
return data.size();
|
return data.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcFS::add_sys_bool(String&& name, bool* var, Function<void()>&& notify_callback)
|
void ProcFS::add_sys_bool(String&& name, Lockable<bool>& var, Function<void()>&& notify_callback)
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
|
|
||||||
|
@ -627,7 +634,7 @@ void ProcFS::add_sys_bool(String&& name, bool* var, Function<void()>&& notify_ca
|
||||||
auto data = make<SysVariableData>();
|
auto data = make<SysVariableData>();
|
||||||
data->type = SysVariableData::Boolean;
|
data->type = SysVariableData::Boolean;
|
||||||
data->notify_callback = move(notify_callback);
|
data->notify_callback = move(notify_callback);
|
||||||
data->address = var;
|
data->address = &var;
|
||||||
inode->set_custom_data(move(data));
|
inode->set_custom_data(move(data));
|
||||||
m_sys_entries.append({ strdup(name.characters()), name.length(), read_sys_bool, write_sys_bool, move(inode) });
|
m_sys_entries.append({ strdup(name.characters()), name.length(), read_sys_bool, write_sys_bool, move(inode) });
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ public:
|
||||||
virtual RetainPtr<Inode> create_directory(InodeIdentifier parent_id, const String& name, mode_t, int& error) override;
|
virtual RetainPtr<Inode> create_directory(InodeIdentifier parent_id, const String& name, mode_t, int& error) override;
|
||||||
|
|
||||||
void add_sys_file(String&&, Function<ByteBuffer(ProcFSInode&)>&& read_callback, Function<ssize_t(ProcFSInode&, const ByteBuffer&)>&& write_callback);
|
void add_sys_file(String&&, Function<ByteBuffer(ProcFSInode&)>&& read_callback, Function<ssize_t(ProcFSInode&, const ByteBuffer&)>&& write_callback);
|
||||||
void add_sys_bool(String&&, bool*, Function<void()>&& notify_callback = nullptr);
|
void add_sys_bool(String&&, Lockable<bool>&, Function<void()>&& notify_callback = nullptr);
|
||||||
void add_sys_string(String&&, Lockable<String>&, Function<void()>&& notify_callback = nullptr);
|
void add_sys_string(String&&, Lockable<String>&, Function<void()>&& notify_callback = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -131,6 +131,7 @@ WSWindowManager::WSWindowManager()
|
||||||
: m_screen(WSScreen::the())
|
: m_screen(WSScreen::the())
|
||||||
, m_screen_rect(m_screen.rect())
|
, m_screen_rect(m_screen.rect())
|
||||||
, m_lock("WSWindowManager")
|
, m_lock("WSWindowManager")
|
||||||
|
, m_flash_flush(false)
|
||||||
{
|
{
|
||||||
#ifndef DEBUG_COUNTERS
|
#ifndef DEBUG_COUNTERS
|
||||||
(void)m_compose_count;
|
(void)m_compose_count;
|
||||||
|
@ -168,7 +169,7 @@ WSWindowManager::WSWindowManager()
|
||||||
m_wallpaper = GraphicsBitmap::load_from_file(m_wallpaper_path.resource(), m_screen_rect.size());
|
m_wallpaper = GraphicsBitmap::load_from_file(m_wallpaper_path.resource(), m_screen_rect.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcFS::the().add_sys_bool("wm_flash_flush", &m_flash_flush);
|
ProcFS::the().add_sys_bool("wm_flash_flush", m_flash_flush);
|
||||||
ProcFS::the().add_sys_string("wm_wallpaper", m_wallpaper_path, [this] {
|
ProcFS::the().add_sys_string("wm_wallpaper", m_wallpaper_path, [this] {
|
||||||
LOCKER(m_wallpaper_path.lock());
|
LOCKER(m_wallpaper_path.lock());
|
||||||
m_wallpaper = GraphicsBitmap::load_from_file(m_wallpaper_path.resource(), m_screen_rect.size());
|
m_wallpaper = GraphicsBitmap::load_from_file(m_wallpaper_path.resource(), m_screen_rect.size());
|
||||||
|
@ -441,7 +442,6 @@ void WSWindowManager::compose()
|
||||||
if (any_window_contains_rect(dirty_rect)) {
|
if (any_window_contains_rect(dirty_rect)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//dbgprintf("Repaint root %d,%d %dx%d\n", dirty_rect.x(), dirty_rect.y(), dirty_rect.width(), dirty_rect.height());
|
|
||||||
LOCKER(m_wallpaper_path.lock());
|
LOCKER(m_wallpaper_path.lock());
|
||||||
if (!m_wallpaper)
|
if (!m_wallpaper)
|
||||||
m_back_painter->fill_rect(dirty_rect, m_background_color);
|
m_back_painter->fill_rect(dirty_rect, m_background_color);
|
||||||
|
@ -472,7 +472,8 @@ void WSWindowManager::compose()
|
||||||
}
|
}
|
||||||
draw_cursor();
|
draw_cursor();
|
||||||
|
|
||||||
if (m_flash_flush) {
|
|
||||||
|
if (m_flash_flush.lock_and_copy()) {
|
||||||
for (auto& rect : dirty_rects)
|
for (auto& rect : dirty_rects)
|
||||||
m_front_painter->fill_rect(rect, Color::Yellow);
|
m_front_painter->fill_rect(rect, Color::Yellow);
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,6 +110,6 @@ private:
|
||||||
|
|
||||||
mutable Lock m_lock;
|
mutable Lock m_lock;
|
||||||
|
|
||||||
bool m_flash_flush { false };
|
Lockable<bool> m_flash_flush;
|
||||||
bool m_buffers_are_flipped { false };
|
bool m_buffers_are_flipped { false };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue