Got rid of wait_sem in the console structure. It was pretty useless.

Added stop_console(), a shutdown procedure for consoled (for cases
when it executes a single command only, like the debugger).

Unfortunately the system kind of freezes when the keyboard is attempted
to be closed. Entering KDL still works. It always shows consoled's
keyboard reader thread running somewhere in the endless loop in
keyboard_read() in the keyboard driver. The main thread is ready in
delete_sem() invoked by keyboard_close(), not advancing any further when
continuing the system. Apparently the scheduler needs a good spanking.
:-P

Generally it also doesn't help that the keyboard driver code is
completely cookie ignorant.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20135 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2007-02-15 22:59:38 +00:00
parent 8d96648eab
commit a6392d3c05
1 changed files with 28 additions and 8 deletions

View File

@ -42,7 +42,6 @@ struct console {
int tty_num;
thread_id keyboard_reader;
thread_id console_writer;
sem_id wait_sem;
};
@ -143,7 +142,6 @@ keyboard_reader(void *arg)
}
#endif // USE_INPUT_SERVER
release_sem(con->wait_sem);
return 0;
}
@ -164,7 +162,6 @@ console_writer(void *arg)
write_len = write(con->console_fd, buf, len);
}
release_sem(con->wait_sem);
return 0;
}
@ -175,10 +172,12 @@ start_console(struct console *con)
DIR *dir;
memset(con, 0, sizeof(struct console));
con->wait_sem = create_sem(0, "console wait sem");
if (con->wait_sem < 0)
return -1;
con->console_fd = -1;
con->keyboard_fd = -1;
con->tty_master_fd = -1;
con->tty_slave_fd = -1;
con->keyboard_reader = -1;
con->console_writer = -1;
con->console_fd = open("/dev/console", O_WRONLY);
if (con->console_fd < 0)
@ -261,6 +260,27 @@ start_console(struct console *con)
}
static void
stop_console(struct console* con)
{
// close TTY FDs; this will also unblock the threads
close(con->tty_master_fd);
close(con->tty_slave_fd);
// close console and keyboard
close(con->console_fd);
#ifndef USE_INPUT_SERVER
close(con->keyboard_fd);
// TODO: USE_INPUT_SERVER case.
#endif
// wait for the threads
status_t returnCode;
wait_for_thread(con->console_writer, &returnCode);
wait_for_thread(con->keyboard_reader, &returnCode);
}
static pid_t
start_process(int argc, const char **argv, struct console *con)
{
@ -344,7 +364,7 @@ main(int argc, char **argv)
}
}
acquire_sem(gConsole.wait_sem);
stop_console(&gConsole);
return 0;
}