mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 16:38:10 +00:00
WindowServer: Port threading to LibThread
This commit is contained in:
parent
1ac7fedefe
commit
8d59b10022
5 changed files with 43 additions and 53 deletions
|
@ -9,26 +9,31 @@
|
|||
#include <unistd.h>
|
||||
|
||||
WSCPUMonitor::WSCPUMonitor()
|
||||
: m_thread([this] {
|
||||
monitor();
|
||||
return 0;
|
||||
})
|
||||
{
|
||||
create_thread([](void* context) -> int {
|
||||
auto& monitor = *(WSCPUMonitor*)context;
|
||||
for (;;) {
|
||||
static unsigned last_busy;
|
||||
static unsigned last_idle;
|
||||
unsigned busy;
|
||||
unsigned idle;
|
||||
monitor.get_cpu_usage(busy, idle);
|
||||
unsigned busy_diff = busy - last_busy;
|
||||
unsigned idle_diff = idle - last_idle;
|
||||
last_busy = busy;
|
||||
last_idle = idle;
|
||||
float cpu = (float)busy_diff / (float)(busy_diff + idle_diff);
|
||||
monitor.m_cpu_history.enqueue(cpu);
|
||||
monitor.m_dirty = true;
|
||||
sleep(1);
|
||||
}
|
||||
},
|
||||
this);
|
||||
m_thread.start();
|
||||
}
|
||||
|
||||
void WSCPUMonitor::monitor()
|
||||
{
|
||||
for (;;) {
|
||||
static unsigned last_busy;
|
||||
static unsigned last_idle;
|
||||
unsigned busy;
|
||||
unsigned idle;
|
||||
get_cpu_usage(busy, idle);
|
||||
unsigned busy_diff = busy - last_busy;
|
||||
unsigned idle_diff = idle - last_idle;
|
||||
last_busy = busy;
|
||||
last_idle = idle;
|
||||
float cpu = (float)busy_diff / (float)(busy_diff + idle_diff);
|
||||
m_cpu_history.enqueue(cpu);
|
||||
m_dirty = true;
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
void WSCPUMonitor::get_cpu_usage(unsigned& busy, unsigned& idle)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue