lock: merge spinlock and mtx locks into one
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
3e5abada9b
commit
2076f1dae1
32 changed files with 158 additions and 169 deletions
|
|
@ -7,24 +7,24 @@
|
|||
static struct {
|
||||
struct thread *head;
|
||||
struct thread *tail;
|
||||
spinlock_t lock;
|
||||
lock_t lock;
|
||||
} sched_queue;
|
||||
|
||||
void sched_add_thread(struct thread *t)
|
||||
{
|
||||
spinlock_acquire(&sched_queue.lock);
|
||||
spin_lock(&sched_queue.lock);
|
||||
t->next = NULL;
|
||||
if (sched_queue.tail)
|
||||
sched_queue.tail->next = t;
|
||||
sched_queue.tail = t;
|
||||
if (!sched_queue.head)
|
||||
sched_queue.head = t;
|
||||
spinlock_release(&sched_queue.lock);
|
||||
spin_unlock(&sched_queue.lock);
|
||||
}
|
||||
|
||||
void sched_remove_thread(struct thread *del)
|
||||
{
|
||||
spinlock_acquire(&sched_queue.lock);
|
||||
spin_lock(&sched_queue.lock);
|
||||
struct thread *t = sched_queue.head;
|
||||
struct thread *p = NULL;
|
||||
while (t) {
|
||||
|
|
@ -43,12 +43,12 @@ void sched_remove_thread(struct thread *del)
|
|||
p = t;
|
||||
t = t->next;
|
||||
}
|
||||
spinlock_release(&sched_queue.lock);
|
||||
spin_unlock(&sched_queue.lock);
|
||||
}
|
||||
|
||||
static struct thread *dequeue_thread()
|
||||
{
|
||||
spinlock_acquire(&sched_queue.lock);
|
||||
spin_lock(&sched_queue.lock);
|
||||
struct thread *t = sched_queue.head;
|
||||
if (t) {
|
||||
sched_queue.head = t->next;
|
||||
|
|
@ -58,7 +58,7 @@ static struct thread *dequeue_thread()
|
|||
} else {
|
||||
t = tls_get()->idle_thread;
|
||||
}
|
||||
spinlock_release(&sched_queue.lock);
|
||||
spin_unlock(&sched_queue.lock);
|
||||
return t;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ tid_t alloc_tid()
|
|||
|
||||
void thread_mmap(struct thread *thread, paddr_t p, vaddr_t v, size_t len, u64 flags)
|
||||
{
|
||||
spinlock_acquire(&thread->mem_lock);
|
||||
spin_lock(&thread->mem_lock);
|
||||
page_map(thread->pgd, p, v, len, flags, &thread->memmap);
|
||||
spinlock_release(&thread->mem_lock);
|
||||
spin_unlock(&thread->mem_lock);
|
||||
}
|
||||
|
||||
void *thread_alloc(struct thread *thread, size_t size)
|
||||
|
|
@ -31,8 +31,8 @@ void *thread_alloc(struct thread *thread, size_t size)
|
|||
|
||||
static int copy_parent_memmap(struct thread *child, struct thread *parent)
|
||||
{
|
||||
spinlock_acquire(&parent->mem_lock);
|
||||
spinlock_acquire(&child->mem_lock);
|
||||
spin_lock(&parent->mem_lock);
|
||||
spin_lock(&child->mem_lock);
|
||||
|
||||
rbnode_t *node = parent->memmap.root;
|
||||
if (!node)
|
||||
|
|
@ -46,8 +46,8 @@ static int copy_parent_memmap(struct thread *child, struct thread *parent)
|
|||
|
||||
void *pages = kalloc(area->len, ALLOC_USER);
|
||||
if (!pages) {
|
||||
spinlock_release(&child->mem_lock);
|
||||
spinlock_release(&parent->mem_lock);
|
||||
spin_unlock(&child->mem_lock);
|
||||
spin_unlock(&parent->mem_lock);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
|
|
@ -58,8 +58,8 @@ static int copy_parent_memmap(struct thread *child, struct thread *parent)
|
|||
}
|
||||
|
||||
done:
|
||||
spinlock_release(&child->mem_lock);
|
||||
spinlock_release(&parent->mem_lock);
|
||||
spin_unlock(&child->mem_lock);
|
||||
spin_unlock(&parent->mem_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -119,14 +119,14 @@ struct thread *thread_fork(struct thread *parent)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
spinlock_acquire(&parent->fd_lock);
|
||||
spin_lock(&parent->fd_lock);
|
||||
if (parent->fd_array_size) {
|
||||
child->fd_array_size = parent->fd_array_size;
|
||||
child->fdt = kalloc(child->fd_array_size * sizeof(struct file), ALLOC_KERN);
|
||||
if (child->fdt)
|
||||
memcpy(child->fdt, parent->fdt, child->fd_array_size * sizeof(struct file));
|
||||
}
|
||||
spinlock_release(&parent->fd_lock);
|
||||
spin_unlock(&parent->fd_lock);
|
||||
|
||||
child->group = child->tid;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue