mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
126 lines
2.2 KiB
C++
126 lines
2.2 KiB
C++
#include "process.h"
|
|
#include "scheduler.h"
|
|
|
|
|
|
bool
|
|
process::wait_on_signal(uint64_t sigmask)
|
|
{
|
|
waiting = process_wait::signal;
|
|
waiting_info = sigmask;
|
|
flags -= process_flags::ready;
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
process::wait_on_child(uint32_t pid)
|
|
{
|
|
waiting = process_wait::child;
|
|
waiting_info = pid;
|
|
flags -= process_flags::ready;
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
process::wait_on_time(uint64_t time)
|
|
{
|
|
waiting = process_wait::time;
|
|
waiting_info = time;
|
|
flags -= process_flags::ready;
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
process::wait_on_send(uint32_t target_id)
|
|
{
|
|
scheduler &s = scheduler::get();
|
|
process *target = s.get_process_by_id(target_id);
|
|
if (!target) return false;
|
|
|
|
if (!target->wake_on_receive(this)) {
|
|
waiting = process_wait::send;
|
|
waiting_info = target_id;
|
|
flags -= process_flags::ready;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
process::wait_on_receive(uint32_t source_id)
|
|
{
|
|
scheduler &s = scheduler::get();
|
|
process *source = s.get_process_by_id(source_id);
|
|
if (!source) return false;
|
|
|
|
if (!source->wake_on_send(this)) {
|
|
waiting = process_wait::receive;
|
|
waiting_info = source_id;
|
|
flags -= process_flags::ready;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool
|
|
process::wake_on_signal(int signal)
|
|
{
|
|
if (waiting != process_wait::signal ||
|
|
(waiting_info & (1 << signal)) == 0)
|
|
return false;
|
|
|
|
waiting = process_wait::none;
|
|
flags += process_flags::ready;
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
process::wake_on_child(process *child)
|
|
{
|
|
if (waiting != process_wait::child ||
|
|
(waiting_info && waiting_info != child->pid))
|
|
return false;
|
|
|
|
waiting = process_wait::none;
|
|
flags += process_flags::ready;
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
process::wake_on_time(uint64_t now)
|
|
{
|
|
if (waiting != process_wait::time ||
|
|
waiting_info > now)
|
|
return false;
|
|
|
|
waiting = process_wait::none;
|
|
flags += process_flags::ready;
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
process::wake_on_send(process *target)
|
|
{
|
|
if (waiting != process_wait::send ||
|
|
waiting_info != target->pid)
|
|
return false;
|
|
|
|
waiting = process_wait::none;
|
|
flags += process_flags::ready;
|
|
return true;
|
|
}
|
|
|
|
|
|
bool
|
|
process::wake_on_receive(process *source)
|
|
{
|
|
if (waiting != process_wait::receive ||
|
|
waiting_info != source->pid)
|
|
return false;
|
|
|
|
waiting = process_wait::none;
|
|
flags += process_flags::ready;
|
|
return true;
|
|
}
|
|
|