aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/include')
-rw-r--r--src/kernel/include/process.h18
-rw-r--r--src/kernel/include/thread.h11
2 files changed, 20 insertions, 9 deletions
diff --git a/src/kernel/include/process.h b/src/kernel/include/process.h
index 1b4012f..def3397 100644
--- a/src/kernel/include/process.h
+++ b/src/kernel/include/process.h
@@ -56,23 +56,29 @@ typedef struct process {
struct process *parent;
struct process *next_child;
struct process *children;
+
+ mutex_t lock;
} process_t;
typedef void* proc_entry_t;
// ---- Process creation, deletion, waiting, etc.
-// Simple semantics : when a process exits, all its ressources are freed immediately
-// except for the process_t that remains attached to the parent process until it does
-// a wait() and acknowleges the process' ending
-// When a process exits, all the children are orphaned and nobody can wait on them anymore,
-// which is a bad thing : a user process must always wait for all its children !
+// Simple semantics :
+// - When a process exits, all its ressources are freed immediately
+// except for the process_t that remains attached to the parent process until it does
+// a wait() and acknowleges the process' ending
+// - When a process exits, if it has living children then they are terminated too. (a process
+// is seen as a "virtual machine", and spawning sub-process is seen as "sharing some ressources
+// it was allocated to create a new VM", therefore removing the ressource allocated to the
+// parent implies removing the ressource from its children too)
process_t *current_process();
process_t *new_process(process_t *parent);
bool start_process(process_t *p, proc_entry_t entry); // maps a region for user stack
-void process_exit(process_t *p, int status, int exit_code); // exit current process
+void process_exit(process_t *p, int status, int exit_code); // exit specified process (must not be current process)
+void current_process_exit(int status, int exit_code);
bool process_new_thread(process_t *p, proc_entry_t entry, void* sp);
void process_thread_deleted(thread_t *t); // called by threading code when a thread exits
diff --git a/src/kernel/include/thread.h b/src/kernel/include/thread.h
index 163045d..2d385ea 100644
--- a/src/kernel/include/thread.h
+++ b/src/kernel/include/thread.h
@@ -5,6 +5,7 @@
#include <region.h>
#include <idt.h>
+#define T_STATE_LOADING 0
#define T_STATE_RUNNING 1
#define T_STATE_PAUSED 2
#define T_STATE_FINISHED 3
@@ -34,21 +35,25 @@ typedef struct thread {
struct thread *next_in_queue;
struct thread *next_in_proc;
+
+ void* waiting_on;
+ bool must_exit;
} thread_t;
typedef void (*entry_t)(void*);
void threading_setup(entry_t cont, void* data); // never returns
-thread_t *new_thread(entry_t entry, void* data); // thread is PAUSED, and must be resume_thread'ed
+thread_t *new_thread(entry_t entry, void* data); // thread is PAUSED, and must be started with start_thread
+void start_thread(thread_t *t);
extern thread_t *current_thread;
void yield();
-void pause();
void exit();
void usleep(int usecs);
+bool wait_on(void* x); // true : resumed normally, false : resumed because thread was killed, or someone else already waiting
-bool resume_thread(thread_t *thread);
+bool resume_on(void* x);
void kill_thread(thread_t *thread); // cannot be called for current thread
// Kernel critical sections