Tweaks to scheduling (priority) and fixes for the shell

This commit is contained in:
Andrew Pamment 2021-12-23 18:08:45 +10:00
parent 07328a4267
commit c2bb04a56e
5 changed files with 45 additions and 28 deletions

44
gui.c
View File

@ -77,6 +77,23 @@ int wallpaper_lock = 0;
struct ModeInfoBlock *modeinfo = (void *)0;
static void gui_window_set_focus(struct window_t *win) {
if (win->focused) return;
for (int i = 0;i < window_count; i++) {
if (windows[i]->focused) {
windows[i]->focused = 0;
windows[i]->mytask->priority -= 10;
if (windows[i]->mytask->priority < 1) {
windows[i]->mytask->priority = 1;
}
}
}
win->mytask->priority += 10;
win->focused = 1;
}
void init_gui(multiboot_info_t *mbinfo) {
if (mbinfo->flags & 1 << 11) {
serialnos = 0;
@ -333,7 +350,6 @@ extern int gui_change_window_caption(int serialno, char *cap) {
int gui_add_window(unsigned char *contents, char *name, int x, int y, int w, int h, unsigned char *icon, unsigned int flags, void (*keyboard_d)(unsigned char c, unsigned char state)) {
struct window_t *new_window;
int i;
if (window_count == 0) {
windows = (struct window_t **)dbmalloc(sizeof(struct window_t *), "gui: add window (malloc)");
@ -356,7 +372,7 @@ int gui_add_window(unsigned char *contents, char *name, int x, int y, int w, int
new_window->mclick = 0;
new_window->flags = flags;
new_window->event_msg_count = 0;
new_window->focused = 0;
if (contents == (void *)0) {
new_window->contents = (unsigned char *)malloc(w * h * depth);
@ -380,15 +396,12 @@ int gui_add_window(unsigned char *contents, char *name, int x, int y, int w, int
strncpy(new_window->name, name, 128);
new_window->zorder = window_count;
new_window->focused = 1;
for (i = 0;i < window_count; i++) {
windows[i]->focused = 0;
}
windows[window_count] = new_window;
window_count++;
keyboard_set_handler(new_window->keyboard_dest);
if (current_task != (void *)0) {
@ -402,6 +415,10 @@ int gui_add_window(unsigned char *contents, char *name, int x, int y, int w, int
current_task->window_count++;
}
new_window->mytask = current_task;
gui_window_set_focus(new_window);
return new_window->serialno;
}
@ -433,7 +450,7 @@ void gui_destroy_window(int serialno, struct task_t *task) {
window_count--;
if (win->focused && window_count > 0) {
windows[window_count - 1]->focused = 1;
gui_window_set_focus(windows[window_count - 1]);
}
windows = (struct window_t **)realloc(windows, sizeof(struct window_t *) * window_count);
@ -556,14 +573,12 @@ void gui_sink_to_bottom(int wh) {
for (int i = wh; i >= 1; i--) {
windows[i] = windows[i - 1];
windows[i]->focused = 0;
windows[i]->zorder++;
}
windows[0] = win;
windows[0]->zorder = 0;
windows[0]->focused = 0;
windows[window_count-1]->focused = 1;
gui_window_set_focus(windows[window_count - 1]);
}
int gui_raise_to_icon_top(int wh) {
@ -594,18 +609,13 @@ void gui_raise_to_top(int wh) {
struct window_t *win;
win = windows[wh];
for (int i = 0; i < wh; i++) {
windows[i]->focused = 0;
}
for (int i = wh; i < window_count - 1; i++) {
windows[i] = windows[i+1];
windows[i]->zorder--;
windows[i]->focused = 0;
}
windows[window_count - 1] = win;
windows[window_count - 1]->zorder = window_count - 1;
windows[window_count - 1]->focused = 1;
gui_window_set_focus(windows[window_count - 1]);
keyboard_set_handler(windows[window_count - 1]->keyboard_dest);
}

1
gui.h
View File

@ -45,6 +45,7 @@ struct window_t {
unsigned char lclick;
unsigned char rclick;
unsigned char mclick;
struct task_t *mytask;
};
extern void init_gui(multiboot_info_t *mbinfo);

View File

@ -486,7 +486,15 @@ int main(int argc, char **argv) {
}
free(porig);
}
if (!found) {
// try cwd
sprintf(buffer, "%s:%s%s", current_drive, cwd, argv_s[0]);
if (!stat(buffer, &s)) {
if (S_ISREG(s.st_mode)) {
found = 1;
}
}
}
} else {
if (argv_s[0][0] == '/') {
strcpy(buffer2, argv_s[0]);

View File

@ -111,11 +111,12 @@ void init_scheduler(void) {
current_task->cr3 = page_directory;
current_task->kstack = _sys_stack + KRNL_STACK_SIZE;
current_task->state = TASK_RUNNING;
current_task->priority = 1;
first_task = current_task;
last_task = current_task;
strcpy(current_task->name, "KERNEL");
for (i=0;i<USER_STACK_SIZE/0x1000;i++) {
current_task->user_stack_pages[i] = 0;
current_task->user_stack_pages[i] = 0;
}
current_task->user_pages_at = 0x40000000;
current_task->user_pages = (void *)0;
@ -157,7 +158,6 @@ void sched_free_task(struct task_t *this_task) {
// free stack virt space
for (i=0;i<this_task->window_count;i++) {
gui_destroy_window(this_task->window_list[i]->serialno, this_task);
}
@ -216,7 +216,7 @@ void schedule(struct regs *r) {
unsigned int *status;
unsigned int *wait_return;
if (block_buffer_trim_timer == 20) {
if (block_buffer_trim_timer == 200) {
hd_buffer_trim();
block_buffer_trim_timer = 0;
}
@ -294,11 +294,8 @@ void schedule(struct regs *r) {
}
if (previous_task != current_task) {
// do switch
if (current_task == first_task) {
current_task->timetorun = 1;
} else {
current_task->timetorun = 5;
}
current_task->timetorun = current_task->priority;
fpu_disable();
if (r->int_no == 0x30) {
@ -309,7 +306,6 @@ void schedule(struct regs *r) {
}
}
struct task_t *sched_new_task() {
struct task_t *new_task = (struct task_t *)malloc(sizeof(struct task_t));
memset(new_task, 0, sizeof(struct task_t));
@ -338,6 +334,7 @@ struct task_t *sched_new_task() {
new_task->waiting_socket_count = 0;
new_task->sem_count = 0;
new_task->cwd = (char *)malloc(strlen(current_task->cwd) + 1);
new_task->priority = 5;
strcpy(new_task->cwd, current_task->cwd);
strcpy(new_task->name, current_task->name);
int i;

View File

@ -11,7 +11,7 @@
#define TASK_WAITING 4
#define TASK_SLEEPING 5
#define TASK_SEM_WAIT 6
#define TASK_ZOMBIE 7
#define TASK_ZOMBIE 7
#define SLEEP_USER 1
#define SLEEP_TCP_ACCEPT 2
@ -59,6 +59,7 @@ struct task_t {
unsigned int *user_pages_virt;
unsigned int user_stack_pages[USER_STACK_SIZE / 0x1000];
unsigned int user_env_pages[64];
unsigned int priority;
struct vfs_device_t *selected_device;
char *cwd;
struct window_t **window_list;