Implement userspace TLS, remove RW Locks
This commit is contained in:
@@ -4,13 +4,12 @@
|
||||
#include <mm/pmm.h>
|
||||
#include <proc/proc.h>
|
||||
#include <proc/procgroup.h>
|
||||
#include <sync/rw_spin_lock.h>
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/debug.h>
|
||||
#include <sys/mm.h>
|
||||
|
||||
static struct rb_node_link* procgroup_tree = NULL;
|
||||
static rw_spin_lock_t procgroup_tree_lock = RW_SPIN_LOCK_INIT;
|
||||
static spin_lock_t procgroup_tree_lock = SPIN_LOCK_INIT;
|
||||
static atomic_int pgids = 0;
|
||||
|
||||
uintptr_t procgroup_map (struct procgroup* procgroup, uintptr_t vaddr, size_t pages, uint32_t flags,
|
||||
@@ -143,10 +142,10 @@ struct procgroup* procgroup_create (void) {
|
||||
procgroup->pd.cr3_paddr = mm_alloc_user_pd_phys ();
|
||||
procgroup->map_base = PROC_MAP_BASE;
|
||||
|
||||
rw_spin_write_lock (&procgroup_tree_lock, &ctxpgtr);
|
||||
spin_lock (&procgroup_tree_lock, &ctxpgtr);
|
||||
rbtree_insert (struct procgroup, &procgroup_tree, &procgroup->procgroup_tree_link,
|
||||
procgroup_tree_link, pgid);
|
||||
rw_spin_write_unlock (&procgroup_tree_lock, &ctxpgtr);
|
||||
spin_unlock (&procgroup_tree_lock, &ctxpgtr);
|
||||
|
||||
return procgroup;
|
||||
}
|
||||
@@ -160,7 +159,6 @@ void procgroup_attach (struct procgroup* procgroup, struct proc* proc) {
|
||||
rbtree_insert (struct proc, &procgroup->memb_proc_tree, &proc->procgroup_memb_tree_link,
|
||||
procgroup_memb_tree_link, pid);
|
||||
atomic_fetch_add (&procgroup->refs, 1);
|
||||
DEBUG ("procgrpup attach PID %d to PGID %d\n", proc->pid, procgroup->pgid);
|
||||
|
||||
spin_unlock (&proc->lock, &ctxpr);
|
||||
spin_unlock (&procgroup->lock, &ctxpg);
|
||||
@@ -174,19 +172,18 @@ void procgroup_detach (struct procgroup* procgroup, struct proc* proc) {
|
||||
|
||||
rbtree_delete (&procgroup->memb_proc_tree, &proc->procgroup_memb_tree_link);
|
||||
int refs = atomic_fetch_sub (&procgroup->refs, 1);
|
||||
DEBUG ("procgrpup detach PID %d to PGID %d\n", proc->pid, procgroup->pgid);
|
||||
|
||||
spin_unlock (&proc->lock, &ctxpr);
|
||||
spin_unlock (&procgroup->lock, &ctxpg);
|
||||
|
||||
if (refs == 1) {
|
||||
rw_spin_write_lock (&procgroup_tree_lock, &ctxpgtr);
|
||||
spin_lock (&procgroup_tree_lock, &ctxpgtr);
|
||||
spin_lock (&procgroup->lock, &ctxpg);
|
||||
|
||||
rbtree_delete (&procgroup_tree, &procgroup->procgroup_tree_link);
|
||||
|
||||
spin_unlock (&procgroup->lock, &ctxpg);
|
||||
rw_spin_write_unlock (&procgroup_tree_lock, &ctxpgtr);
|
||||
spin_unlock (&procgroup_tree_lock, &ctxpgtr);
|
||||
|
||||
/* delete resources */
|
||||
struct rb_node_link* rnode;
|
||||
@@ -214,6 +211,8 @@ void procgroup_detach (struct procgroup* procgroup, struct proc* proc) {
|
||||
|
||||
pmm_free (procgroup->pd.cr3_paddr, 1);
|
||||
|
||||
free (procgroup->tls.tls_tmpl);
|
||||
|
||||
free (procgroup);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user