MOS Source Code
Loading...
Searching...
No Matches
task_types.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
8#include "mos/tasks/wait.hpp"
9
10#include <abi-bits/signal.h>
11#include <mos/allocator.hpp>
14#include <mos/list.hpp>
15#include <mos/shared_ptr.hpp>
16#include <mos/string.hpp>
18#include <mos/type_utils.hpp>
19
21
26
32
33struct Thread;
34
40
41struct fd_type
42{
44 FDFlags flags;
45};
46
47inline const fd_type nullfd{ nullptr, FD_FLAGS_NONE };
48
49#define PROCESS_MAGIC_PROC MOS_FOURCC('P', 'R', 'O', 'C')
50#define THREAD_MAGIC_THRD MOS_FOURCC('T', 'H', 'R', 'D')
51
52struct Process : mos::NamedType<"Process">
53{
55
56 public:
57 explicit Process(Private, Process *parent, mos::string_view name);
58 ~Process();
59
66
67 bool exited;
69
71
74
77
79
81
82 public:
83 static inline bool IsValid(const Process *process)
84 {
85 if (const auto ptr = process)
86 return ptr->magic == PROCESS_MAGIC_PROC;
87 else
88 return false;
89 }
90
91 public:
93 {
94 return mos::create<Process>(Private(), parent, name);
95 }
96
98 {
99 if (!Process::IsValid(process))
100 return stream << "[invalid]";
101
102 return stream << fmt("[p{}:{}]", process->pid, process->name.value_or("<no name>"));
103 }
104};
105
112
113struct Thread : mos::NamedType<"Thread">
114{
125
127
129
131
132 ~Thread();
133
134 static bool IsValid(const Thread *thread)
135 {
136 if (auto ptr = thread; ptr)
137 return ptr->magic == THREAD_MAGIC_THRD;
138 else
139 return false;
140 }
141
143 {
144 if (!Thread::IsValid(thread))
145 return stream << "[invalid]";
146
147 return stream << fmt("[t{}:{}]", thread->tid, thread->name.value_or("<no name>"));
148 }
149};
150
#define MOS_PROCESS_MAX_OPEN_FILES
Definition autoconf.h:26
basic_string_view< Char > value_or(basic_string_view< Char > other) const
Definition string.hpp:294
FDFlag
Definition fs_types.h:47
@ FD_FLAGS_NONE
Definition fs_types.h:48
list_node_t list_head
A linked list head.
Definition list.hpp:23
#define THREAD_MAGIC_THRD
thread_mode
const fd_type nullfd
#define PROCESS_MAGIC_PROC
@ THREAD_MODE_KERNEL
@ THREAD_MODE_USER
basic_string_view< char > string_view
T * create(Args &&...args)
Definition allocator.hpp:12
mos::basic_string< char > string
Definition string.hpp:395
thread_state_t
Definition platform.hpp:43
mos::shared_ptr< T > ptr
#define SIGNAL_MAX_N
Definition io.hpp:39
Thread * main_thread
mos::string name
as_linked_list
node in the parent's children list
static Process * New(Process *parent, mos::string_view name)
bool exited
true if the process has exited
platform_process_options_t platform_options
platform per-process flags
process_signal_info_t signal_info
signal handling info
dentry_t * working_directory
mos::list< Thread * > thread_list
static bool IsValid(const Process *process)
const u32 magic
Process * parent
friend mos::SyslogStreamWriter operator<<(mos::SyslogStreamWriter stream, const Process *process)
Process(Private, Process *parent, mos::string_view name)
Definition process.cpp:68
list_head children
list of children processes
MMContext * mm
fd_type files[MOS_PROCESS_MAX_OPEN_FILES]
pid_t pid
u32 exit_status
exit status
platform_thread_options_t platform_options
platform-specific thread options
thread_mode mode
user-mode thread or kernel-mode
mos::string name
Process * owner
as_linked_list
node in the process's thread list
friend mos::SyslogStreamWriter operator<<(mos::SyslogStreamWriter stream, const Thread *thread)
static bool IsValid(const Thread *thread)
downwards_stack_t u_stack
user-mode stack
waitlist_t waiters
list of threads waiting for this thread to exit
downwards_stack_t k_stack
kernel-mode stack
~Thread()
Definition thread.cpp:32
spinlock_t state_lock
protects the thread state
tid_t tid
thread_state_t state
thread state
thread_signal_info_t signal_info
FDFlags flags
sigaction_t handlers[SIGNAL_MAX_N]
signal handlers
waitlist_t sigchild_waitlist
the parent is waiting for a child to exit, if not empty
list_head pending
list of pending signals
sigset_t mask
pending signals mask
#define fmt(_fmt,...)
Definition syslog.hpp:161
unsigned int u32
Definition types.h:17
s32 tid_t
Definition types.h:75
s32 pid_t
Definition types.h:74
#define MOS_ENUM_FLAGS(enum, flags)
Definition types.hpp:236