Implement proc_spawn_thread syscall, fix proc_resume and proc_suspend
All checks were successful
Build documentation / build-and-deploy (push) Successful in 35s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 35s
This commit is contained in:
@@ -7,36 +7,58 @@
|
||||
#include <sys/debug.h>
|
||||
|
||||
void proc_mutex_lock (struct proc* proc, struct proc_mutex* mutex) {
|
||||
while (atomic_flag_test_and_set_explicit (&mutex->flag, memory_order_acquire))
|
||||
proc_suspend (proc, &mutex->suspension_q);
|
||||
spin_lock_ctx_t ctxmt;
|
||||
|
||||
/* taken */
|
||||
try:
|
||||
spin_lock (&mutex->lock, &ctxmt);
|
||||
|
||||
mutex->owner = proc;
|
||||
if (!mutex->locked || mutex->owner == proc) {
|
||||
mutex->locked = true;
|
||||
mutex->owner = proc;
|
||||
spin_unlock (&mutex->lock, &ctxmt);
|
||||
return;
|
||||
}
|
||||
|
||||
spin_unlock (&mutex->lock, &ctxmt);
|
||||
|
||||
proc_suspend (proc, &mutex->suspension_q);
|
||||
|
||||
goto try;
|
||||
}
|
||||
|
||||
bool proc_mutex_unlock (struct proc* proc, struct proc_mutex* mutex) {
|
||||
if (mutex->owner != proc)
|
||||
return false;
|
||||
spin_lock_ctx_t ctxmt, ctxsq;
|
||||
|
||||
atomic_flag_clear_explicit (&mutex->flag, memory_order_release);
|
||||
spin_lock (&mutex->lock, &ctxmt);
|
||||
|
||||
if (mutex->owner != proc) {
|
||||
spin_unlock (&mutex->lock, &ctxmt);
|
||||
return false;
|
||||
}
|
||||
|
||||
spin_lock (&mutex->suspension_q.lock, &ctxsq);
|
||||
|
||||
struct proc* resumed_proc;
|
||||
struct rb_node_link* node;
|
||||
rbtree_first (&mutex->suspension_q.proc_tree, node);
|
||||
|
||||
while (node) {
|
||||
struct rb_node_link* next;
|
||||
rbtree_next (node, next);
|
||||
|
||||
if (node) {
|
||||
resumed_proc = rbtree_entry (node, struct proc, suspension_link);
|
||||
mutex->owner = resumed_proc;
|
||||
|
||||
spin_unlock (&mutex->suspension_q.lock, &ctxsq);
|
||||
spin_unlock (&mutex->lock, &ctxmt);
|
||||
proc_resume (resumed_proc);
|
||||
|
||||
node = next;
|
||||
return true;
|
||||
}
|
||||
|
||||
assert (mutex->suspension_q.proc_tree == NULL);
|
||||
spin_unlock (&mutex->suspension_q.lock, &ctxsq);
|
||||
|
||||
mutex->locked = false;
|
||||
mutex->owner = NULL;
|
||||
|
||||
spin_unlock (&mutex->lock, &ctxmt);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user