Skip to content

Commit

Permalink
Get rid of redundant unlock_pids()
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Miller committed Oct 12, 2023
1 parent 65a7322 commit 42eab31
Show file tree
Hide file tree
Showing 18 changed files with 88 additions and 74 deletions.
2 changes: 1 addition & 1 deletion app/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static void ios_handle_exit(struct task *task, int code) {
// pid should be saved now since task would be freed
pid_t pid = task->pid;
// if(pids_lock.pid == pid)
// unlock_pids(&pids_lock);
// unlock(&pids_lock);
// while((critical_region_count(task)) || (locks_held_count(task))) { // Wait for now, task is in one or more critical sections, and/or has locks
// nanosleep(&lock_pause, NULL);
// }
Expand Down
4 changes: 2 additions & 2 deletions app/UpgradeRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ - (void)viewDidLoad {

complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
current = pid_get_task(1); // pray
unlock_pids(&pids_lock);
unlock(&pids_lock);
self.terminal = [Terminal createPseudoTerminal:&self->_tty];
current = NULL;

Expand Down Expand Up @@ -76,7 +76,7 @@ - (void)processExited:(NSNotification *)notif {
} else {
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
current = pid_get_task(1); // pray
unlock_pids(&pids_lock);
unlock(&pids_lock);
FsUpdateRepositories();
current = NULL;
[self showAlertWithTitle:@"Upgrade succeeded" message:@""];
Expand Down
2 changes: 1 addition & 1 deletion app/UserPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ - (BOOL)validateShouldEnableExtraLocking:(id *)value error:(NSError **)error {
if(doEnableExtraLocking == true) { // This needs to be the opposite of what you would expect because of reasons. -mke
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
zero_critical_regions_count();
unlock_pids(&pids_lock);
unlock(&pids_lock);
}
return [*value isKindOfClass:NSNumber.class];
}
Expand Down
4 changes: 2 additions & 2 deletions fs/proc/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ static struct task *proc_get_task(struct proc_entry *entry) {
complex_lockt(&pids_lock, 1, __FILE__, __LINE__);
struct task *task = pid_get_task(entry->pid);
if (task == NULL)
unlock_pids(&pids_lock);
unlock(&pids_lock);
return task;
}
static void proc_put_task(struct task *UNUSED(task)) {
unlock_pids(&pids_lock);
unlock(&pids_lock);
}

static int proc_pid_stat_show(struct proc_entry *entry, struct proc_data *buf) {
Expand Down
2 changes: 1 addition & 1 deletion fs/proc/root.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ static bool proc_root_readdir(struct proc_entry *UNUSED(entry), unsigned long *i
do {
pid++;
} while (pid <= MAX_PID && pid_get_task(pid) == NULL);
//unlock_pids(&pids_lock);
//unlock(&pids_lock);
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
if (pid > MAX_PID) {
return false;
Expand Down
10 changes: 5 additions & 5 deletions fs/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ int tty_open(struct tty *tty, struct fd *fd) {
if (tty->session == 0 && current->group->sid == current->pid)
tty_set_controlling(current->group, tty);
unlock(&tty->lock);
unlock_pids(&pids_lock);
unlock(&pids_lock);
}

return 0;
Expand Down Expand Up @@ -443,12 +443,12 @@ static ssize_t tty_read(struct fd *fd, void *buf, size_t bufsize) {
complex_lockt(&pids_lock, 1, __FILE__, __LINE__); // MKEMKE
lock(&tty->lock, 0);
if (tty->hung_up) {
unlock_pids(&pids_lock);
unlock(&pids_lock);
goto error;
}

pid_t_ current_pgid = current->group->pgid;
unlock_pids(&pids_lock);
unlock(&pids_lock);
err = tty_signal_if_background(tty, current_pgid, SIGTTIN_);
if (err < 0)
goto error;
Expand Down Expand Up @@ -653,7 +653,7 @@ static int tiocsctty(struct tty *tty, int force) {

tty_set_controlling(current->group, tty);
out:
unlock_pids(&pids_lock);
unlock(&pids_lock);
return err;
}

Expand Down Expand Up @@ -743,7 +743,7 @@ static int tty_ioctl(struct fd *fd, int cmd, void *arg) {
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
lock(&tty->lock, 0);
pid_t_ sid = current->group->sid;
unlock_pids(&pids_lock);
unlock(&pids_lock);
if (!tty_is_current(tty) || sid != tty->session) {
err = _ENOTTY;
break;
Expand Down
1 change: 0 additions & 1 deletion jit/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ void jit_free(struct jit *jit) {
}
}
jit_free_jetsam(jit);
unlock(&jit->lock);
free(jit->page_hash);
free(jit->hash);
write_lock(&jit->jetsam_lock);
Expand Down
4 changes: 2 additions & 2 deletions kernel/calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,14 @@ void handle_interrupt(int interrupt) {
.sig = SIGTRAP_,
.code = SI_KERNEL_,
});
unlock_pids(&pids_lock);
unlock(&pids_lock);
} else if (interrupt == INT_DEBUG) {
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
send_signal(current, SIGTRAP_, (struct siginfo_) {
.sig = SIGTRAP_,
.code = TRAP_TRACE_,
});
unlock_pids(&pids_lock);
unlock(&pids_lock);
} else if (interrupt != INT_TIMER) {
printk("WARNING: %d(%s) unhandled interrupt %d\n", current->pid, current->comm, interrupt);
sys_exit(interrupt);
Expand Down
2 changes: 1 addition & 1 deletion kernel/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ int __do_execve(const char *file, struct exec_args argv, struct exec_args envp)
.kill.pid = current->pid,
.kill.uid = current->uid,
});
unlock_pids(&pids_lock);
unlock(&pids_lock);
}

return 0;
Expand Down
10 changes: 5 additions & 5 deletions kernel/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ noreturn void do_exit(int status) {
if(current != leader)
task_destroy(current);

unlock_pids(&pids_lock);
unlock(&pids_lock);
//atomic_l_unlockf();

EXIT:pthread_exit(NULL);
Expand Down Expand Up @@ -235,7 +235,7 @@ noreturn void do_exit_group(int status) {
notify(&task->group->stopped_cond);
}

unlock_pids(&pids_lock);
unlock(&pids_lock);
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
unlock(&group->lock);
if(current->pid <= MAX_PID) // abort if crazy. -mke
Expand Down Expand Up @@ -372,7 +372,7 @@ static bool reap_if_zombie(struct task *task, struct siginfo_ *info_out, struct
// &pids_lock is locked already at this point
//complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
task_destroy(task);
//unlock_pids(&pids_lock);
//unlock(&pids_lock);

return true;
}
Expand Down Expand Up @@ -486,12 +486,12 @@ int do_wait(int idtype, pid_t_ id, struct siginfo_ *info, struct rusage_ *rusage
info->sig = SIGCHLD_;
found_something:
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
unlock_pids(&pids_lock);
unlock(&pids_lock);
return 0;

error:
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
unlock_pids(&pids_lock);
unlock(&pids_lock);
return err;
}

Expand Down
4 changes: 2 additions & 2 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static int copy_task(struct task *task, dword_t flags, addr_t stack, addr_t ptid
}
list_add(&task->group->threads, &task->group_links);
unlock(&old_group->lock);
unlock_pids(&pids_lock);
unlock(&pids_lock);

if (flags & CLONE_SETTLS_) {
err = task_set_thread_area(task, tls_addr);
Expand Down Expand Up @@ -162,7 +162,7 @@ dword_t sys_clone(dword_t flags, addr_t stack, addr_t ptid, addr_t tls, addr_t c
// could cause leaks
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
task_destroy(task);
unlock_pids(&pids_lock);
unlock(&pids_lock);

return err;
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/futex.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ int_t sys_get_robust_list(pid_t_ pid, addr_t robust_list_ptr, addr_t len_ptr) {

complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
struct task *task = pid_get_task(pid);
unlock_pids(&pids_lock);
unlock(&pids_lock);
if (task != current)
return _EPERM;

Expand Down
2 changes: 1 addition & 1 deletion kernel/getset.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pid_t_ sys_getppid() {
ppid = current->parent->pid;
else
ppid = 0;
unlock_pids(&pids_lock);
unlock(&pids_lock);
return ppid;
}

Expand Down
12 changes: 6 additions & 6 deletions kernel/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ dword_t sys_setpgid(pid_t_ id, pid_t_ pgid) {

err = 0;
out:
unlock_pids(&pids_lock);
unlock(&pids_lock);
return err;
}

Expand All @@ -66,11 +66,11 @@ pid_t_ sys_getpgid(pid_t_ pid) {
if (pid != 0)
task = pid_get_task(pid);
if (!task) {
unlock_pids(&pids_lock);
unlock(&pids_lock);
return _ESRCH;
}
pid = task->group->pgid;
unlock_pids(&pids_lock);
unlock(&pids_lock);
return pid;
}
pid_t_ sys_getpgrp() {
Expand Down Expand Up @@ -99,7 +99,7 @@ pid_t_ task_setsid(struct task *task) {
struct tgroup *group = task->group;
pid_t_ new_sid = group->leader->pid;
if (group->pgid == new_sid || group->sid == new_sid) {
unlock_pids(&pids_lock);
unlock(&pids_lock);
return _EPERM;
}

Expand All @@ -112,7 +112,7 @@ pid_t_ task_setsid(struct task *task) {
list_add(&pid->pgroup, &group->pgroup);
group->pgid = new_sid;

unlock_pids(&pids_lock);
unlock(&pids_lock);
return new_sid;
}

Expand All @@ -125,7 +125,7 @@ dword_t sys_getsid() {
STRACE("getsid()");
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
pid_t_ sid = current->group->sid;
unlock_pids(&pids_lock);
unlock(&pids_lock);
return sid;
}

2 changes: 1 addition & 1 deletion kernel/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ int_t sys_sched_getaffinity(pid_t_ pid, dword_t cpusetsize, addr_t cpuset_addr)
if (pid != 0) {
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
struct task *task = pid_get_task(pid);
unlock_pids(&pids_lock);
unlock(&pids_lock);
if (task == NULL)
return _ESRCH;
}
Expand Down
14 changes: 7 additions & 7 deletions kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ int send_group_signal(dword_t pgid, int sig, struct siginfo_ info) {
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
struct pid *pid = pid_get(pgid);
if (pid == NULL) {
unlock_pids(&pids_lock);
unlock(&pids_lock);
return _ESRCH;
}
struct tgroup *tgroup;
list_for_each_entry(&pid->pgroup, tgroup, pgroup) {
send_signal(tgroup->leader, sig, info);
}
unlock_pids(&pids_lock);
unlock(&pids_lock);
return 0;
}

Expand Down Expand Up @@ -397,7 +397,7 @@ void receive_signals() { // Should this function have a check for critical_regi
notify(&current->parent->group->child_exit);
// TODO add siginfo
send_signal(current->parent, current->group->leader->exit_signal, SIGINFO_NIL);
unlock_pids(&pids_lock);
unlock(&pids_lock);
}
}
}
Expand Down Expand Up @@ -749,7 +749,7 @@ static int kill_task(struct task *task, dword_t sig) {
static int kill_group(pid_t_ pgid, dword_t sig) {
struct pid *pid = pid_get(pgid);
if (pid == NULL) {
unlock_pids(&pids_lock);
unlock(&pids_lock);
return _ESRCH;
}
struct tgroup *tgroup;
Expand Down Expand Up @@ -796,20 +796,20 @@ static int do_kill(pid_t_ pid, dword_t sig, pid_t_ tgid) {
} else {
struct task *task = pid_get_task(pid);
if (task == NULL) {
unlock_pids(&pids_lock);
unlock(&pids_lock);
return _ESRCH;
}

// If tgid is nonzero, it must be correct
if (tgid != 0 && task->tgid != tgid) {
unlock_pids(&pids_lock);
unlock(&pids_lock);
return _ESRCH;
}

err = kill_task(task, sig);
}

unlock_pids(&pids_lock);
unlock(&pids_lock);
return err;
}

Expand Down
10 changes: 5 additions & 5 deletions kernel/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ dword_t get_count_of_blocked_tasks(void) {
}
}
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
unlock_pids(&pids_lock);
unlock(&pids_lock);
return res;
}

Expand All @@ -100,7 +100,7 @@ dword_t get_count_of_alive_tasks(void) {
list_for_each(&alive_pids_list, item) {
res++;
}
unlock_pids(&pids_lock);
unlock(&pids_lock);
return res;
}

Expand All @@ -118,7 +118,7 @@ struct task *task_create_(struct task *parent) {

struct task *task = malloc(sizeof(struct task));
if (task == NULL) {
unlock_pids(&pids_lock);
unlock(&pids_lock);
return NULL;
}
*task = (struct task) {};
Expand All @@ -135,7 +135,7 @@ struct task *task_create_(struct task *parent) {
task->parent = parent;
list_add(&parent->children, &task->siblings);
}
unlock_pids(&pids_lock);
unlock(&pids_lock);

task->pending = 0;
list_init(&task->queue);
Expand Down Expand Up @@ -212,7 +212,7 @@ void task_destroy(struct task *task) {
}

if(Ishould)
unlock_pids(&pids_lock);
unlock(&pids_lock);

free(task);
}
Expand Down
Loading

0 comments on commit 42eab31

Please sign in to comment.