From 1de0643c9218db536f5b2e294bbfa653c77438e4 Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Tue, 4 Sep 2012 00:33:09 +0200 Subject: Switch from cthreads to pthreads Makefiles, headers, types, macros and function calls are renamed where appropriate. Most of this work was done by Barry deFreese and Thomas DiModica. * auth/Makefile: Switch from cthreads to pthreads. * auth/auth.c: Likewise. * boot/Makefile: Likewise. * boot/boot.c: Likewise. * boot/ux.c: Likewise. * console-client/Makefile: Likewise. * console-client/console.c: Likewise. * console-client/driver.c: Likewise. * console-client/driver.h: Likewise. * console-client/generic-speaker.c: Likewise. * console-client/kbd-repeat.c: Likewise. * console-client/ncursesw.c: Likewise. * console-client/pc-kbd.c: Likewise. * console-client/pc-mouse.c: Likewise. * console-client/timer.c: Likewise. * console-client/trans.c: Likewise. * console-client/vga.c: Likewise. * console/Makefile: Likewise. * console/console.c: Likewise. * console/display.c: Likewise. * console/input.c: Likewise. * console/pager.c: Likewise. * defpager/backing.c: Likewise. * exec/Makefile: Likewise. * exec/exec.c: Likewise. * exec/hashexec.c: Likewise. * exec/priv.h: Likewise. * ext2fs/Makefile: Likewise. * ext2fs/balloc.c: Likewise. * ext2fs/dir.c: Likewise. * ext2fs/ext2fs.c: Likewise. * ext2fs/ext2fs.h: Likewise. * ext2fs/ialloc.c: Likewise. * ext2fs/inode.c: Likewise. * ext2fs/msg.c: Likewise. * ext2fs/pager.c: Likewise. * ext2fs/pokel.c: Likewise. * ext2fs/storeinfo.c: Likewise. * ext2fs/truncate.c: Likewise. * fatfs/Makefile: Likewise. * fatfs/dir.c: Likewise. * fatfs/fat.c: Likewise. * fatfs/fatfs.h: Likewise. * fatfs/inode.c: Likewise. * fatfs/main.c: Likewise. * fatfs/pager.c: Likewise. * fatfs/virt-inode.c: Likewise. * ftpfs/Makefile: Likewise. * ftpfs/ccache.c: Likewise. * ftpfs/ccache.h: Likewise. * ftpfs/conn.c: Likewise. * ftpfs/dir.c: Likewise. * ftpfs/fs.c: Likewise. * ftpfs/ftpfs.c: Likewise. * ftpfs/ftpfs.h: Likewise. * ftpfs/ncache.c: Likewise. * ftpfs/netfs.c: Likewise. * ftpfs/node.c: Likewise. * hostmux/Makefile: Likewise. * hostmux/hostmux.h: Likewise. * hostmux/mux.c: Likewise. * hostmux/node.c: Likewise. * hostmux/stubs.c: Likewise. * hurd/shared.h: Likewise. * isofs/Makefile: Likewise. * isofs/inode.c: Likewise. * isofs/lookup.c: Likewise. * isofs/main.c: Likewise. * isofs/pager.c: Likewise. * libcons/Makefile: Likewise. * libcons/cons-switch.c: Likewise. * libcons/cons.h: Likewise. * libcons/dir-changed.c: Likewise. * libcons/file-changed.c: Likewise. * libcons/init-init.c: Likewise. * libcons/vcons-close.c: Likewise. * libcons/vcons-input.c: Likewise. * libcons/vcons-move-mouse.c: Likewise. * libcons/vcons-open.c: Likewise. * libcons/vcons-scrollback.c: Likewise. * libdiskfs/Makefile: Likewise. * libdiskfs/boot-start.c: Likewise. * libdiskfs/dead-name.c: Likewise. * libdiskfs/dir-chg.c: Likewise. * libdiskfs/dir-link.c: Likewise. * libdiskfs/dir-lookup.c: Likewise. * libdiskfs/dir-mkdir.c: Likewise. * libdiskfs/dir-mkfile.c: Likewise. * libdiskfs/dir-readdir.c: Likewise. * libdiskfs/dir-rename.c: Likewise. * libdiskfs/dir-renamed.c: Likewise. * libdiskfs/dir-rmdir.c: Likewise. * libdiskfs/dir-unlink.c: Likewise. * libdiskfs/disk-pager.c: Likewise. * libdiskfs/diskfs-pager.h: Likewise. * libdiskfs/diskfs.h: Likewise. * libdiskfs/file-access.c: Likewise. * libdiskfs/file-chg.c: Likewise. * libdiskfs/file-exec.c: Likewise. * libdiskfs/file-get-fs-opts.c: Likewise. * libdiskfs/file-get-trans.c: Likewise. * libdiskfs/file-get-transcntl.c: Likewise. * libdiskfs/file-getcontrol.c: Likewise. * libdiskfs/file-getfh.c: Likewise. * libdiskfs/file-lock-stat.c: Likewise. * libdiskfs/file-lock.c: Likewise. * libdiskfs/file-reparent.c: Likewise. * libdiskfs/file-set-trans.c: Likewise. * libdiskfs/file-sync.c: Likewise. * libdiskfs/file-syncfs.c: Likewise. * libdiskfs/fsys-getroot.c: Likewise. * libdiskfs/fsys-options.c: Likewise. * libdiskfs/fsys-syncfs.c: Likewise. * libdiskfs/ifsock.c: Likewise. * libdiskfs/init-first.c: Likewise. * libdiskfs/init-init.c: Likewise. * libdiskfs/init-startup.c: Likewise. * libdiskfs/io-duplicate.c: Likewise. * libdiskfs/io-get-conch.c: Likewise. * libdiskfs/io-identity.c: Likewise. * libdiskfs/io-map-cntl.c: Likewise. * libdiskfs/io-map.c: Likewise. * libdiskfs/io-modes-get.c: Likewise. * libdiskfs/io-modes-off.c: Likewise. * libdiskfs/io-modes-on.c: Likewise. * libdiskfs/io-modes-set.c: Likewise. * libdiskfs/io-owner-get.c: Likewise. * libdiskfs/io-owner-mod.c: Likewise. * libdiskfs/io-prenotify.c: Likewise. * libdiskfs/io-read.c: Likewise. * libdiskfs/io-readable.c: Likewise. * libdiskfs/io-reauthenticate.c: Likewise. * libdiskfs/io-rel-conch.c: Likewise. * libdiskfs/io-restrict-auth.c: Likewise. * libdiskfs/io-revoke.c: Likewise. * libdiskfs/io-seek.c: Likewise. * libdiskfs/io-sigio.c: Likewise. * libdiskfs/io-stat.c: Likewise. * libdiskfs/io-write.c: Likewise. * libdiskfs/lookup.c: Likewise. * libdiskfs/name-cache.c: Likewise. * libdiskfs/node-drop.c: Likewise. * libdiskfs/node-make.c: Likewise. * libdiskfs/node-nput.c: Likewise. * libdiskfs/node-nputl.c: Likewise. * libdiskfs/node-nref.c: Likewise. * libdiskfs/node-nrefl.c: Likewise. * libdiskfs/node-nrele.c: Likewise. * libdiskfs/node-nrelel.c: Likewise. * libdiskfs/peropen-rele.c: Likewise. * libdiskfs/priv.h: Likewise. * libdiskfs/shutdown.c: Likewise. * libdiskfs/sync-interval.c: Likewise. * libfshelp/Makefile: Likewise. * libfshelp/fetch-root.c: Likewise. * libfshelp/fshelp.h: Likewise. * libfshelp/get-identity.c: Likewise. * libfshelp/lock-acquire.c: Likewise. * libfshelp/lock-init.c: Likewise. * libfshelp/locks.h: Likewise. * libfshelp/set-active.c: Likewise. * libfshelp/trans.h: Likewise. * libfshelp/transbox-init.c: Likewise. * libiohelp/Makefile: Likewise. * libiohelp/get_conch.c: Likewise. * libiohelp/handle_io_release_conch.c: Likewise. * libiohelp/initialize_conch.c: Likewise. * libiohelp/iohelp.h: Likewise. * libiohelp/verify_user_conch.c: Likewise. * libnetfs/Makefile: Likewise. * libnetfs/dir-lookup.c: Likewise. * libnetfs/dir-mkdir.c: Likewise. * libnetfs/dir-mkfile.c: Likewise. * libnetfs/dir-readdir.c: Likewise. * libnetfs/dir-rmdir.c: Likewise. * libnetfs/dir-unlink.c: Likewise. * libnetfs/drop-node.c: Likewise. * libnetfs/file-chauthor.c: Likewise. * libnetfs/file-check-access.c: Likewise. * libnetfs/file-chflags.c: Likewise. * libnetfs/file-chmod.c: Likewise. * libnetfs/file-chown.c: Likewise. * libnetfs/file-exec.c: Likewise. * libnetfs/file-get-storage-info.c: Likewise. * libnetfs/file-get-translator.c: Likewise. * libnetfs/file-lock-stat.c: Likewise. * libnetfs/file-lock.c: Likewise. * libnetfs/file-reparent.c: Likewise. * libnetfs/file-set-size.c: Likewise. * libnetfs/file-set-translator.c: Likewise. * libnetfs/file-statfs.c: Likewise. * libnetfs/file-sync.c: Likewise. * libnetfs/file-syncfs.c: Likewise. * libnetfs/file-utimes.c: Likewise. * libnetfs/fsys-getroot.c: Likewise. * libnetfs/fsys-set-options.c: Likewise. * libnetfs/init-init.c: Likewise. * libnetfs/io-clear-some-openmodes.c: Likewise. * libnetfs/io-duplicate.c: Likewise. * libnetfs/io-get-openmodes.c: Likewise. * libnetfs/io-get-owner.c: Likewise. * libnetfs/io-identity.c: Likewise. * libnetfs/io-mod-owner.c: Likewise. * libnetfs/io-read.c: Likewise. * libnetfs/io-readable.c: Likewise. * libnetfs/io-reauthenticate.c: Likewise. * libnetfs/io-restrict-auth.c: Likewise. * libnetfs/io-revoke.c: Likewise. * libnetfs/io-seek.c: Likewise. * libnetfs/io-set-all-openmodes.c: Likewise. * libnetfs/io-set-some-openmodes.c: Likewise. * libnetfs/io-stat.c: Likewise. * libnetfs/io-write.c: Likewise. * libnetfs/make-node.c: Likewise. * libnetfs/netfs.h: Likewise. * libnetfs/nput.c: Likewise. * libnetfs/nref.c: Likewise. * libnetfs/nrele.c: Likewise. * libnetfs/release-peropen.c: Likewise. * libnetfs/shutdown.c: Likewise. * libpager/Makefile: Likewise. * libpager/chg-compl.c: Likewise. * libpager/clean.c: Likewise. * libpager/data-request.c: Likewise. * libpager/data-return.c: Likewise. * libpager/data-unlock.c: Likewise. * libpager/inhibit-term.c: Likewise. * libpager/lock-completed.c: Likewise. * libpager/lock-object.c: Likewise. * libpager/mark-error.c: Likewise. * libpager/no-senders.c: Likewise. * libpager/object-init.c: Likewise. * libpager/object-terminate.c: Likewise. * libpager/offer-page.c: Likewise. * libpager/pager-attr.c: Likewise. * libpager/pager-create.c: Likewise. * libpager/pager-shutdown.c: Likewise. * libpager/priv.h: Likewise. * libpager/seqnos.c: Likewise. * libpipe/Makefile: Likewise. * libpipe/pipe.c: Likewise. * libpipe/pipe.h: Likewise. * libports/Makefile: Likewise. * libports/begin-rpc.c: Likewise. * libports/bucket-iterate.c: Likewise. * libports/claim-right.c: Likewise. * libports/class-iterate.c: Likewise. * libports/complete-deallocate.c: Likewise. * libports/count-bucket.c: Likewise. * libports/count-class.c: Likewise. * libports/create-bucket.c: Likewise. * libports/create-internal.c: Likewise. * libports/destroy-right.c: Likewise. * libports/enable-bucket.c: Likewise. * libports/enable-class.c: Likewise. * libports/end-rpc.c: Likewise. * libports/get-right.c: Likewise. * libports/import-port.c: Likewise. * libports/inhibit-all-rpcs.c: Likewise. * libports/inhibit-bucket-rpcs.c: Likewise. * libports/inhibit-class-rpcs.c: Likewise. * libports/inhibit-port-rpcs.c: Likewise. * libports/init.c: Likewise. * libports/interrupt-notified-rpcs.c: Likewise. * libports/interrupt-on-notify.c: Likewise. * libports/interrupt-operation.c: Likewise. * libports/interrupt-rpcs.c: Likewise. * libports/interrupted.c: Likewise. * libports/lookup-port.c: Likewise. * libports/manage-multithread.c: Likewise. * libports/no-senders.c: Likewise. * libports/port-deref-weak.c: Likewise. * libports/port-deref.c: Likewise. * libports/port-ref-weak.c: Likewise. * libports/port-ref.c: Likewise. * libports/ports.h: Likewise. * libports/reallocate-from-external.c: Likewise. * libports/reallocate-port.c: Likewise. * libports/resume-all-rpcs.c: Likewise. * libports/resume-bucket-rpcs.c: Likewise. * libports/resume-class-rpcs.c: Likewise. * libports/resume-port-rpcs.c: Likewise. * libports/stubs.c: Likewise. * libports/transfer-right.c: Likewise. * libstore/Makefile: Likewise. * libstore/gunzip.c: Likewise. * libstore/part.c: Likewise. * libstore/unzipstore.c: Likewise. * libthreads/Makefile: Likewise. * libtreefs/dir-lookup.c: Likewise. * libtreefs/fsys-getroot.c: Likewise. * libtreefs/fsys-hooks.c: Likewise. * libtreefs/fsys.c: Likewise. * libtreefs/trans-help.c: Likewise. * libtreefs/trans-start.c: Likewise. * libtreefs/treefs.h: Likewise. * libtrivfs/cntl-create.c: Likewise. * libtrivfs/dyn-classes.c: Likewise. * libtrivfs/io-reauthenticate.c: Likewise. * libtrivfs/io-restrict-auth.c: Likewise. * libtrivfs/protid-clean.c: Likewise. * libtrivfs/protid-dup.c: Likewise. * libtrivfs/trivfs.h: Likewise. * mach-defpager/Makefile: Likewise. * mach-defpager/default_pager.c: Likewise. * mach-defpager/kalloc.c: Likewise. * mach-defpager/main.c: Likewise. * nfs/Makefile: Likewise. * nfs/cache.c: Likewise. * nfs/main.c: Likewise. * nfs/mount.c: Likewise. * nfs/name-cache.c: Likewise. * nfs/nfs.h: Likewise. * nfs/ops.c: Likewise. * nfs/rpc.c: Likewise. * nfsd/Makefile: Likewise. * nfsd/cache.c: Likewise. * nfsd/loop.c: Likewise. * nfsd/main.c: Likewise. * nfsd/nfsd.h: Likewise. * pfinet/Makefile: Likewise. * pfinet/ethernet.c: Likewise. * pfinet/glue-include/asm/spinlock.h: Likewise. * pfinet/glue-include/linux/interrupt.h: Likewise. * pfinet/glue-include/linux/sched.h: Likewise. * pfinet/glue-include/linux/timer.h: Likewise. * pfinet/glue-include/linux/wait.h: Likewise. * pfinet/iioctl-ops.c: Likewise. * pfinet/io-ops.c: Likewise. * pfinet/kmem_cache.c: Likewise. * pfinet/main.c: Likewise. * pfinet/options.c: Likewise. * pfinet/pfinet-ops.c: Likewise. * pfinet/pfinet.h: Likewise. * pfinet/sched.c: Likewise. * pfinet/socket-ops.c: Likewise. * pfinet/socket.c: Likewise. * pfinet/timer-emul.c: Likewise. * pfinet/tunnel.c: Likewise. * pflocal/Makefile: Likewise. * pflocal/connq.c: Likewise. * pflocal/io.c: Likewise. * pflocal/sock.c: Likewise. * pflocal/sock.h: Likewise. * pflocal/socket.c: Likewise. * pflocal/sserver.c: Likewise. * proc/Makefile: Likewise. * proc/info.c: Likewise. * proc/main.c: Likewise. * proc/mgt.c: Likewise. * proc/msg.c: Likewise. * proc/proc.h: Likewise. * proc/stubs.c: Likewise. * proc/wait.c: Likewise. * storeio/Makefile: Likewise. * storeio/dev.c: Likewise. * storeio/dev.h: Likewise. * storeio/open.c: Likewise. * storeio/open.h: Likewise. * storeio/pager.c: Likewise. * storeio/storeio.c: Likewise. * term/Makefile: Likewise. * term/devio.c: Likewise. * term/hurdio.c: Likewise. * term/main.c: Likewise. * term/munge.c: Likewise. * term/ptyio.c: Likewise. * term/term.h: Likewise. * term/users.c: Likewise. * tmpfs/Makefile: Likewise. * tmpfs/dir.c: Likewise. * tmpfs/node.c: Likewise. * tmpfs/tmpfs.c: Likewise. * tmpfs/tmpfs.h: Likewise. * trans/Makefile: Likewise. * trans/fakeroot.c: Likewise. * trans/fifo.c: Likewise. * trans/hello-mt.c: Likewise. * trans/new-fifo.c: Likewise. * trans/streamio.c: Likewise. * ufs/Makefile: Likewise. * ufs/alloc.c: Likewise. * ufs/dir.c: Likewise. * ufs/hyper.c: Likewise. * ufs/inode.c: Likewise. * ufs/main.c: Likewise. * ufs/pager.c: Likewise. * ufs/pokeloc.c: Likewise. * ufs/sizes.c: Likewise. * ufs/ufs.h: Likewise. * usermux/Makefile: Likewise. * usermux/mux.c: Likewise. * usermux/node.c: Likewise. * usermux/usermux.h: Likewise. * utils/Makefile: Likewise. * utils/fakeauth.c: Likewise. * utils/rpctrace.c: Likewise. --- console-client/Makefile | 6 +- console-client/console.c | 120 +++++++++++++++++++-------------------- console-client/driver.c | 60 ++++++++++---------- console-client/driver.h | 33 +++++------ console-client/generic-speaker.c | 2 - console-client/kbd-repeat.c | 51 +++++++++-------- console-client/ncursesw.c | 66 +++++++++++---------- console-client/pc-kbd.c | 16 ++++-- console-client/pc-mouse.c | 65 ++++++++++++--------- console-client/timer.c | 42 ++++++++------ console-client/trans.c | 30 ++++++---- console-client/vga.c | 14 ++--- 12 files changed, 275 insertions(+), 230 deletions(-) (limited to 'console-client') diff --git a/console-client/Makefile b/console-client/Makefile index ce8ce353..69a7e371 100644 --- a/console-client/Makefile +++ b/console-client/Makefile @@ -36,8 +36,8 @@ SRCS = $(CONSOLE_SRCS) \ VPATH += $(srcdir)/xkb OBJS = $(addsuffix .o,$(basename $(notdir $(SRCS)))) kdioctlServer.o -HURDLIBS = cons threads ports netfs fshelp iohelp ihash shouldbeinlibc -LDLIBS = -ldl +HURDLIBS = cons ports netfs fshelp iohelp ihash shouldbeinlibc +LDLIBS = -ldl -lpthread module-dir = $(libdir)/hurd/console console-LDFLAGS = -Wl,-E @@ -62,7 +62,7 @@ driver-DEPS = $(..)config.make console: $(CONSOLE_SRCS:.c=.o) \ ../libnetfs/libnetfs.a ../libfshelp/libfshelp.a \ ../libcons/libcons.a ../libports/libports.a \ - ../libthreads/libthreads.a ../libshouldbeinlibc/libshouldbeinlibc.a + ../libshouldbeinlibc/libshouldbeinlibc.a modules = vga pc_kbd generic_speaker pc_mouse current_vcs diff --git a/console-client/console.c b/console-client/console.c index 06a8c1ac..806bec6d 100644 --- a/console-client/console.c +++ b/console-client/console.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include @@ -45,7 +45,7 @@ const char *cons_client_version = HURD_VERSION; /* The global lock protects the active_vcons variable, and thus all operations on the virtual console that is currently active. */ -static struct mutex global_lock; +static pthread_mutex_t global_lock; /* The active virtual console. This is the one currently displayed. */ @@ -70,15 +70,15 @@ console_current_id (int *cur) { vcons_t vcons; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); vcons = active_vcons; if (!vcons) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return ENODEV; } *cur = vcons->id; - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return 0; } @@ -99,28 +99,28 @@ console_switch (int id, int delta) it isn't deallocated while we are outside of the global lock. We also know that */ - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); vcons = active_vcons; if (!vcons) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return EINVAL; } ports_port_ref (vcons); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); err = cons_switch (vcons, id, delta, &new_vcons); if (!err) { - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); if (active_vcons != new_vcons) { cons_vcons_close (active_vcons); active_vcons = new_vcons; } - mutex_unlock (&new_vcons->lock); + pthread_mutex_unlock (&new_vcons->lock); ports_port_deref (vcons); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); } return err; } @@ -134,15 +134,15 @@ console_input (char *buf, size_t size) error_t err = 0; vcons_t vcons; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); vcons = active_vcons; if (!vcons) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return EINVAL; } ports_port_ref (vcons); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); if (vcons) { @@ -161,16 +161,16 @@ console_move_mouse (mouse_event_t ev) error_t err; vcons_t vcons; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); vcons = active_vcons; if (!vcons) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return EINVAL; } ports_port_ref (vcons); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); if (vcons) { @@ -178,7 +178,7 @@ console_move_mouse (mouse_event_t ev) ports_port_deref (vcons); } - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return 0; } @@ -192,15 +192,15 @@ console_scrollback (cons_scroll_t type, float value) int nr = 0; vcons_t vcons; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); vcons = active_vcons; if (!vcons) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return EINVAL; } ports_port_ref (vcons); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); if (vcons) { @@ -216,7 +216,7 @@ console_scrollback (cons_scroll_t type, float value) void console_switch_away (void) { - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); driver_iterate if (driver->ops->save_status) @@ -226,7 +226,7 @@ console_switch_away (void) saved_cons = active_vcons->cons; cons_vcons_close (active_vcons); active_vcons = NULL; - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); } /* Switch back to the console client from an external user of the @@ -235,7 +235,7 @@ void console_switch_back (void) { vcons_list_t conslist; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); driver_iterate if (driver->ops->restore_status) @@ -248,22 +248,22 @@ console_switch_back (void) err = cons_lookup (saved_cons, saved_id, 1, &conslist); if (err) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return; } err = cons_vcons_open (saved_cons, conslist, &active_vcons); if (err) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return; } conslist->vcons = active_vcons; saved_cons = NULL; - mutex_unlock (&active_vcons->lock); + pthread_mutex_unlock (&active_vcons->lock); } - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); } @@ -278,18 +278,18 @@ console_exit (void) /* Signal an error to the user. */ void console_error (const wchar_t *const err_msg) { - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); bell_iterate if (bell->ops->beep) bell->ops->beep (bell->handle); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); } #if QUAERENDO_INVENIETIS void console_deprecated (int key) { - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); input_iterate if (input->ops->deprecated) (*input->ops->deprecated) (input->handle, key); @@ -299,7 +299,7 @@ console_deprecated (int key) bell_iterate if (bell->ops->deprecated) (*bell->ops->deprecated) (bell->handle, key); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); } #endif /* QUAERENDO_INVENIETIS */ @@ -312,7 +312,7 @@ void cons_vcons_add (cons_t cons, vcons_list_t vcons_entry) { error_t err = 0; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); if (!active_vcons) { vcons_t vcons; @@ -324,10 +324,10 @@ cons_vcons_add (cons_t cons, vcons_list_t vcons_entry) { vcons_entry->vcons = vcons; active_vcons = vcons; - mutex_unlock (&vcons->lock); + pthread_mutex_unlock (&vcons->lock); } } - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); } @@ -341,12 +341,12 @@ cons_vcons_add (cons_t cons, vcons_list_t vcons_entry) void cons_vcons_update (vcons_t vcons) { - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); if (vcons == active_vcons) display_iterate if (display->ops->update) display->ops->update (display->handle); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); } @@ -355,12 +355,12 @@ cons_vcons_update (vcons_t vcons) void cons_vcons_set_cursor_pos (vcons_t vcons, uint32_t col, uint32_t row) { - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); if (vcons == active_vcons) display_iterate if (display->ops->set_cursor_pos) display->ops->set_cursor_pos (display->handle, col, row); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); } @@ -369,12 +369,12 @@ cons_vcons_set_cursor_pos (vcons_t vcons, uint32_t col, uint32_t row) void cons_vcons_set_cursor_status (vcons_t vcons, uint32_t status) { - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); if (vcons == active_vcons) display_iterate if (display->ops->set_cursor_status) display->ops->set_cursor_status (display->handle, status); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); } @@ -388,12 +388,12 @@ cons_vcons_set_cursor_status (vcons_t vcons, uint32_t status) void cons_vcons_scroll (vcons_t vcons, int delta) { - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); if (vcons == active_vcons) display_iterate if (display->ops->scroll) display->ops->scroll (display->handle, delta); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); } @@ -407,12 +407,12 @@ cons_vcons_scroll (vcons_t vcons, int delta) void cons_vcons_clear (vcons_t vcons, size_t length, uint32_t col, uint32_t row) { - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); if (vcons == active_vcons) display_iterate if (display->ops->clear) display->ops->clear (display->handle, length, col, row); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); } @@ -423,12 +423,12 @@ void cons_vcons_write (vcons_t vcons, conchar_t *str, size_t length, uint32_t col, uint32_t row) { - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); if (vcons == active_vcons) display_iterate if (display->ops->write) display->ops->write (display->handle, str, length, col, row); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); } @@ -437,12 +437,12 @@ cons_vcons_write (vcons_t vcons, conchar_t *str, size_t length, void cons_vcons_beep (vcons_t vcons) { - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); if (vcons == active_vcons) bell_iterate if (bell->ops->beep) bell->ops->beep (bell->handle); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); } @@ -451,12 +451,12 @@ cons_vcons_beep (vcons_t vcons) void cons_vcons_flash (vcons_t vcons) { - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); if (vcons == active_vcons) display_iterate if (display->ops->flash) display->ops->flash (display->handle); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); } @@ -465,12 +465,12 @@ cons_vcons_flash (vcons_t vcons) void cons_vcons_set_scroll_lock (vcons_t vcons, int onoff) { - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); if (vcons == active_vcons) input_iterate if (input->ops->set_scroll_lock_status) input->ops->set_scroll_lock_status (input->handle, onoff); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); } @@ -481,12 +481,12 @@ cons_vcons_set_scroll_lock (vcons_t vcons, int onoff) error_t cons_vcons_set_dimension (vcons_t vcons, uint32_t col, uint32_t row) { - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); if (vcons == active_vcons) display_iterate if (display->ops->set_dimension) display->ops->set_dimension (display->handle, col, row); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return 0; } @@ -494,12 +494,12 @@ cons_vcons_set_dimension (vcons_t vcons, uint32_t col, uint32_t row) error_t cons_vcons_set_mousecursor_pos (vcons_t vcons, float x, float y) { - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); if (vcons == active_vcons) display_iterate if (display->ops->set_mousecursor_pos) display->ops->set_mousecursor_pos (display->handle, x, y); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return 0; } @@ -507,12 +507,12 @@ cons_vcons_set_mousecursor_pos (vcons_t vcons, float x, float y) error_t cons_vcons_set_mousecursor_status (vcons_t vcons, int status) { - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); if (vcons == active_vcons) display_iterate if (display->ops->set_mousecursor_status) display->ops->set_mousecursor_status (display->handle, status); - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return 0; } @@ -615,7 +615,7 @@ main (int argc, char *argv[]) if (err) error (1, err, "Starting driver %s failed", errname); - mutex_init (&global_lock); + pthread_mutex_init (&global_lock, NULL); err = cons_init (); if (err) diff --git a/console-client/driver.c b/console-client/driver.c index 7f799f0a..64078241 100644 --- a/console-client/driver.c +++ b/console-client/driver.c @@ -25,7 +25,7 @@ #include -#include +#include #include "driver.h" @@ -42,7 +42,7 @@ char *driver_path; /* The driver list lock, the list itself, its current length and the total number of entries in the list. */ -struct mutex driver_list_lock; +pthread_mutex_t driver_list_lock; driver_t driver_list; size_t driver_list_len; size_t driver_list_alloc; @@ -52,10 +52,10 @@ size_t driver_list_alloc; error_t driver_init (void) { - mutex_init (&driver_list_lock); - mutex_init (&display_list_lock); - mutex_init (&input_list_lock); - mutex_init (&bell_list_lock); + pthread_mutex_init (&driver_list_lock, NULL); + pthread_mutex_init (&display_list_lock, NULL); + pthread_mutex_init (&input_list_lock, NULL); + pthread_mutex_init (&bell_list_lock, NULL); return 0; } @@ -67,7 +67,7 @@ driver_fini (void) { unsigned int i; - mutex_lock (&driver_list_lock); + pthread_mutex_lock (&driver_list_lock); for (i = 0; i < driver_list_len; i++) { driver_list[i].ops->fini (driver_list[i].handle, 1); @@ -76,7 +76,7 @@ driver_fini (void) free (driver_list[i].driver); } driver_list_len = 0; - mutex_unlock (&driver_list_lock); + pthread_mutex_unlock (&driver_list_lock); return 0; } @@ -101,11 +101,11 @@ error_t driver_add (const char *const name, const char *const driver, int defpath = 0; char *opt_backup; - mutex_lock (&driver_list_lock); + pthread_mutex_lock (&driver_list_lock); for (i = 0; i < driver_list_len; i++) if (driver_list[i].name && !strcmp (driver_list[i].name, name)) { - mutex_unlock (&driver_list_lock); + pthread_mutex_unlock (&driver_list_lock); return EEXIST; } @@ -122,7 +122,7 @@ error_t driver_add (const char *const name, const char *const driver, if (asprintf (&filename, "%s/%s%s", dir, driver, CONSOLE_SONAME_SUFFIX) < 0) { - mutex_unlock (&driver_list_lock); + pthread_mutex_unlock (&driver_list_lock); return ENOMEM; } @@ -134,7 +134,7 @@ error_t driver_add (const char *const name, const char *const driver, if (errno != ENOENT) { free (filename); - mutex_unlock (&driver_list_lock); + pthread_mutex_unlock (&driver_list_lock); return errno ?: EGRATUITOUS; } } @@ -158,7 +158,7 @@ error_t driver_add (const char *const name, const char *const driver, { if (filename) free (filename); - mutex_unlock (&driver_list_lock); + pthread_mutex_unlock (&driver_list_lock); return ENOENT; } @@ -166,7 +166,7 @@ error_t driver_add (const char *const name, const char *const driver, { dlclose (shobj); free (filename); - mutex_unlock (&driver_list_lock); + pthread_mutex_unlock (&driver_list_lock); return ENOMEM; } @@ -176,7 +176,7 @@ error_t driver_add (const char *const name, const char *const driver, { dlclose (shobj); free (filename); - mutex_unlock (&driver_list_lock); + pthread_mutex_unlock (&driver_list_lock); return EGRATUITOUS; } @@ -189,7 +189,7 @@ error_t driver_add (const char *const name, const char *const driver, { dlclose (shobj); free (filename); - mutex_unlock (&driver_list_lock); + pthread_mutex_unlock (&driver_list_lock); return errno; } driver_list = new_list; @@ -210,7 +210,7 @@ error_t driver_add (const char *const name, const char *const driver, free (drv->driver); dlclose (shobj); free (filename); - mutex_unlock (&driver_list_lock); + pthread_mutex_unlock (&driver_list_lock); return ENOMEM; } @@ -229,12 +229,12 @@ error_t driver_add (const char *const name, const char *const driver, free (drv->driver); dlclose (shobj); free (filename); - mutex_unlock (&driver_list_lock); + pthread_mutex_unlock (&driver_list_lock); return err; } driver_list_len++; - mutex_unlock (&driver_list_lock); + pthread_mutex_unlock (&driver_list_lock); return 0; } @@ -250,7 +250,7 @@ driver_start (char **name) error_t err = 0; int i; - mutex_lock (&driver_list_lock); + pthread_mutex_lock (&driver_list_lock); for (i = 0; i < driver_list_len; i++) { if (driver_list[i].ops->start) @@ -266,7 +266,7 @@ driver_start (char **name) break; } } - mutex_unlock (&driver_list_lock); + pthread_mutex_unlock (&driver_list_lock); return err; } @@ -279,7 +279,7 @@ error_t driver_remove (const char *const name) error_t err; unsigned int i; - mutex_lock (&driver_list_lock); + pthread_mutex_lock (&driver_list_lock); for (i = 0; i < driver_list_len; i++) if (driver_list[i].name && !strcmp (driver_list[i].name, name)) { @@ -297,15 +297,15 @@ error_t driver_remove (const char *const name) } driver_list_len--; } - mutex_unlock (&driver_list_lock); + pthread_mutex_unlock (&driver_list_lock); return err; } - mutex_unlock (&driver_list_lock); + pthread_mutex_unlock (&driver_list_lock); return ESRCH; } #define ADD_REMOVE_COMPONENT(component) \ -struct mutex component##_list_lock; \ +pthread_mutex_t component##_list_lock; \ component##_t component##_list; \ size_t component##_list_len; \ size_t component##_list_alloc; \ @@ -313,7 +313,7 @@ size_t component##_list_alloc; \ error_t \ driver_add_##component (component##_ops_t ops, void *handle) \ { \ - mutex_lock (&component##_list_lock); \ + pthread_mutex_lock (&component##_list_lock); \ if (component##_list_len == component##_list_alloc) \ { \ size_t new_alloc = component##_list_alloc + LIST_GROW; \ @@ -322,7 +322,7 @@ driver_add_##component (component##_ops_t ops, void *handle) \ * sizeof (*component##_list)); \ if (!new_list) \ { \ - mutex_unlock (&component##_list_lock); \ + pthread_mutex_unlock (&component##_list_lock); \ return errno; \ } \ component##_list = new_list; \ @@ -331,7 +331,7 @@ driver_add_##component (component##_ops_t ops, void *handle) \ component##_list[component##_list_len].ops = ops; \ component##_list[component##_list_len].handle = handle; \ component##_list_len++; \ - mutex_unlock (&component##_list_lock); \ + pthread_mutex_unlock (&component##_list_lock); \ return 0; \ } \ \ @@ -340,7 +340,7 @@ driver_remove_##component (component##_ops_t ops, void *handle) \ { \ unsigned int i; \ \ - mutex_lock (&component##_list_lock); \ + pthread_mutex_lock (&component##_list_lock); \ for (i = 0; i < component##_list_len; i++) \ if (component##_list[i].ops == ops \ && component##_list[i].handle == handle) \ @@ -352,7 +352,7 @@ driver_remove_##component (component##_ops_t ops, void *handle) \ } \ component##_list_len--; \ } \ - mutex_unlock (&component##_list_lock); \ + pthread_mutex_unlock (&component##_list_lock); \ return 0; \ } diff --git a/console-client/driver.h b/console-client/driver.h index aacd5890..c1b24b07 100644 --- a/console-client/driver.h +++ b/console-client/driver.h @@ -23,6 +23,7 @@ #include #include +#include #include "display.h" #include "input.h" @@ -87,10 +88,10 @@ error_t driver_remove (const char *const name); The variable DRIVER is provided by the macro. */ #define driver_iterate \ - for (driver_t driver = (mutex_lock (&driver_list_lock), \ + for (driver_t driver = (pthread_mutex_lock (&driver_list_lock), \ &driver_list[0]); \ driver < &driver_list[driver_list_len] \ - || (mutex_unlock (&driver_list_lock), 0); \ + || (pthread_mutex_unlock (&driver_list_lock), 0); \ driver++) @@ -194,7 +195,7 @@ typedef struct driver *driver_t; /* Forward declarations needed by the macro above. Don't use these variables directly. */ -extern struct mutex driver_list_lock; +extern pthread_mutex_t driver_list_lock; extern driver_t driver_list; extern size_t driver_list_len; @@ -206,10 +207,10 @@ extern size_t driver_list_len; The variable DISPLAY is provided by the macro. */ #define display_iterate \ - for (display_t display = (mutex_lock (&display_list_lock), \ + for (display_t display = (pthread_mutex_lock (&display_list_lock), \ &display_list[0]); \ display < &display_list[display_list_len] \ - || (mutex_unlock (&display_list_lock), 0); \ + || (pthread_mutex_unlock (&display_list_lock), 0); \ display++) @@ -224,7 +225,7 @@ typedef struct display *display_t; /* Forward declarations needed by the macro above. Don't use these variables directly. */ -extern struct mutex display_list_lock; +extern pthread_mutex_t display_list_lock; extern display_t display_list; extern size_t display_list_len; @@ -235,10 +236,10 @@ extern size_t display_list_len; input_iterate input->ops->set_scroll_lock_status (input->handle, 0); The variable INPUT is provided by the macro. */ -#define input_iterate \ - for (input_t input = (mutex_lock (&input_list_lock), &input_list[0]); \ - input < &input_list[input_list_len] \ - || (mutex_unlock (&input_list_lock), 0); \ +#define input_iterate \ + for (input_t input = (pthread_mutex_lock (&input_list_lock), &input_list[0]); \ + input < &input_list[input_list_len] \ + || (pthread_mutex_unlock (&input_list_lock), 0); \ input++) @@ -253,7 +254,7 @@ typedef struct input *input_t; /* Forward declarations needed by the macro above. Don't use these variables directly. */ -extern struct mutex input_list_lock; +extern pthread_mutex_t input_list_lock; extern input_t input_list; extern size_t input_list_len; @@ -264,10 +265,10 @@ extern size_t input_list_len; bell_iterate bell->ops->beep (bell->handle); The variable BELL is provided by the macro. */ -#define bell_iterate \ - for (bell_t bell = (mutex_lock (&bell_list_lock), &bell_list[0]); \ - bell < &bell_list[bell_list_len] \ - || (mutex_unlock (&bell_list_lock), 0); \ +#define bell_iterate \ + for (bell_t bell = (pthread_mutex_lock (&bell_list_lock), &bell_list[0]); \ + bell < &bell_list[bell_list_len] \ + || (pthread_mutex_unlock (&bell_list_lock), 0); \ bell++) @@ -282,7 +283,7 @@ typedef struct bell *bell_t; /* Forward declarations needed by the macro above. Don't use these variables directly. */ -extern struct mutex bell_list_lock; +extern pthread_mutex_t bell_list_lock; extern bell_t bell_list; extern size_t bell_list_len; diff --git a/console-client/generic-speaker.c b/console-client/generic-speaker.c index 5d8f509c..c03cc47e 100644 --- a/console-client/generic-speaker.c +++ b/console-client/generic-speaker.c @@ -23,8 +23,6 @@ #include #include -#include - #include "driver.h" #include "timer.h" diff --git a/console-client/kbd-repeat.c b/console-client/kbd-repeat.c index b9000b22..ddfd1cf4 100644 --- a/console-client/kbd-repeat.c +++ b/console-client/kbd-repeat.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "kdioctl_S.h" @@ -44,15 +45,15 @@ static struct kbdbuf char keybuffer[KBDBUFSZ]; int pos; size_t size; - struct condition readcond; - struct condition writecond; + pthread_cond_t readcond; + pthread_cond_t writecond; } kbdbuf; /* Wakeup for select */ -static struct condition select_alert; +static pthread_cond_t select_alert; /* The global lock */ -static struct mutex global_lock; +static pthread_mutex_t global_lock; /* Amount of times the device was opened. Normally this translator should be only opened once. */ @@ -65,13 +66,13 @@ kbd_repeat_key (kd_event *key) { kd_event *ev; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); while (kbdbuf.size + sizeof (kd_event) > KBDBUFSZ) { /* The input buffer is full, wait until there is some space. */ - if (hurd_condition_wait (&kbdbuf.writecond, &global_lock)) + if (pthread_hurd_cond_wait_np (&kbdbuf.writecond, &global_lock)) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); /* Interrupt, silently continue. */ } } @@ -80,9 +81,9 @@ kbd_repeat_key (kd_event *key) kbdbuf.size += sizeof (kd_event); memcpy (ev, key, sizeof (kd_event)); - condition_broadcast (&kbdbuf.readcond); - condition_broadcast (&select_alert); - mutex_unlock (&global_lock); + pthread_cond_broadcast (&kbdbuf.readcond); + pthread_cond_broadcast (&select_alert); + pthread_mutex_unlock (&global_lock); } @@ -99,22 +100,22 @@ repeater_select (struct protid *cred, mach_port_t reply, if (*type == 0) return 0; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); while (1) { if (kbdbuf.size > 0) { *type = SELECT_READ; - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return 0; } ports_interrupt_self_on_port_death (cred, reply); - if (hurd_condition_wait (&select_alert, &global_lock)) + if (pthread_hurd_cond_wait_np (&select_alert, &global_lock)) { *type = 0; - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return EINTR; } @@ -133,18 +134,18 @@ repeater_read (struct protid *cred, char **data, else if (! (cred->po->openstat & O_READ)) return EBADF; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); while (amount > kbdbuf.size) { if (cred->po->openstat & O_NONBLOCK && amount > kbdbuf.size) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return EWOULDBLOCK; } - if (hurd_condition_wait (&kbdbuf.readcond, &global_lock)) + if (pthread_hurd_cond_wait_np (&kbdbuf.readcond, &global_lock)) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return EINTR; } } @@ -160,7 +161,7 @@ repeater_read (struct protid *cred, char **data, *data = mmap (0, amount, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); if (*data == MAP_FAILED) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return ENOMEM; } } @@ -174,11 +175,11 @@ repeater_read (struct protid *cred, char **data, kbdbuf.pos = KBDBUF_POS (kbdbuf.pos); } kbdbuf.size -= amount; - condition_broadcast (&kbdbuf.writecond); + pthread_cond_broadcast (&kbdbuf.writecond); } *datalen = amount; - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return 0; } @@ -228,11 +229,11 @@ kbd_setrepeater (const char *nodename, consnode_t *cn) (*cn)->close = repeater_close; (*cn)->demuxer = kdioctl_server; - mutex_init (&global_lock); + pthread_mutex_init (&global_lock, NULL); - condition_init (&kbdbuf.readcond); - condition_init (&kbdbuf.writecond); - condition_init (&select_alert); + pthread_cond_init (&kbdbuf.readcond, NULL); + pthread_cond_init (&kbdbuf.writecond, NULL); + pthread_cond_init (&select_alert, NULL); console_register_consnode (*cn); diff --git a/console-client/ncursesw.c b/console-client/ncursesw.c index a34026a2..881acad7 100644 --- a/console-client/ncursesw.c +++ b/console-client/ncursesw.c @@ -26,7 +26,7 @@ -I${prefix}/ncursesw. */ #include -#include +#include #include #include "driver.h" @@ -34,7 +34,7 @@ /* ncurses is not thread-safe. This lock protects all calls into the ncurses library. */ -static struct mutex ncurses_lock; +static pthread_mutex_t ncurses_lock; /* The current width and height the ncursesw driver is using. */ static unsigned int current_width; @@ -286,8 +286,8 @@ refresh_screen (void) ? current_width : (unsigned int) COLS) - 1); } -static any_t -input_loop (any_t unused) +static void * +input_loop (void *unused) { int fd = 0; fd_set rfds; @@ -309,7 +309,7 @@ input_loop (any_t unused) char *buf = buffer; size_t size = 0; - mutex_lock (&ncurses_lock); + pthread_mutex_lock (&ncurses_lock); while ((ret = wgetch (conspad)) != ERR) { unsigned int i; @@ -320,7 +320,7 @@ input_loop (any_t unused) switch (ret) { case 'x': - mutex_unlock (&ncurses_lock); + pthread_mutex_unlock (&ncurses_lock); console_exit (); break; case 23: /* ^W */ @@ -337,9 +337,9 @@ input_loop (any_t unused) case '8': case '9': /* Avoid a dead lock. */ - mutex_unlock (&ncurses_lock); + pthread_mutex_unlock (&ncurses_lock); console_switch (1 + (ret - '1'), 0); - mutex_lock (&ncurses_lock); + pthread_mutex_lock (&ncurses_lock); break; case 'j': /* Scroll pad to left. */ @@ -414,7 +414,7 @@ input_loop (any_t unused) break; } } - mutex_unlock (&ncurses_lock); + pthread_mutex_unlock (&ncurses_lock); if (size) console_input (buf, size); } @@ -494,9 +494,9 @@ mvwputsn (conchar_t *str, size_t len, off_t x, off_t y) static error_t ncursesw_update (void *handle) { - mutex_lock (&ncurses_lock); + pthread_mutex_lock (&ncurses_lock); refresh_screen (); - mutex_unlock (&ncurses_lock); + pthread_mutex_unlock (&ncurses_lock); return 0; } @@ -504,7 +504,7 @@ ncursesw_update (void *handle) static error_t ncursesw_set_cursor_pos (void *handle, uint32_t col, uint32_t row) { - mutex_lock (&ncurses_lock); + pthread_mutex_lock (&ncurses_lock); assert (current_width && current_height); if (autoscroll) { @@ -544,7 +544,7 @@ ncursesw_set_cursor_pos (void *handle, uint32_t col, uint32_t row) wmove (conspad, row, col); - mutex_unlock (&ncurses_lock); + pthread_mutex_unlock (&ncurses_lock); return 0; } @@ -552,7 +552,7 @@ ncursesw_set_cursor_pos (void *handle, uint32_t col, uint32_t row) static error_t ncursesw_set_cursor_status (void *handle, uint32_t status) { - mutex_lock (&ncurses_lock); + pthread_mutex_lock (&ncurses_lock); /* If the cursor is invisible and switching to one visible state is impossible, switch to the other visible state or else the cursor @@ -560,7 +560,7 @@ ncursesw_set_cursor_status (void *handle, uint32_t status) if (curs_set (status) == -1 && status) curs_set (status == 1 ? 2 : 1); - mutex_unlock (&ncurses_lock); + pthread_mutex_unlock (&ncurses_lock); return 0; } @@ -571,13 +571,13 @@ ncursesw_scroll (void *handle, int delta) /* XXX We don't support scrollback for now. */ assert (delta >= 0); - mutex_lock (&ncurses_lock); + pthread_mutex_lock (&ncurses_lock); idlok (conspad, TRUE); scrollok (conspad, TRUE); wscrl (conspad, delta); idlok (conspad, FALSE); scrollok (conspad, FALSE); - mutex_unlock (&ncurses_lock); + pthread_mutex_unlock (&ncurses_lock); return 0; } @@ -589,11 +589,11 @@ ncursesw_write (void *handle, conchar_t *str, size_t length, int x; int y; - mutex_lock (&ncurses_lock); + pthread_mutex_lock (&ncurses_lock); getyx (conspad, y, x); mvwputsn (str, length, col, row); wmove (conspad, y, x); - mutex_unlock (&ncurses_lock); + pthread_mutex_unlock (&ncurses_lock); return 0; } @@ -601,9 +601,9 @@ ncursesw_write (void *handle, conchar_t *str, size_t length, static error_t ncursesw_flash (void *handle) { - mutex_lock (&ncurses_lock); + pthread_mutex_lock (&ncurses_lock); flash (); - mutex_unlock (&ncurses_lock); + pthread_mutex_unlock (&ncurses_lock); return 0; } @@ -612,9 +612,9 @@ ncursesw_flash (void *handle) error_t ncursesw_beep (void *handle) { - mutex_lock (&ncurses_lock); + pthread_mutex_lock (&ncurses_lock); beep (); - mutex_unlock (&ncurses_lock); + pthread_mutex_unlock (&ncurses_lock); return 0; } @@ -624,13 +624,14 @@ static error_t ncursesw_driver_init (void **handle, int no_exit, int argc, char *argv[], int *next) { - mutex_init (&ncurses_lock); + pthread_mutex_init (&ncurses_lock, NULL); return 0; } static error_t ncursesw_driver_start (void *handle) { + pthread_t thread; error_t err; int i; @@ -675,7 +676,14 @@ ncursesw_driver_start (void *handle) return err; } - cthread_detach (cthread_fork (input_loop, NULL)); + err = pthread_create (&thread, NULL, input_loop, NULL); + if (!err) + pthread_detach (thread); + else + { + errno = err; + perror ("pthread_create"); + } return 0; } @@ -685,11 +693,11 @@ static error_t ncursesw_driver_fini (void *handle, int force) { /* XXX Cancel the input thread. */ - mutex_lock (&ncurses_lock); + pthread_mutex_lock (&ncurses_lock); driver_remove_display (&ncursesw_display_ops, NULL); driver_remove_input (&ncursesw_input_ops, NULL); driver_remove_bell (&ncursesw_bell_ops, NULL); - mutex_unlock (&ncurses_lock); + pthread_mutex_unlock (&ncurses_lock); endwin (); return 0; @@ -698,7 +706,7 @@ ncursesw_driver_fini (void *handle, int force) static error_t ncursesw_set_dimension (void *handle, unsigned int width, unsigned int height) { - mutex_lock (&ncurses_lock); + pthread_mutex_lock (&ncurses_lock); if (width != current_width || height != current_height) { wresize (conspad, height, width); @@ -707,7 +715,7 @@ ncursesw_set_dimension (void *handle, unsigned int width, unsigned int height) } current_width = width; current_height = height; - mutex_unlock(&ncurses_lock); + pthread_mutex_unlock(&ncurses_lock); return 0; } diff --git a/console-client/pc-kbd.c b/console-client/pc-kbd.c index 95109e52..c6eda86f 100644 --- a/console-client/pc-kbd.c +++ b/console-client/pc-kbd.c @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include @@ -786,8 +786,8 @@ read_keycode (void) #endif /* XKB_SUPPORT */ /* The input loop. */ -static any_t -input_loop (any_t unused) +static void * +input_loop (void *unused) { #ifdef XKB_SUPPORT /* XXX: until conversion from scancode to keycode is properly implemented @@ -1350,6 +1350,7 @@ static error_t pc_kbd_start (void *handle) { error_t err; + pthread_t thread; device_t device_master; cd = iconv_open ("UTF-8", "WCHAR_T"); @@ -1412,7 +1413,14 @@ pc_kbd_start (void *handle) if (repeater_node) kbd_setrepeater (repeater_node, &cnode); - cthread_detach (cthread_fork (input_loop, NULL)); + err = pthread_create (&thread, NULL, input_loop, NULL); + if (!err) + pthread_detach (thread); + else + { + errno = err; + perror ("pthread_create"); + } return 0; } diff --git a/console-client/pc-mouse.c b/console-client/pc-mouse.c index 8a9009fb..1b7bb5d7 100644 --- a/console-client/pc-mouse.c +++ b/console-client/pc-mouse.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "driver.h" #include "mach-inputdev.h" @@ -60,15 +61,15 @@ static struct mousebuf char evtbuffer[MOUSEBUFSZ]; int pos; size_t size; - struct condition readcond; - struct condition writecond; + pthread_cond_t readcond; + pthread_cond_t writecond; } mousebuf; /* Wakeup for select */ -static struct condition select_alert; +static pthread_cond_t select_alert; /* The global lock */ -static struct mutex global_lock; +static pthread_mutex_t global_lock; /* Amount of times the device was opened. Normally this translator should be only opened once. */ @@ -89,13 +90,13 @@ repeat_event (kd_event *evt) { kd_event *ev; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); while (mousebuf.size + sizeof (kd_event) > MOUSEBUFSZ) { /* The input buffer is full, wait until there is some space. */ - if (hurd_condition_wait (&mousebuf.writecond, &global_lock)) + if (pthread_hurd_cond_wait_np (&mousebuf.writecond, &global_lock)) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); /* Interrupt, silently continue. */ } } @@ -104,9 +105,9 @@ repeat_event (kd_event *evt) mousebuf.size += sizeof (kd_event); memcpy (ev, evt, sizeof (kd_event)); - condition_broadcast (&mousebuf.readcond); - condition_broadcast (&select_alert); - mutex_unlock (&global_lock); + pthread_cond_broadcast (&mousebuf.readcond); + pthread_cond_broadcast (&select_alert); + pthread_mutex_unlock (&global_lock); } @@ -123,22 +124,22 @@ repeater_select (struct protid *cred, mach_port_t reply, if (*type == 0) return 0; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); while (1) { if (mousebuf.size > 0) { *type = SELECT_READ; - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return 0; } ports_interrupt_self_on_port_death (cred, reply); - if (hurd_condition_wait (&select_alert, &global_lock)) + if (pthread_hurd_cond_wait_np (&select_alert, &global_lock)) { *type = 0; - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return EINTR; } @@ -176,18 +177,18 @@ repeater_read (struct protid *cred, char **data, else if (! (cred->po->openstat & O_READ)) return EBADF; - mutex_lock (&global_lock); + pthread_mutex_lock (&global_lock); while (!mousebuf.size) { if (cred->po->openstat & O_NONBLOCK && mousebuf.size == 0) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return EWOULDBLOCK; } - if (hurd_condition_wait (&mousebuf.readcond, &global_lock)) + if (pthread_hurd_cond_wait_np (&mousebuf.readcond, &global_lock)) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return EINTR; } } @@ -207,7 +208,7 @@ repeater_read (struct protid *cred, char **data, *data = mmap (0, amount, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); if (*data == MAP_FAILED) { - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return ENOMEM; } } @@ -221,19 +222,19 @@ repeater_read (struct protid *cred, char **data, mousebuf.pos = MOUSEBUF_POS (mousebuf.pos); } mousebuf.size -= amount; - condition_broadcast (&mousebuf.writecond); + pthread_cond_broadcast (&mousebuf.writecond); } *datalen = amount; - mutex_unlock (&global_lock); + pthread_mutex_unlock (&global_lock); return 0; } -static any_t -input_loop (any_t unused) +static void * +input_loop (void *unused) { kd_event *ev; vm_offset_t buf; @@ -420,6 +421,7 @@ static error_t pc_mouse_start (void *handle) { error_t err; + pthread_t thread; char device_name[9]; int devnum = majordev << 3 | minordev; device_t device_master; @@ -443,7 +445,14 @@ pc_mouse_start (void *handle) return err; } - cthread_detach (cthread_fork (input_loop, NULL)); + err = pthread_create (&thread, NULL, input_loop, NULL); + if (!err) + pthread_detach (thread); + else + { + errno = err; + perror ("pthread_create"); + } if (repeater_node) setrepeater (repeater_node); @@ -496,11 +505,11 @@ setrepeater (const char *nodename) cnode->close = repeater_close; cnode->demuxer = 0; - mutex_init (&global_lock); + pthread_mutex_init (&global_lock, NULL); - condition_init (&mousebuf.readcond); - condition_init (&mousebuf.writecond); - condition_init (&select_alert); + pthread_cond_init (&mousebuf.readcond, NULL); + pthread_cond_init (&mousebuf.writecond, NULL); + pthread_cond_init (&select_alert, NULL); console_register_consnode (cnode); diff --git a/console-client/timer.c b/console-client/timer.c index 7bcdeab0..a8869b5e 100644 --- a/console-client/timer.c +++ b/console-client/timer.c @@ -21,8 +21,9 @@ #include #include #include - -#include +#include +#include +#include #include "timer.h" @@ -37,7 +38,7 @@ volatile struct mapped_time_value *timer_mapped_time; static thread_t timer_thread; /* The lock protects the timer list TIMERS. */ -static struct mutex timer_lock; +static pthread_mutex_t timer_lock; /* A list of all active timers. */ static struct timer_list *timers; @@ -84,15 +85,15 @@ kick_timer_thread (void) } /* The timer thread. */ -static int -timer_function (int this_is_a_pointless_variable_with_a_rather_long_name) +static void * +timer_function (void *this_is_a_pointless_variable_with_a_rather_long_name) { mach_port_t recv = mach_reply_port (); int wait = 0; timer_thread = mach_thread_self (); - mutex_lock (&timer_lock); + pthread_mutex_lock (&timer_lock); while (1) { int jiff = fetch_jiffies (); @@ -104,11 +105,11 @@ timer_function (int this_is_a_pointless_variable_with_a_rather_long_name) else wait = ((timers->expires - jiff) * 1000) / HZ; - mutex_unlock (&timer_lock); + pthread_mutex_unlock (&timer_lock); mach_msg (NULL, (MACH_RCV_MSG | MACH_RCV_INTERRUPT | (wait == -1 ? 0 : MACH_RCV_TIMEOUT)), 0, 0, recv, wait, MACH_PORT_NULL); - mutex_lock (&timer_lock); + pthread_mutex_lock (&timer_lock); while (timers && timers->expires < fetch_jiffies ()) { @@ -128,7 +129,7 @@ timer_function (int this_is_a_pointless_variable_with_a_rather_long_name) } } - return 0; + return NULL; } @@ -138,8 +139,9 @@ timer_init (void) { error_t err; struct timeval tp; + pthread_t thread; - mutex_init (&timer_lock); + pthread_mutex_init (&timer_lock, NULL); err = maptime_map (0, 0, &timer_mapped_time); if (err) @@ -150,7 +152,15 @@ timer_init (void) timer_root_jiffies = (long long) tp.tv_sec * HZ + ((long long) tp.tv_usec * HZ) / 1000000; - cthread_detach (cthread_fork ((cthread_fn_t) timer_function, 0)); + err = pthread_create (&thread, NULL, timer_function, NULL); + if (!err) + pthread_detach (thread); + else + { + errno = err; + perror ("pthread_create"); + } + return 0; } @@ -166,20 +176,20 @@ timer_clear (struct timer_list *timer) void timer_add (struct timer_list *timer) { - mutex_lock (&timer_lock); + pthread_mutex_lock (&timer_lock); timer_add_internal (timer); if (timers == timer) kick_timer_thread (); - mutex_unlock (&timer_lock); + pthread_mutex_unlock (&timer_lock); } /* Remove the timer TIMER from the list. */ int timer_remove (struct timer_list *timer) { - mutex_lock (&timer_lock); + pthread_mutex_lock (&timer_lock); if (timer->prev) { *timer->prev = timer->next; @@ -188,12 +198,12 @@ timer_remove (struct timer_list *timer) timer->next = 0; timer->prev = 0; - mutex_unlock (&timer_lock); + pthread_mutex_unlock (&timer_lock); return 1; } else { - mutex_unlock (&timer_lock); + pthread_mutex_unlock (&timer_lock); return 0; } } diff --git a/console-client/trans.c b/console-client/trans.c index a90b5c5d..67c84b4e 100644 --- a/console-client/trans.c +++ b/console-client/trans.c @@ -22,11 +22,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include "trans.h" @@ -305,11 +307,11 @@ netfs_attempt_lookup (struct iouser *user, struct node *dir, err = ENOENT; out: - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); if (err) *node = 0; else - mutex_lock (&(*node)->lock); + pthread_mutex_lock (&(*node)->lock); if (!err && *node != dir && (*node)->nn->node->open) (*node)->nn->node->open (); @@ -454,15 +456,15 @@ netfs_attempt_mkfile (struct iouser *user, struct node *dir, return err; } - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); nn = calloc (1, sizeof (*nn)); if (!nn) return ENOMEM; *np = netfs_make_node (nn); - mutex_lock (&(*np)->lock); - spin_unlock (&netfs_node_refcnt_lock); + pthread_mutex_lock (&(*np)->lock); + pthread_spin_unlock (&netfs_node_refcnt_lock); return 0; } @@ -477,7 +479,7 @@ netfs_attempt_create_file (struct iouser *user, struct node *dir, char *name, mode_t mode, struct node **np) { *np = 0; - mutex_unlock (&dir->lock); + pthread_mutex_unlock (&dir->lock); return EOPNOTSUPP; } @@ -604,7 +606,7 @@ void netfs_node_norefs (struct node *np) if (np->nn->symlink_path) free (np->nn->symlink_path); - spin_unlock (&netfs_node_refcnt_lock); + pthread_spin_unlock (&netfs_node_refcnt_lock); free (np->nn); free (np); } @@ -738,8 +740,8 @@ netfs_get_dirents (struct iouser *cred, struct node *dir, -static any_t -console_client_translator (any_t unused) +static void * +console_client_translator (void *unused) { error_t err; @@ -831,6 +833,7 @@ console_setup_node (char *path) file_t node; struct port_info *newpi; mach_port_t right; + pthread_t thread; node = file_name_lookup (path, O_CREAT|O_NOTRANS, 0664); if (node == MACH_PORT_NULL) @@ -886,7 +889,14 @@ console_setup_node (char *path) fshelp_touch (&netfs_root_node->nn_stat, TOUCH_ATIME|TOUCH_MTIME|TOUCH_CTIME, console_maptime); - cthread_detach (cthread_fork (console_client_translator, NULL)); + err = pthread_create (&thread, NULL, console_client_translator, NULL); + if (!err) + pthread_detach (thread); + else + { + errno = err; + perror ("pthread_create"); + } return 0; } diff --git a/console-client/vga.c b/console-client/vga.c index 9e8abb3a..8a3260bf 100644 --- a/console-client/vga.c +++ b/console-client/vga.c @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include "driver.h" @@ -69,7 +69,7 @@ static int vga_display_max_glyphs; static struct timer_list vga_display_timer; /* The lock that protects the color palette manipulation. */ -static struct mutex vga_display_lock; +static pthread_mutex_t vga_display_lock; /* Forward declaration. */ static struct display_ops vga_display_ops; @@ -134,13 +134,13 @@ vga_display_invert_border (void) { unsigned char col[3]; - mutex_lock (&vga_display_lock); + pthread_mutex_lock (&vga_display_lock); vga_read_palette (0, col, 1); col[0] = 0xff - col[0]; col[1] = 0xff - col[1]; col[2] = 0xff - col[2]; vga_write_palette (0, col, 1); - mutex_unlock (&vga_display_lock); + pthread_mutex_unlock (&vga_display_lock); } @@ -274,7 +274,7 @@ vga_display_init (void **handle, int no_exit, int argc, char *argv[], int pos = 1; /* XXX Assert that we are called only once. */ - mutex_init (&vga_display_lock); + pthread_mutex_init (&vga_display_lock, NULL); timer_clear (&vga_display_timer); vga_display_timer.fnc = &vga_display_flash_off; @@ -578,10 +578,10 @@ vga_display_recalculate_attr (dynacolor_t *dc, conchar_attr_t attr) /* Try to get the colors as desired. This might change the palette, so we need to take the lock (in case a flash operation times out). */ - mutex_lock (&vga_display_lock); + pthread_mutex_lock (&vga_display_lock); res_bgcol = dynacolor_lookup (*dc, bgcol); res_fgcol = dynacolor_lookup (*dc, fgcol); - mutex_unlock (&vga_display_lock); + pthread_mutex_unlock (&vga_display_lock); if (res_bgcol == -1 || res_fgcol == -1) dynacolor_replace_colors (dc, fgcol, bgcol, &res_fgcol, &res_bgcol); vga_attr = res_bgcol << 4 | res_fgcol; -- cgit v1.2.3