From 18cfa8b70ce9a6a3572908115f98211f3fa9a367 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Sun, 8 Sep 2002 21:55:59 +0000 Subject: libcons/ 2002-09-09 Marcus Brinkmann * vcons-remove.c: New file. * Makefile (SRCS): Add vcons-destroy.c. * cons.h: New type vcons_list_t. (struct vcons_list): New structure. (struct cons_notify): Remove VCONS member. (struct vcons): Remove members NEXT, PREV and NOTIFY. Add the notify structure to the top to make it possible to use a vcons as a port. New member VCONS_ENTRY. (struct cons): Change type of members vcons_list and vcons_last to vcons_list_t. Remove member active. (cons_vcons_add): Change prototype to match new definition. (cons_vcons_remove): Likewise. (cons_switch): Likewise. (cons_lookup): Likewise. (cons_vcons_open): Likewise. (cons_vcons_destroy): New prototype. * cons-lookup.c (cons_lookup): Change type of R_VCONS argument vcons_list_t. Change type of previous_vcons and vcons variables to vcons_list_t. Append _entry to all these variables. Don't allocate and initialize a vcons_t, but a vcons_list_t. After this has been added to the list, call cons_vcons_add. * cons-switch.c: Do not include (cons_switch): Add arguments ACTIVE_ID and R_VCONS. New variable ERR and VCONS_ENTRY. Remove variable ACTIVE. Do not keep track of active console. Instead, look it up using ACTIVE_ID. Lock the returned console. Call cons_vcons_open, not cons_vcons_activate. * dir-changed.c (add_one): Change VCONS to VCONS_ENTRY and its type from vcons_t to vcons_list_t to follow cons_lookup change. (lookup_one): Likewise. (cons_S_dir_changed): Likewise. * file-changed.c (cons_S_file_changed): Cast NOTIFY to VCONS. Check that NOTIFY->cons is not set instead that NOTIFY->vcons is. * init-init.c (cons_init): Pass cons_vcons_destroy as clean_routine to ports_create_class. Don't initialize CONS->active, nor DIR_NOTIFY_PORT->vcons. * vcons-add.c (cons_vcons_add): Change argument VCONS to CONS and VCONS_ENTRY. Don't do anything here (the user must implement it all). * vcons-close.c: Don't include , , , , , . Include , and . (cons_vcons_close): Clear VCONS->vcons_entry->vcons. Derefence and destroy VCONS. * vcons-open.c (cons_vcons_open): Change arguments from VCONS to CONS, VCONS_ENTRY and R_VCONS. New variable VCONS. Set up VCONS as a port, and request notification messages on that. * vcons-remove.c: Do not include . (cons_vcons_remove): Assert that VCONS_ENTRY does not have an open VCONS. utils/ 2002-09-09 Marcus Brinkmann * console-ncurses.c: New global variable global_lock. (main): Initialize global_lock. (cons_vcons_activate): Removed. (console_switch): New function. (cons_vcons_add): New function. (input_loop): Call console_switch, not cons_switch. Do not take active_vcons lock but global_lock. (cons_vcons_update): Take global lock. (cons_vcons_set_cursor_pos): Likewise. (cons_vcons_set_cursor_status): Likewise. (cons_vcons_scroll): Likewise. (cons_vcons_write): Likewise. (cons_vcons_beep): Likewise. (cons_vcons_flash): Likewise. --- libcons/vcons-open.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'libcons/vcons-open.c') diff --git a/libcons/vcons-open.c b/libcons/vcons-open.c index 7256b4c8..0d826b63 100644 --- a/libcons/vcons-open.c +++ b/libcons/vcons-open.c @@ -29,9 +29,10 @@ #include "cons.h" -/* Open the virtual console VCONS. VCONS->cons is locked. */ +/* Open the virtual console for VCONS_ENTRY. CONS is locked. + Afterwards, R_VCONS will be locked. */ error_t -cons_vcons_open (vcons_t vcons) +cons_vcons_open (cons_t cons, vcons_list_t vcons_entry, vcons_t *r_vcons) { error_t err = 0; char *name; @@ -40,12 +41,23 @@ cons_vcons_open (vcons_t vcons) int fd = -1; struct stat statbuf; mach_port_t notify = MACH_PORT_NULL; + vcons_t vcons; - if (asprintf (&name, "%u", vcons->id) < 0) + if (asprintf (&name, "%u", vcons_entry->id) < 0) return err; + /* Set up the port we receive notification messages on. */ + err = ports_create_port (cons_port_class, cons_port_bucket, + sizeof (*vcons), &vcons); + if (err) + goto err; + vcons->notify.cons = NULL; + vcons->cons = cons; + vcons->vcons_entry = vcons_entry; + vcons->id = vcons_entry->id; + /* Open the directory port of the virtual console. */ - vconsp = file_name_lookup_under (vcons->cons->dirport, name, + vconsp = file_name_lookup_under (cons->dirport, name, O_DIRECTORY | O_RDONLY, 0); if (vconsp == MACH_PORT_NULL) { @@ -116,23 +128,19 @@ cons_vcons_open (vcons_t vcons) vcons->state.changes.buffer = ((uint32_t *) vcons->display) + vcons->display->changes.buffer; - /* Set up the port we receive notification messages on. */ - err = ports_create_port (cons_port_class, cons_port_bucket, - sizeof (*vcons->notify), &vcons->notify); - if (err) - goto err; - vcons->notify->cons = NULL; - vcons->notify->vcons = vcons; - /* Request notification messages. */ - notify = ports_get_right (vcons->notify); + notify = ports_get_right (vcons); mach_port_set_qlimit (mach_task_self (), notify, 1); /* When this succeeds, we will immediately receive notification messages for this virtual console. */ + mutex_lock (&vcons->lock); err = file_notice_changes (file, notify, MACH_MSG_TYPE_MAKE_SEND); if (!err) - goto out; + { + *r_vcons = vcons; + goto out; + } err: if (vcons->input >= 0) @@ -148,8 +156,9 @@ cons_vcons_open (vcons_t vcons) if (notify) { mach_port_deallocate (mach_task_self (), notify); - vcons->notify = MACH_PORT_NULL; + ports_port_deref (vcons); } + ports_destroy_right (vcons); out: if (fd > 0) close (fd); -- cgit v1.2.3