diff options
Diffstat (limited to 'console')
-rw-r--r-- | console/Makefile | 3 | ||||
-rw-r--r-- | console/console.c | 105 | ||||
-rw-r--r-- | console/display.c | 110 | ||||
-rw-r--r-- | console/input.c | 44 | ||||
-rw-r--r-- | console/pager.c | 21 |
5 files changed, 152 insertions, 131 deletions
diff --git a/console/Makefile b/console/Makefile index 10737489..c5ab543e 100644 --- a/console/Makefile +++ b/console/Makefile @@ -26,7 +26,8 @@ SRCS = console.c display.c pager.c input.c MIGSTUBS = notifyServer.o tioctlServer.o fs_notifyUser.o -HURDLIBS = netfs fshelp iohelp pager threads ports ihash shouldbeinlibc +HURDLIBS = netfs fshelp iohelp pager ports ihash shouldbeinlibc +OTHERLIBS = -lpthread OBJS = $(sort $(SRCS:.c=.o) $(MIGSTUBS)) MIGSFLAGS += -imacros $(srcdir)/mutations.h diff --git a/console/console.c b/console/console.c index cf208cff..0577ea04 100644 --- a/console/console.c +++ b/console/console.c @@ -33,9 +33,8 @@ #include <dirent.h> #include <sys/mman.h> #include <sys/stat.h> -#include <rwlock.h> #include <maptime.h> -#include <cthreads.h> +#include <pthread.h> #include <version.h> @@ -104,7 +103,7 @@ struct vcons display_t display; input_t input; - struct mutex lock; + pthread_mutex_t lock; /* Nodes in the filesystem referring to this virtual console. */ struct node *dir_node; struct node *cons_node; @@ -124,7 +123,7 @@ struct cons /* The lock protects the console, all virtual consoles contained in it and the reference counters. It also locks the configuration parameters. */ - struct mutex lock; + pthread_mutex_t lock; vcons_t vcons_list; /* The encoding. */ char *encoding; @@ -188,7 +187,7 @@ vcons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons) if (!id && !create) return EINVAL; - mutex_lock (&cons->lock); + pthread_mutex_lock (&cons->lock); if (id) { if (cons->vcons_list && cons->vcons_list->id <= id) @@ -199,14 +198,14 @@ vcons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons) if (previous_vcons->id == id) { previous_vcons->refcnt++; - mutex_unlock (&cons->lock); + pthread_mutex_unlock (&cons->lock); *r_vcons = previous_vcons; return 0; } } else if (!create) { - mutex_unlock (&cons->lock); + pthread_mutex_unlock (&cons->lock); return ESRCH; } } @@ -227,7 +226,7 @@ vcons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons) vcons = calloc (1, sizeof (struct vcons)); if (!vcons) { - mutex_unlock (&cons->lock); + pthread_mutex_unlock (&cons->lock); return ENOMEM; } vcons->cons = cons; @@ -236,7 +235,7 @@ vcons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons) asprintf (&vcons->name, "%i", id); /* XXX Error checking. */ - mutex_init (&vcons->lock); + pthread_mutex_init (&vcons->lock, NULL); err = display_create (&vcons->display, cons->encoding ?: DEFAULT_ENCODING, cons->attribute, cons->lines, cons->width, cons->height); @@ -244,7 +243,7 @@ vcons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons) { free (vcons->name); free (vcons); - mutex_unlock (&cons->lock); + pthread_mutex_unlock (&cons->lock); return err; } @@ -254,7 +253,7 @@ vcons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons) display_destroy (vcons->display); free (vcons->name); free (vcons); - mutex_unlock (&cons->lock); + pthread_mutex_unlock (&cons->lock); return err; } @@ -280,7 +279,7 @@ vcons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons) } cons_notice_dirchange (cons, DIR_CHANGED_NEW, vcons->name); - mutex_unlock (&cons->lock); + pthread_mutex_unlock (&cons->lock); *r_vcons = vcons; return 0; } @@ -291,9 +290,9 @@ vcons_ref (vcons_t vcons) { cons_t cons = vcons->cons; - mutex_lock (&cons->lock); + pthread_mutex_lock (&cons->lock); vcons->refcnt++; - mutex_unlock (&cons->lock); + pthread_mutex_unlock (&cons->lock); } /* Release a reference to the virtual console VCONS. If this was the @@ -303,7 +302,7 @@ vcons_release (vcons_t vcons) { cons_t cons = vcons->cons; - mutex_lock (&cons->lock); + pthread_mutex_lock (&cons->lock); if (!--vcons->refcnt) { /* As we keep a reference for all input focus groups pointing to @@ -326,7 +325,7 @@ vcons_release (vcons_t vcons) free (vcons->name); free (vcons); } - mutex_unlock (&cons->lock); + pthread_mutex_unlock (&cons->lock); } struct netnode @@ -424,19 +423,19 @@ netfs_node_norefs (struct node *np) assert (!np->nn->cons && np->nn->vcons); /* Avoid deadlock. */ - spin_unlock (&netfs_node_refcnt_lock); + pthread_spin_unlock (&netfs_node_refcnt_lock); /* Find the back reference to ourself in the virtual console structure, and delete it. */ - mutex_lock (&vcons->lock); - spin_lock (&netfs_node_refcnt_lock); + pthread_mutex_lock (&vcons->lock); + pthread_spin_lock (&netfs_node_refcnt_lock); if (np->references) { /* Someone else got a reference while we were attempting to go away. This can happen in netfs_attempt_lookup. In this case, just unlock the node and do nothing else. */ - mutex_unlock (&vcons->lock); - mutex_unlock (&np->lock); + pthread_mutex_unlock (&vcons->lock); + pthread_mutex_unlock (&np->lock); return; } if (np == vcons->dir_node) @@ -450,7 +449,7 @@ netfs_node_norefs (struct node *np) assert (np == vcons->inpt_node); vcons->inpt_node = 0; } - mutex_unlock (&vcons->lock); + pthread_mutex_unlock (&vcons->lock); /* Release our reference. */ vcons_release (vcons); @@ -470,7 +469,7 @@ netfs_attempt_create_file (struct iouser *user, struct node *dir, /* We create virtual consoles dynamically on the fly, so there is no need for an explicit create operation. */ *np = 0; - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); return EOPNOTSUPP; } @@ -616,7 +615,7 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir, if (err) goto out; - mutex_lock (&vcons->lock); + pthread_mutex_lock (&vcons->lock); if (vcons->dir_node) { /* We already have a directory node for this virtual @@ -636,7 +635,7 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir, else release_vcons = 1; } - mutex_unlock (&vcons->lock); + pthread_mutex_unlock (&vcons->lock); if (release_vcons) vcons_release (vcons); } @@ -649,7 +648,7 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir, if (!strcmp (name, "console")) { - mutex_lock (&vcons->lock); + pthread_mutex_lock (&vcons->lock); if (vcons->cons_node) { *node = vcons->cons_node; @@ -664,11 +663,11 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir, ref_vcons = 1; } } - mutex_unlock (&vcons->lock); + pthread_mutex_unlock (&vcons->lock); } else if (!strcmp (name, "display")) { - mutex_lock (&vcons->lock); + pthread_mutex_lock (&vcons->lock); if (vcons->disp_node) { *node = vcons->disp_node; @@ -683,11 +682,11 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir, ref_vcons = 1; } } - mutex_unlock (&vcons->lock); + pthread_mutex_unlock (&vcons->lock); } else if (!strcmp (name, "input")) { - mutex_lock (&vcons->lock); + pthread_mutex_lock (&vcons->lock); if (vcons->inpt_node) { *node = vcons->inpt_node; @@ -702,7 +701,7 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir, ref_vcons = 1; } } - mutex_unlock (&vcons->lock); + pthread_mutex_unlock (&vcons->lock); } else err = ENOENT; @@ -715,11 +714,11 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir, fshelp_touch (&dir->nn_stat, TOUCH_ATIME, console_maptime); out: - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); if (err) *node = 0; else - mutex_lock (&(*node)->lock); + pthread_mutex_lock (&(*node)->lock); return err; } @@ -771,7 +770,7 @@ netfs_get_dirents (struct iouser *cred, struct node *dir, if (dir->nn->cons) { - mutex_lock (&dir->nn->cons->lock); + pthread_mutex_lock (&dir->nn->cons->lock); /* Find the first entry. */ for (first_vcons = dir->nn->cons->vcons_list, count = 2; @@ -881,7 +880,7 @@ netfs_get_dirents (struct iouser *cred, struct node *dir, } if (dir->nn->cons) - mutex_unlock(&dir->nn->cons->lock); + pthread_mutex_unlock(&dir->nn->cons->lock); fshelp_touch (&dir->nn_stat, TOUCH_ATIME, console_maptime); return err; @@ -916,7 +915,7 @@ netfs_attempt_chown (struct iouser *cred, struct node *node, node->nn_stat.st_uid = uid; node->nn_stat.st_gid = gid; - mutex_lock (&cons->lock); + pthread_mutex_lock (&cons->lock); cons->stat_template.st_uid = uid; cons->stat_template.st_gid = gid; @@ -944,7 +943,7 @@ netfs_attempt_chown (struct iouser *cred, struct node *node, vcons->inpt_node->nn_stat.st_gid = gid; } } - mutex_unlock (&cons->lock); + pthread_mutex_unlock (&cons->lock); fshelp_touch (&node->nn_stat, TOUCH_CTIME, console_maptime); return err; } @@ -968,7 +967,7 @@ netfs_attempt_chauthor (struct iouser *cred, struct node *node, uid_t author) /* Change NODE's author. */ node->nn_stat.st_author = author; - mutex_lock (&cons->lock); + pthread_mutex_lock (&cons->lock); cons->stat_template.st_author = author; /* Change the author of each leaf node. */ @@ -983,7 +982,7 @@ netfs_attempt_chauthor (struct iouser *cred, struct node *node, uid_t author) if (vcons->inpt_node) vcons->inpt_node->nn_stat.st_author = author; } - mutex_unlock (&cons->lock); + pthread_mutex_unlock (&cons->lock); fshelp_touch (&node->nn_stat, TOUCH_CTIME, console_maptime); return err; } @@ -1113,7 +1112,7 @@ netfs_attempt_read (struct iouser *cred, struct node *np, || np == vcons->inpt_node) return EOPNOTSUPP; - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); if (np == vcons->cons_node) { ssize_t amt = input_dequeue (vcons->input, @@ -1143,7 +1142,7 @@ netfs_attempt_read (struct iouser *cred, struct node *np, else *len = amt; } - mutex_lock (&np->lock); + pthread_mutex_lock (&np->lock); return err; } @@ -1157,7 +1156,7 @@ netfs_attempt_write (struct iouser *cred, struct node *np, || np == vcons->disp_node) return EOPNOTSUPP; - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); if (np == vcons->cons_node) { /* The term server is writing to the console device. Feed the @@ -1185,7 +1184,7 @@ netfs_attempt_write (struct iouser *cred, struct node *np, else *len = amt; } - mutex_lock (&np->lock); + pthread_mutex_lock (&np->lock); return err; } @@ -1214,7 +1213,7 @@ netfs_S_io_map (struct protid *cred, flags = cred->po->openstat & (O_READ | O_WRITE); - mutex_lock (&np->lock); + pthread_mutex_lock (&np->lock); switch (flags) { case O_READ | O_WRITE: @@ -1235,7 +1234,7 @@ netfs_S_io_map (struct protid *cred, goto error; break; } - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); *rdtype = MACH_MSG_TYPE_MOVE_SEND; *wrtype = MACH_MSG_TYPE_MOVE_SEND; @@ -1243,7 +1242,7 @@ netfs_S_io_map (struct protid *cred, return 0; error: - mutex_unlock (&np->lock); + pthread_mutex_unlock (&np->lock); return errno; } @@ -1263,7 +1262,7 @@ netfs_S_dir_notice_changes (struct protid *cred, mach_port_t notify) if (!cons) return EOPNOTSUPP; - mutex_lock (&cons->lock); + pthread_mutex_lock (&cons->lock); /* We have to prevent that we accumulate dead-names in the notification list. They are cleaned up in cons_notice_dirchange, but that is not called often enough, so we also clean them up @@ -1292,19 +1291,19 @@ netfs_S_dir_notice_changes (struct protid *cred, mach_port_t notify) err = dir_changed (notify, cons->dirmod_tick, DIR_CHANGED_NULL, ""); if (err) { - mutex_unlock (&cons->lock); + pthread_mutex_unlock (&cons->lock); return err; } req = malloc (sizeof (struct modreq)); if (!req) { - mutex_unlock (&cons->lock); + pthread_mutex_unlock (&cons->lock); return errno; } req->port = notify; req->next = cons->dirmod_reqs; cons->dirmod_reqs = req; - mutex_unlock (&cons->lock); + pthread_mutex_unlock (&cons->lock); return 0; } @@ -1473,11 +1472,11 @@ parse_opt (int opt, char *arg, struct argp_state *state) break; case ARGP_KEY_INIT: - mutex_lock (&cons->lock); + pthread_mutex_lock (&cons->lock); break; case ARGP_KEY_FINI: - mutex_unlock (&cons->lock); + pthread_mutex_unlock (&cons->lock); break; case 'f': @@ -2001,7 +2000,7 @@ main (int argc, char **argv) cons = malloc (sizeof (struct cons)); if (!cons) error (1, ENOMEM, "Cannot create console structure"); - mutex_init (&cons->lock); + pthread_mutex_init (&cons->lock, NULL); cons->encoding = NULL; cons->width = DEFAULT_WIDTH; cons->height = DEFAULT_HEIGHT; diff --git a/console/display.c b/console/display.c index e807c50f..97e16264 100644 --- a/console/display.c +++ b/console/display.c @@ -29,7 +29,7 @@ #include <assert.h> #include <error.h> -#include <cthreads.h> +#include <pthread.h> #include <hurd.h> #include <hurd/ports.h> @@ -119,7 +119,7 @@ struct output multi-byte or composed character at the end of the buffer, so we have to keep them around. */ int stopped; - struct condition resumed; + pthread_cond_t resumed; char *buffer; size_t allocated; size_t size; @@ -159,7 +159,7 @@ struct notify struct display { /* The lock for the virtual console display structure. */ - struct mutex lock; + pthread_mutex_t lock; /* Indicates if OWNER_ID is initialized. */ int has_owner; @@ -339,7 +339,7 @@ do_mach_notify_dead_name (mach_port_t notify, mach_port_t dead_name) return EOPNOTSUPP; display = notify_port->display; - mutex_lock (&display->lock); + pthread_mutex_lock (&display->lock); /* Find request in pending queue. */ preq = &display->filemod_reqs_pending; @@ -361,7 +361,7 @@ do_mach_notify_dead_name (mach_port_t notify, mach_port_t dead_name) mach_port_deallocate (mach_task_self (), req->port); free (req); } - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); /* Drop gratuitous extra reference that the notification creates. */ mach_port_deallocate (mach_task_self (), dead_name); @@ -406,7 +406,7 @@ do_mach_notify_msg_accepted (mach_port_t notify, mach_port_t send) } display = notify_port->display; - mutex_lock (&display->lock); + pthread_mutex_lock (&display->lock); /* Find request in pending queue. */ preq = &display->filemod_reqs_pending; while (*preq && (*preq)->port != send) @@ -417,7 +417,7 @@ do_mach_notify_msg_accepted (mach_port_t notify, mach_port_t send) if (! *preq) { assert(0); - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); ports_port_deref (notify_port); return 0; } @@ -435,7 +435,7 @@ do_mach_notify_msg_accepted (mach_port_t notify, mach_port_t send) { mach_port_t old; *preq = req->next; - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); /* Cancel the dead-name notification. */ mach_port_request_notification (mach_task_self (), req->port, @@ -451,7 +451,7 @@ do_mach_notify_msg_accepted (mach_port_t notify, mach_port_t send) } if (err == MACH_SEND_WILL_NOTIFY) { - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); return 0; } /* The message was successfully queued, fall through. */ @@ -461,15 +461,15 @@ do_mach_notify_msg_accepted (mach_port_t notify, mach_port_t send) /* Insert request into active queue. */ req->next = display->filemod_reqs; display->filemod_reqs = req; - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); ports_port_deref (notify_port); return 0; } /* A top-level function for the notification thread that just services notification messages. */ -static void -service_notifications (any_t arg) +static void * +service_notifications (void *arg) { struct port_bucket *notify_bucket = arg; extern int notify_server (mach_msg_header_t *inp, mach_msg_header_t *outp); @@ -478,6 +478,7 @@ service_notifications (any_t arg) ports_manage_port_operations_one_thread (notify_bucket, notify_server, 1000 * 60 * 10); + return NULL; } error_t @@ -488,19 +489,19 @@ display_notice_changes (display_t display, mach_port_t notify) mach_port_t notify_port; mach_port_t old; - mutex_lock (&display->lock); + pthread_mutex_lock (&display->lock); err = nowait_file_changed (notify, 0, FILE_CHANGED_NULL, 0, 0, MACH_PORT_NULL); if (err) { - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); return err; } req = malloc (sizeof (struct modreq)); if (!req) { - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); return errno; } @@ -514,7 +515,7 @@ display_notice_changes (display_t display, mach_port_t notify) if (err) { free (req); - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); return err; } assert (old == MACH_PORT_NULL); @@ -523,7 +524,7 @@ display_notice_changes (display_t display, mach_port_t notify) req->pending = 0; req->next = display->filemod_reqs; display->filemod_reqs = req; - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); return 0; } @@ -924,7 +925,7 @@ screen_shift_right (display_t display, size_t col1, size_t row1, size_t col2, static error_t output_init (output_t output, const char *encoding) { - condition_init (&output->resumed); + pthread_cond_init (&output->resumed, NULL); output->stopped = 0; output->buffer = NULL; output->allocated = 0; @@ -1806,6 +1807,9 @@ void display_destroy_complete (void *pi); void display_init (void) { + pthread_t thread; + error_t err; + user_pager_init (); /* Create the notify bucket, and start to serve notifications. */ @@ -1816,8 +1820,14 @@ display_init (void) if (! notify_class) error (5, errno, "Cannot create notify class"); - cthread_detach (cthread_fork ((cthread_fn_t) service_notifications, - (any_t) notify_bucket)); + err = pthread_create (&thread, NULL, service_notifications, notify_bucket); + if (!err) + pthread_detach (thread); + else + { + errno = err; + perror ("pthread_create"); + } } @@ -1845,7 +1855,7 @@ display_create (display_t *r_display, const char *encoding, } display->notify_port->display = display; - mutex_init (&display->lock); + pthread_mutex_init (&display->lock, NULL); display->attr.attr_def = def_attr; display->attr.current = display->attr.attr_def; display->csr.bottom = height - 1; @@ -1875,7 +1885,7 @@ display_create (display_t *r_display, const char *encoding, void display_destroy (display_t display) { - mutex_lock (&display->lock); + pthread_mutex_lock (&display->lock); if (display->filemod_reqs_pending) { free_modreqs (display->filemod_reqs_pending); @@ -1889,7 +1899,7 @@ display_destroy (display_t display) ports_destroy_right (display->notify_port); output_deinit (&display->output); user_destroy (display); - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); /* We can not free the display structure here, because it might still be needed by pending modification requests when msg @@ -1923,12 +1933,12 @@ display_get_size (display_t display) void display_getsize (display_t display, struct winsize *winsize) { - mutex_lock (&display->lock); + pthread_mutex_lock (&display->lock); winsize->ws_row = display->user->screen.height; winsize->ws_col = display->user->screen.width; winsize->ws_xpixel = 0; winsize->ws_ypixel = 0; - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); } @@ -1937,10 +1947,10 @@ display_getsize (display_t display, struct winsize *winsize) error_t display_set_owner (display_t display, pid_t pid) { - mutex_lock (&display->lock); + pthread_mutex_lock (&display->lock); display->has_owner = 1; display->owner_id = pid; - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); return 0; } @@ -1951,12 +1961,12 @@ error_t display_get_owner (display_t display, pid_t *pid) { error_t err = 0; - mutex_lock (&display->lock); + pthread_mutex_lock (&display->lock); if (!display->has_owner) err = ENOTTY; else *pid = display->owner_id; - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); return err; } @@ -1994,18 +2004,18 @@ display_output (display_t display, int nonblock, char *data, size_t datalen) return 0; } - mutex_lock (&display->lock); + pthread_mutex_lock (&display->lock); while (output->stopped) { if (nonblock) { - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); errno = EWOULDBLOCK; return -1; } - if (hurd_condition_wait (&output->resumed, &display->lock)) + if (pthread_hurd_cond_wait_np (&output->resumed, &display->lock)) { - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); errno = EINTR; return -1; } @@ -2016,7 +2026,7 @@ display_output (display_t display, int nonblock, char *data, size_t datalen) err = ensure_output_buffer_size (output->size + datalen); if (err) { - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); errno = ENOMEM; return -1; } @@ -2036,7 +2046,7 @@ display_output (display_t display, int nonblock, char *data, size_t datalen) if (err && !amount) { - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); errno = err; return err; } @@ -2049,7 +2059,7 @@ display_output (display_t display, int nonblock, char *data, size_t datalen) err = ensure_output_buffer_size (buffer_size); if (err) { - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); return err; } memmove (output->buffer, buffer, buffer_size); @@ -2057,7 +2067,7 @@ display_output (display_t display, int nonblock, char *data, size_t datalen) output->size = buffer_size; amount += buffer_size; - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); return amount; } @@ -2066,9 +2076,9 @@ ssize_t display_read (display_t display, int nonblock, off_t off, char *data, size_t len) { - mutex_lock (&display->lock); + pthread_mutex_lock (&display->lock); memcpy (data, ((char *) display->user) + off, len); - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); return len; } @@ -2077,17 +2087,17 @@ display_read (display_t display, int nonblock, off_t off, void display_start_output (display_t display) { - mutex_lock (&display->lock); + pthread_mutex_lock (&display->lock); if (display->output.stopped) { display->output.stopped = 0; - condition_broadcast (&display->output.resumed); + pthread_cond_broadcast (&display->output.resumed); } display->changes.flags = display->user->flags; display->changes.which = DISPLAY_CHANGE_FLAGS; display->user->flags &= ~CONS_FLAGS_SCROLL_LOCK; display_flush_filechange (display, DISPLAY_CHANGE_FLAGS); - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); } @@ -2095,13 +2105,13 @@ display_start_output (display_t display) void display_stop_output (display_t display) { - mutex_lock (&display->lock); + pthread_mutex_lock (&display->lock); display->output.stopped = 1; display->changes.flags = display->user->flags; display->changes.which = DISPLAY_CHANGE_FLAGS; display->user->flags |= CONS_FLAGS_SCROLL_LOCK; display_flush_filechange (display, DISPLAY_CHANGE_FLAGS); - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); } @@ -2110,9 +2120,9 @@ size_t display_pending_output (display_t display) { int output_size; - mutex_lock (&display->lock); + pthread_mutex_lock (&display->lock); output_size = display->output.size; - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); return output_size; } @@ -2121,9 +2131,9 @@ display_pending_output (display_t display) void display_discard_output (display_t display) { - mutex_lock (&display->lock); + pthread_mutex_lock (&display->lock); display->output.size = 0; - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); } @@ -2131,8 +2141,8 @@ mach_port_t display_get_filemap (display_t display, vm_prot_t prot) { mach_port_t memobj; - mutex_lock (&display->lock); + pthread_mutex_lock (&display->lock); memobj = user_pager_get_filemap (&display->user_pager, prot); - mutex_unlock (&display->lock); + pthread_mutex_unlock (&display->lock); return memobj; } diff --git a/console/input.c b/console/input.c index 14879d07..7ebac302 100644 --- a/console/input.c +++ b/console/input.c @@ -25,16 +25,16 @@ #include <malloc.h> #include <sys/types.h> -#include <cthreads.h> +#include <pthread.h> #include "input.h" struct input { - struct mutex lock; + pthread_mutex_t lock; - struct condition data_available; - struct condition space_available; + pthread_cond_t data_available; + pthread_cond_t space_available; #define INPUT_QUEUE_SIZE 300 char buffer[INPUT_QUEUE_SIZE]; int full; @@ -58,9 +58,9 @@ error_t input_create (input_t *r_input, const char *encoding) if (!input) return ENOMEM; - mutex_init (&input->lock); - condition_init (&input->data_available); - condition_init (&input->space_available); + pthread_mutex_init (&input->lock, NULL); + pthread_cond_init (&input->data_available, NULL); + pthread_cond_init (&input->space_available, NULL); input->cd = iconv_open (encoding, "UTF-8"); if (input->cd == (iconv_t) -1) @@ -119,7 +119,7 @@ ssize_t input_enqueue (input_t input, int nonblock, char *data, return 0; } - mutex_lock (&input->lock); + pthread_mutex_lock (&input->lock); was_empty = !input->size; while (datalen) @@ -133,7 +133,7 @@ ssize_t input_enqueue (input_t input, int nonblock, char *data, err = EWOULDBLOCK; goto out; } - if (hurd_condition_wait (&input->space_available, &input->lock)) + if (pthread_hurd_cond_wait_np (&input->space_available, &input->lock)) { err = EINTR; goto out; @@ -180,7 +180,7 @@ ssize_t input_enqueue (input_t input, int nonblock, char *data, readers and go to sleep (above). */ input->full = 1; if (was_empty) - condition_broadcast (&input->data_available); + pthread_cond_broadcast (&input->data_available); /* Prevent calling condition_broadcast again if nonblock. */ was_empty = 0; } @@ -201,7 +201,7 @@ ssize_t input_enqueue (input_t input, int nonblock, char *data, err = ensure_cd_buffer_size (datalen); if (err) { - mutex_unlock (&input->lock); + pthread_mutex_unlock (&input->lock); errno = err; return enqueued ?: -1; } @@ -212,11 +212,11 @@ ssize_t input_enqueue (input_t input, int nonblock, char *data, if (enqueued) { if (was_empty) - condition_broadcast (&input->data_available); + pthread_cond_broadcast (&input->data_available); } else errno = err; - mutex_unlock (&input->lock); + pthread_mutex_unlock (&input->lock); return enqueued ?: -1; } @@ -231,18 +231,18 @@ ssize_t input_dequeue (input_t input, int nonblock, char *data, { size_t amount = datalen; - mutex_lock (&input->lock); + pthread_mutex_lock (&input->lock); while (!input->size) { if (nonblock) { - mutex_unlock (&input->lock); + pthread_mutex_unlock (&input->lock); errno = EWOULDBLOCK; return -1; } - if (hurd_condition_wait (&input->data_available, &input->lock)) + if (pthread_hurd_cond_wait_np (&input->data_available, &input->lock)) { - mutex_unlock (&input->lock); + pthread_mutex_unlock (&input->lock); errno = EINTR; return -1; } @@ -256,9 +256,9 @@ ssize_t input_dequeue (input_t input, int nonblock, char *data, if (amount && input->full) { input->full = 0; - condition_broadcast (&input->space_available); + pthread_cond_broadcast (&input->space_available); } - mutex_unlock (&input->lock); + pthread_mutex_unlock (&input->lock); return amount; } @@ -266,12 +266,12 @@ ssize_t input_dequeue (input_t input, int nonblock, char *data, /* Flush the input buffer, discarding all pending data. */ void input_flush (input_t input) { - mutex_lock (&input->lock); + pthread_mutex_lock (&input->lock); input->size = 0; if (input->full) { input->full = 0; - condition_broadcast (&input->space_available); + pthread_cond_broadcast (&input->space_available); } - mutex_unlock (&input->lock); + pthread_mutex_unlock (&input->lock); } diff --git a/console/pager.c b/console/pager.c index 092a8820..781ba35e 100644 --- a/console/pager.c +++ b/console/pager.c @@ -21,9 +21,10 @@ #include <errno.h> #include <assert.h> #include <error.h> +#include <stdio.h> #include <sys/mman.h> -#include <cthreads.h> +#include <pthread.h> #include <hurd.h> #include <hurd/pager.h> @@ -114,8 +115,8 @@ pager_dropweak (struct user_pager_info *upi) /* A top-level function for the paging thread that just services paging requests. */ -static void -service_paging_requests (any_t arg) +static void * +service_paging_requests (void *arg) { struct port_bucket *pager_bucket = arg; for (;;) @@ -123,6 +124,7 @@ service_paging_requests (any_t arg) pager_demuxer, 1000 * 60 * 2, 1000 * 60 * 10, 0); + return NULL; } @@ -130,14 +132,23 @@ service_paging_requests (any_t arg) void user_pager_init (void) { + pthread_t thread; + error_t err; + /* Create the pager bucket, and start to serve paging requests. */ pager_bucket = ports_create_bucket (); if (! pager_bucket) error (5, errno, "Cannot create pager bucket"); /* Make a thread to service paging requests. */ - cthread_detach (cthread_fork ((cthread_fn_t) service_paging_requests, - (any_t) pager_bucket)); + err = pthread_create (&thread, NULL, service_paging_requests, pager_bucket); + if (!err) + pthread_detach (thread); + else + { + errno = err; + perror ("pthread_create"); + } } |