aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/include
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-03-04 11:51:30 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-03-04 11:51:30 +0100
commit503f176e001ddf15e6e32bc912cf10b5764bc23b (patch)
tree2595bc45e582df3ede9241c00656b65866301e38 /src/kernel/include
parent0934f9943ef7bdec8c2eee3ea31b5e0f1e8a3faf (diff)
downloadkogata-503f176e001ddf15e6e32bc912cf10b5764bc23b.tar.gz
kogata-503f176e001ddf15e6e32bc912cf10b5764bc23b.zip
Process exiting & thread termination. IMPORTANT NOTE FOLLOWS.
Threads may now communicate via wait_on(void* ressource) and resume_on (void* ressource). Previous pause() is replaced by wait_on(current_thread) and resume(thread) by resume_on(thread). wait_on(x) may return false, indicating that the reason for returning is NOT that resume_on(x) was called but something else happenned. Typically false indicates that the curent thread is being killed and must terminate its kernel-land processing as soon as possible.
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