Skip to content

Commit

Permalink
o More stability fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Miller committed Nov 26, 2023
1 parent 85bf265 commit e4fd38e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
6 changes: 1 addition & 5 deletions app/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,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_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);
// }

unlock(&pids_lock);
unlock(&task->general_lock);
dispatch_async(dispatch_get_main_queue(), ^{
Expand Down
18 changes: 10 additions & 8 deletions kernel/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,39 +232,40 @@ void die(const char *msg, ...) {

// fun little utility function
int current_pid(void) {
//modify_critical_region_counter(current, 1, __FILE__, __LINE__);
modify_critical_region_counter(current, 1, __FILE__, __LINE__);
if(current != NULL) {
if (current->exiting != true) {
//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
return current->pid;
} else {
//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
return -1;
}
}

//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
return -1;
}

int current_uid(void) {
//modify_critical_region_counter(current, 1, __FILE__, __LINE__);
modify_critical_region_counter(current, 1, __FILE__, __LINE__);
if(current != NULL) {
if (current->exiting != true) {
//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
return current->uid;
} else {
//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
return -1;
}
}

//modify_critical_region_counter(current, -1, __FILE__, __LINE__);
modify_critical_region_counter(current, -1, __FILE__, __LINE__);
return -1;
}

char * current_comm(void) {
static char comm[16];
modify_critical_region_counter(current, 1, __FILE__, __LINE__);
if(current != NULL) {
if(strcmp(current->comm, "")) {
strncpy(comm, current->comm, 16);
Expand All @@ -277,6 +278,7 @@ char * current_comm(void) {
return "";
}
}
modify_critical_region_counter(current, -1, __FILE__, __LINE__);

return "";
}
Expand Down
7 changes: 6 additions & 1 deletion kernel/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,13 @@ void task_destroy(struct task *task, int caller) {
unlock(&pids_lock);
}

retry:
// Free the task's resources.
free(task);
if (!critical_region_count(task)) {
free(task);
} else {
goto retry;
}
}

void run_at_boot(void) { // Stuff we run only once, at boot time.
Expand Down
7 changes: 5 additions & 2 deletions util/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ void modify_critical_region_counter(struct task *task, int value, __attribute__(
printk("ERROR: Attempt to decrement critical_region count to be negative, ignoring(%s:%d) (%d - %d) (%s:%d)\n", task->comm, task->pid, task->critical_region.count, value, file, line);
if(ilocked == true)
unlock(&task->general_lock);

pthread_mutex_unlock(&task->critical_region.lock);

return;
}

Expand Down Expand Up @@ -209,11 +212,11 @@ void sigusr1_handler(void) {
// Because sometimes we can't #include "kernel/task.h" -mke
unsigned critical_region_count(struct task *task) {
unsigned tmp = 0;
// pthread_mutex_lock(task->critical_region.lock); // This would make more
pthread_mutex_lock(&task->critical_region.lock); // This would make more
tmp = task->critical_region.count;
if(tmp > 1000) // Not likely
tmp = 0;
// pthread_mutex_unlock(task->critical_region.lock);
pthread_mutex_unlock(&task->critical_region.lock);

return tmp;
}
Expand Down

0 comments on commit e4fd38e

Please sign in to comment.