diff options
Diffstat (limited to 'libports')
42 files changed, 168 insertions, 171 deletions
diff --git a/libports/Makefile b/libports/Makefile index 8d7d9bbb..767ee73a 100644 --- a/libports/Makefile +++ b/libports/Makefile @@ -41,6 +41,7 @@ SRCS = create-bucket.c create-class.c \ installhdrs = ports.h HURDLIBS= ihash +LDLIBS += -lpthread OBJS = $(SRCS:.c=.o) notifyServer.o interruptServer.o MIGCOMSFLAGS = -prefix ports_ diff --git a/libports/begin-rpc.c b/libports/begin-rpc.c index ebe3473c..1e0e8ed6 100644 --- a/libports/begin-rpc.c +++ b/libports/begin-rpc.c @@ -19,7 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> #define INHIBITED (PORTS_INHIBITED | PORTS_INHIBIT_WAIT) @@ -30,14 +29,14 @@ ports_begin_rpc (void *portstruct, mach_msg_id_t msg_id, struct rpc_info *info) struct port_info *pi = portstruct; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); do { /* If our receive right is gone, then abandon the RPC. */ if (pi->port_right == MACH_PORT_NULL) { - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return EOPNOTSUPP; } @@ -76,13 +75,13 @@ ports_begin_rpc (void *portstruct, mach_msg_id_t msg_id, struct rpc_info *info) if (block_flags) { *block_flags |= PORTS_BLOCKED; - if (hurd_condition_wait (&_ports_block, &_ports_lock)) + if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock)) /* We've been cancelled, just return EINTR. If we were the only one blocking, PORTS_BLOCKED will still be turned on, but that's ok, it will just cause a (harmless) extra - condition_broadcast(). */ + pthread_cond_broadcast(). */ { - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return EINTR; } } @@ -103,7 +102,7 @@ ports_begin_rpc (void *portstruct, mach_msg_id_t msg_id, struct rpc_info *info) pi->bucket->rpcs++; _ports_total_rpcs++; - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return 0; } diff --git a/libports/bucket-iterate.c b/libports/bucket-iterate.c index e439cb19..dc1c7b11 100644 --- a/libports/bucket-iterate.c +++ b/libports/bucket-iterate.c @@ -19,7 +19,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ #include "ports.h" -#include <cthreads.h> #include <hurd/ihash.h> @@ -40,7 +39,7 @@ _ports_bucket_class_iterate (struct port_bucket *bucket, struct item *i, *nxt; error_t err; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); HURD_IHASH_ITERATE (&bucket->htable, arg) { struct port_info *const pi = arg; @@ -55,7 +54,7 @@ _ports_bucket_class_iterate (struct port_bucket *bucket, pi->refcnt++; } } - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); err = 0; for (i = list; i; i = nxt) diff --git a/libports/claim-right.c b/libports/claim-right.c index aef53bb7..69d378f9 100644 --- a/libports/claim-right.c +++ b/libports/claim-right.c @@ -34,7 +34,7 @@ ports_claim_right (void *portstruct) if (ret == MACH_PORT_NULL) return ret; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); hurd_ihash_locp_remove (&pi->bucket->htable, pi->hentry); err = mach_port_move_member (mach_task_self (), ret, MACH_PORT_NULL); assert_perror (err); @@ -42,11 +42,11 @@ ports_claim_right (void *portstruct) if (pi->flags & PORT_HAS_SENDRIGHTS) { pi->flags &= ~PORT_HAS_SENDRIGHTS; - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); ports_port_deref (pi); } else - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return ret; } diff --git a/libports/class-iterate.c b/libports/class-iterate.c index e2a15173..1f8878a5 100644 --- a/libports/class-iterate.c +++ b/libports/class-iterate.c @@ -18,19 +18,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ #include "ports.h" -#include <cthreads.h> error_t ports_class_iterate (struct port_class *class, error_t (*fun)(void *)) { - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); if (class->ports != 0) { struct port_bucket *bucket = class->ports->bucket; - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return _ports_bucket_class_iterate (bucket, class, fun); } - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return 0; } diff --git a/libports/complete-deallocate.c b/libports/complete-deallocate.c index 52e8f17b..e569b461 100644 --- a/libports/complete-deallocate.c +++ b/libports/complete-deallocate.c @@ -21,7 +21,6 @@ #include "ports.h" #include <assert.h> #include <hurd/ihash.h> -#include <cthreads.h> void _ports_complete_deallocate (struct port_info *pi) @@ -43,7 +42,7 @@ _ports_complete_deallocate (struct port_info *pi) pi->bucket->count--; pi->class->count--; - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); if (pi->class->clean_routine) (*pi->class->clean_routine)(pi); diff --git a/libports/count-bucket.c b/libports/count-bucket.c index 9aff58e9..63feb6be 100644 --- a/libports/count-bucket.c +++ b/libports/count-bucket.c @@ -19,17 +19,16 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> int ports_count_bucket (struct port_bucket *bucket) { int ret; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); ret = bucket->count; bucket->flags |= PORT_BUCKET_NO_ALLOC; - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return ret; } diff --git a/libports/count-class.c b/libports/count-class.c index 6aa88aa9..986a68bb 100644 --- a/libports/count-class.c +++ b/libports/count-class.c @@ -19,17 +19,16 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> int ports_count_class (struct port_class *class) { int ret; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); ret = class->count; class->flags |= PORT_CLASS_NO_ALLOC; - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return ret; } diff --git a/libports/create-bucket.c b/libports/create-bucket.c index 6be4bcad..52d50c35 100644 --- a/libports/create-bucket.c +++ b/libports/create-bucket.c @@ -23,7 +23,6 @@ #include <errno.h> #include <stdlib.h> #include <hurd/ihash.h> -#include <cthreads.h> struct port_bucket * ports_create_bucket () @@ -50,10 +49,10 @@ ports_create_bucket () hurd_ihash_init (&ret->htable, offsetof (struct port_info, hentry)); ret->rpcs = ret->flags = ret->count = 0; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); ret->next = _ports_all_buckets; _ports_all_buckets = ret; - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return ret; } diff --git a/libports/create-internal.c b/libports/create-internal.c index 7a9b1cb0..c60f6fd9 100644 --- a/libports/create-internal.c +++ b/libports/create-internal.c @@ -19,7 +19,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ #include <assert.h> -#include <cthreads.h> #include <hurd/ihash.h> #include "ports.h" @@ -64,20 +63,20 @@ _ports_create_port_internal (struct port_class *class, pi->current_rpcs = 0; pi->bucket = bucket; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); loop: if (class->flags & PORT_CLASS_NO_ALLOC) { class->flags |= PORT_CLASS_ALLOC_WAIT; - if (hurd_condition_wait (&_ports_block, &_ports_lock)) + if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock)) goto cancelled; goto loop; } if (bucket->flags & PORT_BUCKET_NO_ALLOC) { bucket->flags |= PORT_BUCKET_ALLOC_WAIT; - if (hurd_condition_wait (&_ports_block, &_ports_lock)) + if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock)) goto cancelled; goto loop; } @@ -93,7 +92,7 @@ _ports_create_port_internal (struct port_class *class, class->ports = pi; bucket->count++; class->count++; - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); if (install) { @@ -109,7 +108,7 @@ _ports_create_port_internal (struct port_class *class, cancelled: err = EINTR; lose: - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); lose_unlocked: err = mach_port_mod_refs (mach_task_self (), port, MACH_PORT_RIGHT_RECEIVE, -1); diff --git a/libports/destroy-right.c b/libports/destroy-right.c index 327029a8..65e19c78 100644 --- a/libports/destroy-right.c +++ b/libports/destroy-right.c @@ -19,7 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> #include <hurd/ihash.h> #include <assert.h> @@ -31,12 +30,12 @@ ports_destroy_right (void *portstruct) if (pi->port_right != MACH_PORT_NULL) { - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); hurd_ihash_locp_remove (&pi->bucket->htable, pi->hentry); err = mach_port_mod_refs (mach_task_self (), pi->port_right, MACH_PORT_RIGHT_RECEIVE, -1); assert_perror (err); - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); pi->port_right = MACH_PORT_NULL; diff --git a/libports/enable-bucket.c b/libports/enable-bucket.c index 278c5bb5..f9c7b859 100644 --- a/libports/enable-bucket.c +++ b/libports/enable-bucket.c @@ -19,17 +19,16 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> void ports_enable_bucket (struct port_bucket *bucket) { - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); bucket->flags &= ~PORT_BUCKET_NO_ALLOC; if (bucket->flags & PORT_BUCKET_ALLOC_WAIT) { bucket->flags &= ~PORT_BUCKET_ALLOC_WAIT; - condition_broadcast (&_ports_block); + pthread_cond_broadcast (&_ports_block); } - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); } diff --git a/libports/enable-class.c b/libports/enable-class.c index 7aebf685..b3894ebb 100644 --- a/libports/enable-class.c +++ b/libports/enable-class.c @@ -19,17 +19,16 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> void ports_enable_class (struct port_class *class) { - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); class->flags &= ~PORT_CLASS_NO_ALLOC; if (class->flags & PORT_CLASS_ALLOC_WAIT) { class->flags &= ~PORT_CLASS_ALLOC_WAIT; - condition_broadcast (&_ports_block); + pthread_cond_broadcast (&_ports_block); } - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); } diff --git a/libports/end-rpc.c b/libports/end-rpc.c index 47fd1ae7..b5dcb3a2 100644 --- a/libports/end-rpc.c +++ b/libports/end-rpc.c @@ -19,14 +19,13 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> void ports_end_rpc (void *port, struct rpc_info *info) { struct port_info *pi = port; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); if (info->notifies) _ports_remove_notified_rpc (info); @@ -42,7 +41,7 @@ ports_end_rpc (void *port, struct rpc_info *info) || (pi->bucket->flags & PORT_BUCKET_INHIBIT_WAIT) || (pi->class->flags & PORT_CLASS_INHIBIT_WAIT) || (_ports_flags & _PORTS_INHIBIT_WAIT)) - condition_broadcast (&_ports_block); + pthread_cond_broadcast (&_ports_block); /* This removes the current thread's rpc (which should be INFO) from the ports interrupted list. */ @@ -52,5 +51,5 @@ ports_end_rpc (void *port, struct rpc_info *info) RPC is now finished anwhow. */ hurd_check_cancel (); - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); } diff --git a/libports/get-right.c b/libports/get-right.c index 95662f58..89050c6b 100644 --- a/libports/get-right.c +++ b/libports/get-right.c @@ -19,7 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> #include <mach/notify.h> #include <assert.h> @@ -30,11 +29,11 @@ ports_get_right (void *port) mach_port_t foo; error_t err; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); if (pi->port_right == MACH_PORT_NULL) { - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return MACH_PORT_NULL; } @@ -54,6 +53,6 @@ ports_get_right (void *port) if (foo != MACH_PORT_NULL) mach_port_deallocate (mach_task_self (), foo); } - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return pi->port_right; } diff --git a/libports/import-port.c b/libports/import-port.c index d7a62960..226f47e3 100644 --- a/libports/import-port.c +++ b/libports/import-port.c @@ -22,7 +22,6 @@ #include "ports.h" #include <assert.h> -#include <cthreads.h> #include <hurd/ihash.h> #include <mach/notify.h> @@ -58,20 +57,20 @@ ports_import_port (struct port_class *class, struct port_bucket *bucket, pi->current_rpcs = 0; pi->bucket = bucket; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); loop: if (class->flags & PORT_CLASS_NO_ALLOC) { class->flags |= PORT_CLASS_ALLOC_WAIT; - if (hurd_condition_wait (&_ports_block, &_ports_lock)) + if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock)) goto cancelled; goto loop; } if (bucket->flags & PORT_BUCKET_NO_ALLOC) { bucket->flags |= PORT_BUCKET_ALLOC_WAIT; - if (hurd_condition_wait (&_ports_block, &_ports_lock)) + if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock)) goto cancelled; goto loop; } @@ -87,7 +86,7 @@ ports_import_port (struct port_class *class, struct port_bucket *bucket, class->ports = pi; bucket->count++; class->count++; - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); mach_port_move_member (mach_task_self (), port, bucket->portset); @@ -109,7 +108,7 @@ ports_import_port (struct port_class *class, struct port_bucket *bucket, cancelled: err = EINTR; lose: - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); free (pi); return err; diff --git a/libports/inhibit-all-rpcs.c b/libports/inhibit-all-rpcs.c index 9a72f83e..d4a54ba5 100644 --- a/libports/inhibit-all-rpcs.c +++ b/libports/inhibit-all-rpcs.c @@ -20,7 +20,6 @@ #include "ports.h" #include <hurd.h> -#include <cthreads.h> #include <hurd/ihash.h> error_t @@ -28,7 +27,7 @@ ports_inhibit_all_rpcs () { error_t err = 0; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); if (_ports_flags & (_PORTS_INHIBITED | _PORTS_INHIBIT_WAIT)) err = EBUSY; @@ -59,7 +58,7 @@ ports_inhibit_all_rpcs () while (_ports_total_rpcs > this_one) { _ports_flags |= _PORTS_INHIBIT_WAIT; - if (hurd_condition_wait (&_ports_block, &_ports_lock)) + if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock)) /* We got cancelled. */ { err = EINTR; @@ -72,7 +71,7 @@ ports_inhibit_all_rpcs () _ports_flags |= _PORTS_INHIBITED; } - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return err; } diff --git a/libports/inhibit-bucket-rpcs.c b/libports/inhibit-bucket-rpcs.c index 7fc55d31..965aa036 100644 --- a/libports/inhibit-bucket-rpcs.c +++ b/libports/inhibit-bucket-rpcs.c @@ -20,7 +20,6 @@ #include "ports.h" #include <hurd.h> -#include <cthreads.h> #include <hurd/ihash.h> error_t @@ -28,7 +27,7 @@ ports_inhibit_bucket_rpcs (struct port_bucket *bucket) { error_t err = 0; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); if (bucket->flags & (PORT_BUCKET_INHIBITED | PORT_BUCKET_INHIBIT_WAIT)) err = EBUSY; @@ -55,7 +54,7 @@ ports_inhibit_bucket_rpcs (struct port_bucket *bucket) while (bucket->rpcs > this_one) { bucket->flags |= PORT_BUCKET_INHIBIT_WAIT; - if (hurd_condition_wait (&_ports_block, &_ports_lock)) + if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock)) /* We got cancelled. */ { err = EINTR; @@ -68,7 +67,7 @@ ports_inhibit_bucket_rpcs (struct port_bucket *bucket) bucket->flags |= PORT_BUCKET_INHIBITED; } - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return err; } diff --git a/libports/inhibit-class-rpcs.c b/libports/inhibit-class-rpcs.c index 951de4bf..7ee86538 100644 --- a/libports/inhibit-class-rpcs.c +++ b/libports/inhibit-class-rpcs.c @@ -20,14 +20,13 @@ #include "ports.h" #include <hurd.h> -#include <cthreads.h> error_t ports_inhibit_class_rpcs (struct port_class *class) { error_t err = 0; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); if (class->flags & (PORT_CLASS_INHIBITED | PORT_CLASS_INHIBIT_WAIT)) err = EBUSY; @@ -50,7 +49,7 @@ ports_inhibit_class_rpcs (struct port_class *class) while (class->rpcs > this_one) { class->flags |= PORT_CLASS_INHIBIT_WAIT; - if (hurd_condition_wait (&_ports_block, &_ports_lock)) + if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock)) /* We got cancelled. */ { err = EINTR; @@ -63,7 +62,7 @@ ports_inhibit_class_rpcs (struct port_class *class) class->flags |= PORT_CLASS_INHIBITED; } - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return err; } diff --git a/libports/inhibit-port-rpcs.c b/libports/inhibit-port-rpcs.c index 02a3b462..b741eeb7 100644 --- a/libports/inhibit-port-rpcs.c +++ b/libports/inhibit-port-rpcs.c @@ -20,7 +20,6 @@ #include "ports.h" #include <hurd.h> -#include <cthreads.h> error_t ports_inhibit_port_rpcs (void *portstruct) @@ -28,7 +27,7 @@ ports_inhibit_port_rpcs (void *portstruct) error_t err = 0; struct port_info *pi = portstruct; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); if (pi->flags & (PORT_INHIBITED | PORT_INHIBIT_WAIT)) err = EBUSY; @@ -51,7 +50,7 @@ ports_inhibit_port_rpcs (void *portstruct) && !(pi->current_rpcs == this_rpc && ! this_rpc->next)) { pi->flags |= PORT_INHIBIT_WAIT; - if (hurd_condition_wait (&_ports_block, &_ports_lock)) + if (pthread_hurd_cond_wait_np (&_ports_block, &_ports_lock)) /* We got cancelled. */ { err = EINTR; @@ -64,7 +63,7 @@ ports_inhibit_port_rpcs (void *portstruct) pi->flags |= PORT_INHIBITED; } - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return err; } diff --git a/libports/init.c b/libports/init.c index 7d4d16fd..3ef53888 100644 --- a/libports/init.c +++ b/libports/init.c @@ -19,10 +19,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> -struct mutex _ports_lock = MUTEX_INITIALIZER; -struct condition _ports_block = CONDITION_INITIALIZER; +pthread_mutex_t _ports_lock = PTHREAD_MUTEX_INITIALIZER; +pthread_cond_t _ports_block = PTHREAD_COND_INITIALIZER; struct port_bucket *_ports_all_buckets; int _ports_total_rpcs; int _ports_flags; diff --git a/libports/interrupt-notified-rpcs.c b/libports/interrupt-notified-rpcs.c index bdfef977..6d6493d3 100644 --- a/libports/interrupt-notified-rpcs.c +++ b/libports/interrupt-notified-rpcs.c @@ -36,7 +36,7 @@ ports_interrupt_notified_rpcs (void *object, { struct ports_notify *np; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); for (np = _ports_notifications; np; np = np->next) if (np->port == port && np->what == what) { @@ -49,7 +49,7 @@ ports_interrupt_notified_rpcs (void *object, } break; } - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); } } diff --git a/libports/interrupt-on-notify.c b/libports/interrupt-on-notify.c index 42ae4884..b358e840 100644 --- a/libports/interrupt-on-notify.c +++ b/libports/interrupt-on-notify.c @@ -34,13 +34,13 @@ ports_interrupt_rpc_on_notification (void *object, struct rpc_notify *new_req, *req; struct port_info *pi = object; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); if (! MACH_PORT_VALID (port)) /* PORT is already dead or bogus, so interrupt the rpc immediately. */ { hurd_thread_cancel (rpc->thread); - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return 0; } @@ -53,11 +53,11 @@ ports_interrupt_rpc_on_notification (void *object, time we'll add a new structure, so we malloc while we don't have the lock, and free it if we're wrong. */ { - mutex_unlock (&_ports_lock); /* Don't hold the lock during malloc. */ + pthread_mutex_unlock (&_ports_lock); /* Don't hold the lock during malloc. */ new_req = malloc (sizeof (struct rpc_notify)); if (! new_req) return ENOMEM; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); } /* Find any existing entry for PORT/WHAT. */ @@ -80,7 +80,7 @@ ports_interrupt_rpc_on_notification (void *object, { new_req->next = _ports_free_rpc_notifies; _ports_free_rpc_notifies = new_req; - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return ENOMEM; } } @@ -89,7 +89,7 @@ ports_interrupt_rpc_on_notification (void *object, pn->port = port; pn->what = what; pn->pending = 0; - mutex_init (&pn->lock); + pthread_mutex_init (&pn->lock, NULL); pn->next = _ports_notifications; pn->prevp = &_ports_notifications; @@ -136,9 +136,9 @@ ports_interrupt_rpc_on_notification (void *object, immediate notification). */ req_notify = !pn->pending; if (req_notify) - mutex_lock (&pn->lock); + pthread_mutex_lock (&pn->lock); - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); if (req_notify) { @@ -152,7 +152,7 @@ ports_interrupt_rpc_on_notification (void *object, mach_port_deallocate (mach_task_self (), old); pn->pending = 1; - mutex_unlock (&pn->lock); + pthread_mutex_unlock (&pn->lock); return err; } @@ -170,11 +170,11 @@ ports_interrupt_self_on_notification (void *object, struct port_info *pi = object; thread_t thread = hurd_thread_self (); - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); for (rpc = pi->current_rpcs; rpc; rpc = rpc->next) if (rpc->thread == thread) break; - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); assert (rpc); diff --git a/libports/interrupt-operation.c b/libports/interrupt-operation.c index 1545f788..19c0edf6 100644 --- a/libports/interrupt-operation.c +++ b/libports/interrupt-operation.c @@ -30,10 +30,10 @@ ports_S_interrupt_operation (mach_port_t port, struct port_info *pi = ports_lookup_port (0, port, 0); if (!pi) return EOPNOTSUPP; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); if (pi->cancel_threshold < seqno) pi->cancel_threshold = seqno; - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); ports_interrupt_rpcs (pi); ports_port_deref (pi); return 0; diff --git a/libports/interrupt-rpcs.c b/libports/interrupt-rpcs.c index 7c28ff2c..42f51a5e 100644 --- a/libports/interrupt-rpcs.c +++ b/libports/interrupt-rpcs.c @@ -20,7 +20,6 @@ #include "ports.h" #include <hurd.h> -#include <cthreads.h> void ports_interrupt_rpcs (void *portstruct) @@ -28,7 +27,7 @@ ports_interrupt_rpcs (void *portstruct) struct port_info *pi = portstruct; struct rpc_info *rpc; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); for (rpc = pi->current_rpcs; rpc; rpc = rpc->next) { @@ -36,5 +35,5 @@ ports_interrupt_rpcs (void *portstruct) _ports_record_interruption (rpc); } - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); } diff --git a/libports/interrupted.c b/libports/interrupted.c index e4cb2fc2..88fb9ef0 100644 --- a/libports/interrupted.c +++ b/libports/interrupted.c @@ -20,7 +20,7 @@ #include "ports.h" -static spin_lock_t interrupted_lock = SPIN_LOCK_INITIALIZER; +static pthread_spinlock_t interrupted_lock = PTHREAD_SPINLOCK_INITIALIZER; /* True if some active rpc has been interrupted. */ static struct rpc_info *interrupted = 0; @@ -33,19 +33,19 @@ ports_self_interrupted () struct rpc_info **rpc_p, *rpc; thread_t self = hurd_thread_self (); - spin_lock (&interrupted_lock); + pthread_spin_lock (&interrupted_lock); for (rpc_p = &interrupted; *rpc_p; rpc_p = &rpc->interrupted_next) { rpc = *rpc_p; if (rpc->thread == self) { *rpc_p = rpc->interrupted_next; - spin_unlock (&interrupted_lock); + pthread_spin_unlock (&interrupted_lock); rpc->interrupted_next = 0; return 1; } } - spin_unlock (&interrupted_lock); + pthread_spin_unlock (&interrupted_lock); return 0; } @@ -56,14 +56,14 @@ _ports_record_interruption (struct rpc_info *rpc) { struct rpc_info *i; - spin_lock (&interrupted_lock); + pthread_spin_lock (&interrupted_lock); /* See if RPC is already in the interrupted list. */ for (i = interrupted; i; i = i->interrupted_next) if (i == rpc) /* Yup, it is, so just leave it there. */ { - spin_unlock (&interrupted_lock); + pthread_spin_unlock (&interrupted_lock); return; } @@ -71,5 +71,5 @@ _ports_record_interruption (struct rpc_info *rpc) rpc->interrupted_next = interrupted; interrupted = rpc; - spin_unlock (&interrupted_lock); + pthread_spin_unlock (&interrupted_lock); } diff --git a/libports/lookup-port.c b/libports/lookup-port.c index 8eb98a12..373d929c 100644 --- a/libports/lookup-port.c +++ b/libports/lookup-port.c @@ -19,7 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> #include <hurd/ihash.h> void * @@ -29,7 +28,7 @@ ports_lookup_port (struct port_bucket *bucket, { struct port_info *pi = 0; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); if (bucket) pi = hurd_ihash_find (&bucket->htable, port); @@ -47,7 +46,7 @@ ports_lookup_port (struct port_bucket *bucket, if (pi) pi->refcnt++; - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return pi; } diff --git a/libports/manage-multithread.c b/libports/manage-multithread.c index 035cd38d..c46a09fc 100644 --- a/libports/manage-multithread.c +++ b/libports/manage-multithread.c @@ -19,13 +19,18 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <spin-lock.h> #include <assert.h> -#include <cthreads.h> +#include <stdio.h> #include <mach/message.h> #include <mach/thread_info.h> #include <mach/thread_switch.h> +#define STACK_SIZE (64 * 1024) + +/* FIXME Until threadvars are completely replaced with correct TLS, use this + hack to set the stack size. */ +size_t __pthread_stack_default_size = STACK_SIZE; + #define THREAD_PRI 2 /* XXX To reduce starvation, the priority of new threads is initially @@ -88,9 +93,14 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket, { volatile unsigned int nreqthreads; volatile unsigned int totalthreads; - spin_lock_t lock = SPIN_LOCK_INITIALIZER; + pthread_spinlock_t lock = PTHREAD_SPINLOCK_INITIALIZER; + pthread_attr_t attr; + + auto void * thread_function (void *); - auto int thread_function (int); + /* FIXME This is currently a no-op. */ + pthread_attr_init (&attr); + pthread_attr_setstacksize (&attr, STACK_SIZE); int internal_demuxer (mach_msg_header_t *inp, @@ -110,18 +120,32 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket, /* msgt_unused = */ 0 }; - spin_lock (&lock); + pthread_spin_lock (&lock); assert (nreqthreads); nreqthreads--; if (nreqthreads != 0) - spin_unlock (&lock); + pthread_spin_unlock (&lock); else /* No thread would be listening for requests, spawn one. */ { + pthread_t pthread_id; + error_t err; + totalthreads++; nreqthreads++; - spin_unlock (&lock); - cthread_detach (cthread_fork ((cthread_fn_t) thread_function, 0)); + pthread_spin_unlock (&lock); + + err = pthread_create (&pthread_id, &attr, thread_function, NULL); + if (!err) + pthread_detach (pthread_id); + else + { + /* XXX The number of threads should be adjusted but the code + and design of the Hurd servers just don't handle thread + creation failure. */ + errno = err; + perror ("pthread_create"); + } } /* Fill in default response. */ @@ -146,10 +170,10 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket, } else { - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); if (inp->msgh_seqno < pi->cancel_threshold) hurd_thread_cancel (link.thread); - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); status = demuxer (inp, outheadp); ports_end_rpc (pi, &link); } @@ -161,16 +185,17 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket, status = 1; } - spin_lock (&lock); + pthread_spin_lock (&lock); nreqthreads++; - spin_unlock (&lock); + pthread_spin_unlock (&lock); return status; } - int - thread_function (int master) + void * + thread_function (void *arg) { + int master = (int) arg; int timeout; error_t err; @@ -195,32 +220,32 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket, if (master) { - spin_lock (&lock); + pthread_spin_lock (&lock); if (totalthreads != 1) { - spin_unlock (&lock); + pthread_spin_unlock (&lock); goto startover; } } else { - spin_lock (&lock); + pthread_spin_lock (&lock); if (nreqthreads == 1) { /* No other thread is listening for requests, continue. */ - spin_unlock (&lock); + pthread_spin_unlock (&lock); goto startover; } nreqthreads--; totalthreads--; - spin_unlock (&lock); + pthread_spin_unlock (&lock); } - return 0; + return NULL; } nreqthreads = 1; totalthreads = 1; - thread_function (1); + thread_function ((void *) 1); } diff --git a/libports/no-senders.c b/libports/no-senders.c index 0e8a5f17..1a6084b1 100644 --- a/libports/no-senders.c +++ b/libports/no-senders.c @@ -19,7 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> #include <mach/notify.h> void @@ -30,10 +29,10 @@ ports_no_senders (void *portstruct, int dealloc; mach_port_t old; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); if ((pi->flags & PORT_HAS_SENDRIGHTS) == 0) { - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); return; } if (mscount >= pi->mscount) @@ -54,7 +53,7 @@ ports_no_senders (void *portstruct, mach_port_deallocate (mach_task_self (), old); dealloc = 0; } - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); if (dealloc) { diff --git a/libports/port-deref-weak.c b/libports/port-deref-weak.c index 2bef3338..91071ffa 100644 --- a/libports/port-deref-weak.c +++ b/libports/port-deref-weak.c @@ -19,7 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> #include <assert.h> void @@ -27,12 +26,12 @@ ports_port_deref_weak (void *portstruct) { struct port_info *pi = portstruct; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); assert (pi->weakrefcnt); pi->weakrefcnt--; if (pi->refcnt == 0 && pi->weakrefcnt == 0) _ports_complete_deallocate (pi); else - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); } diff --git a/libports/port-deref.c b/libports/port-deref.c index 1ded45d9..ae10a02c 100644 --- a/libports/port-deref.c +++ b/libports/port-deref.c @@ -19,7 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> #include <assert.h> void @@ -30,12 +29,12 @@ ports_port_deref (void *portstruct) retry: - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); if (pi->refcnt == 1 && pi->weakrefcnt && pi->class->dropweak_routine && !trieddroppingweakrefs) { - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); (*pi->class->dropweak_routine) (pi); trieddroppingweakrefs = 1; goto retry; @@ -47,7 +46,7 @@ ports_port_deref (void *portstruct) if (pi->refcnt == 0 && pi->weakrefcnt == 0) _ports_complete_deallocate (pi); else - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); } diff --git a/libports/port-ref-weak.c b/libports/port-ref-weak.c index 6ebd5608..c7d3c690 100644 --- a/libports/port-ref-weak.c +++ b/libports/port-ref-weak.c @@ -19,7 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> #include <assert.h> void @@ -27,8 +26,8 @@ ports_port_ref_weak (void *portstruct) { struct port_info *pi = portstruct; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); assert (pi->refcnt || pi->weakrefcnt); pi->weakrefcnt++; - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); } diff --git a/libports/port-ref.c b/libports/port-ref.c index 7fd15272..864c540e 100644 --- a/libports/port-ref.c +++ b/libports/port-ref.c @@ -19,7 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> #include <assert.h> void @@ -27,10 +26,10 @@ ports_port_ref (void *portstruct) { struct port_info *pi = portstruct; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); assert (pi->refcnt || pi->weakrefcnt); pi->refcnt++; - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); } diff --git a/libports/ports.h b/libports/ports.h index 9a5ccbc2..07918412 100644 --- a/libports/ports.h +++ b/libports/ports.h @@ -26,6 +26,7 @@ #include <hurd.h> #include <hurd/ihash.h> #include <mach/notify.h> +#include <pthread.h> /* These are global values for common flags used in the various structures. Not all of these are meaningful in all flag fields. */ @@ -115,7 +116,7 @@ struct ports_notify mach_port_t port; /* */ mach_msg_id_t what; /* MACH_NOTIFY_* */ unsigned pending : 1; /* There's a notification outstanding. */ - struct mutex lock; + pthread_mutex_t lock; struct rpc_notify *reqs; /* Which rpcs are notified by this port. */ struct ports_notify *next, **prevp; /* Linked list of all notified ports. */ @@ -396,8 +397,8 @@ extern kern_return_t ports_S_interrupt_operation (mach_port_t, mach_port_seqno_t); /* Private data */ -extern struct mutex _ports_lock; -extern struct condition _ports_block; +extern pthread_mutex_t _ports_lock; +extern pthread_cond_t _ports_block; extern struct port_bucket *_ports_all_buckets; extern int _ports_total_rpcs; extern int _ports_flags; diff --git a/libports/reallocate-from-external.c b/libports/reallocate-from-external.c index ebddd9f7..cd12143c 100644 --- a/libports/reallocate-from-external.c +++ b/libports/reallocate-from-external.c @@ -20,7 +20,6 @@ #include "ports.h" #include <assert.h> -#include <cthreads.h> #include <hurd/ihash.h> #include <mach/notify.h> @@ -36,7 +35,7 @@ ports_reallocate_from_external (void *portstruct, mach_port_t receive) err = mach_port_get_receive_status (mach_task_self (), receive, &stat); assert_perror (err); - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); assert (pi->port_right); @@ -62,7 +61,7 @@ ports_reallocate_from_external (void *portstruct, mach_port_t receive) pi->mscount = stat.mps_mscount; hurd_ihash_add (&pi->bucket->htable, receive, pi); - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); mach_port_move_member (mach_task_self (), receive, pi->bucket->portset); diff --git a/libports/reallocate-port.c b/libports/reallocate-port.c index 23898e88..891786cb 100644 --- a/libports/reallocate-port.c +++ b/libports/reallocate-port.c @@ -21,7 +21,6 @@ #include "ports.h" #include <hurd/ihash.h> #include <assert.h> -#include <cthreads.h> void ports_reallocate_port (void *portstruct) @@ -30,7 +29,7 @@ ports_reallocate_port (void *portstruct) error_t err; int dropref = 0; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); assert (pi->port_right); err = mach_port_mod_refs (mach_task_self (), pi->port_right, @@ -50,7 +49,7 @@ ports_reallocate_port (void *portstruct) pi->cancel_threshold = 0; pi->mscount = 0; hurd_ihash_add (&pi->bucket->htable, pi->port_right, pi); - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); err = mach_port_move_member (mach_task_self (), pi->port_right, pi->bucket->portset); diff --git a/libports/resume-all-rpcs.c b/libports/resume-all-rpcs.c index 452da3b2..e9669e0f 100644 --- a/libports/resume-all-rpcs.c +++ b/libports/resume-all-rpcs.c @@ -19,21 +19,20 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> #include <assert.h> void ports_resume_all_rpcs () { - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); assert (_ports_flags & _PORTS_INHIBITED); _ports_flags &= ~_PORTS_INHIBITED; if (_ports_flags & _PORTS_BLOCKED) { _ports_flags &= ~_PORTS_BLOCKED; - condition_broadcast (&_ports_block); + pthread_cond_broadcast (&_ports_block); } - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); } diff --git a/libports/resume-bucket-rpcs.c b/libports/resume-bucket-rpcs.c index 59cc75a4..cf4db91c 100644 --- a/libports/resume-bucket-rpcs.c +++ b/libports/resume-bucket-rpcs.c @@ -19,19 +19,18 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> #include <assert.h> void ports_resume_bucket_rpcs (struct port_bucket *bucket) { - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); assert (bucket->flags & PORT_BUCKET_INHIBITED); bucket->flags &= ~PORT_BUCKET_INHIBITED; if (bucket->flags & PORT_BUCKET_BLOCKED) { bucket->flags &= ~PORT_BUCKET_BLOCKED; - condition_broadcast (&_ports_block); + pthread_cond_broadcast (&_ports_block); } - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); } diff --git a/libports/resume-class-rpcs.c b/libports/resume-class-rpcs.c index a4191747..a8c701e2 100644 --- a/libports/resume-class-rpcs.c +++ b/libports/resume-class-rpcs.c @@ -19,20 +19,19 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> #include <assert.h> void ports_resume_class_rpcs (struct port_class *class) { - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); assert (class->flags & PORT_CLASS_INHIBITED); class->flags &= ~PORT_CLASS_INHIBITED; if (class->flags & PORT_CLASS_BLOCKED) { class->flags &= ~PORT_CLASS_BLOCKED; - condition_broadcast (&_ports_block); + pthread_cond_broadcast (&_ports_block); } - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); } diff --git a/libports/resume-port-rpcs.c b/libports/resume-port-rpcs.c index e9e30fbd..5dc5c70e 100644 --- a/libports/resume-port-rpcs.c +++ b/libports/resume-port-rpcs.c @@ -19,7 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "ports.h" -#include <cthreads.h> #include <assert.h> void @@ -27,16 +26,16 @@ ports_resume_port_rpcs (void *portstruct) { struct port_info *pi = portstruct; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); assert (pi->flags & PORT_INHIBITED); pi->flags &= ~PORT_INHIBITED; if (pi->flags & PORT_BLOCKED) { pi->flags &= ~PORT_BLOCKED; - condition_broadcast (&_ports_block); + pthread_cond_broadcast (&_ports_block); } - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); } diff --git a/libports/stubs.c b/libports/stubs.c index 23c6a0ea..de4ae4dd 100644 --- a/libports/stubs.c +++ b/libports/stubs.c @@ -21,6 +21,7 @@ /* This file contains stubs for some cthreads functions. It should only get used if the user isn't otherwise using cthreads. */ +#if 0 #include <cthreads.h> void condition_wait (condition_t c, mutex_t m) __attribute__ ((weak)); @@ -36,3 +37,4 @@ void cond_broadcast (condition_t c) { } +#endif diff --git a/libports/transfer-right.c b/libports/transfer-right.c index e7b0ff55..2a790694 100644 --- a/libports/transfer-right.c +++ b/libports/transfer-right.c @@ -35,7 +35,7 @@ ports_transfer_right (void *tostruct, int hassendrights = 0; error_t err; - mutex_lock (&_ports_lock); + pthread_mutex_lock (&_ports_lock); /* Fetch the port in FROMPI and clear its use */ port = frompi->port_right; @@ -86,7 +86,7 @@ ports_transfer_right (void *tostruct, } } - mutex_unlock (&_ports_lock); + pthread_mutex_unlock (&_ports_lock); /* Take care of any lowered reference counts. */ if (dereffrompi) |