diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2014-05-03 01:02:35 +0200 |
---|---|---|
committer | Justus Winter <4winter@informatik.uni-hamburg.de> | 2014-10-05 23:31:08 +0200 |
commit | 78343e97c68fda079c66f2443bab6d1ee16f0b67 (patch) | |
tree | c2293ad70042bf6d839ab6ef5436e4c9fdf2cdcc /libports/complete-deallocate.c | |
parent | 9a043bf1792be16a045dd2e2e37c2c6354425b9b (diff) | |
download | hurd-78343e97c68fda079c66f2443bab6d1ee16f0b67.tar.gz hurd-78343e97c68fda079c66f2443bab6d1ee16f0b67.tar.bz2 hurd-78343e97c68fda079c66f2443bab6d1ee16f0b67.zip |
libports: lock-less reference counting for port_info objects
* libports/ports.h (struct port_info): Use the new type.
* libports/lookup-port.c: No need to lock _ports_lock anymore.
* libports/bucket-iterate.c: Likewise.
* libports/complete-deallocate.c: Check if someone reacquired a
reference through a hash table lookup.
* libports/create-internal.c: Use the new reference counting primitives.
* libports/get-right.c: Likewise.
* libports/import-port.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/reallocate-from-external.c: Likewise.
* libports/transfer-right.c: Likewise.
* utils/rpctrace.c: Likewise.
Diffstat (limited to 'libports/complete-deallocate.c')
-rw-r--r-- | libports/complete-deallocate.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/libports/complete-deallocate.c b/libports/complete-deallocate.c index 4768dab9..0d852f57 100644 --- a/libports/complete-deallocate.c +++ b/libports/complete-deallocate.c @@ -29,15 +29,29 @@ _ports_complete_deallocate (struct port_info *pi) if (pi->port_right) { + struct references result; + pthread_rwlock_wrlock (&_ports_htable_lock); + refcounts_references (&pi->refcounts, &result); + if (result.hard > 0 || result.weak > 0) + { + /* A reference was reacquired through a hash table lookup. + It's fine, we didn't touch anything yet. */ + pthread_mutex_unlock (&_ports_htable_lock); + return; + } + hurd_ihash_locp_remove (&_ports_htable, pi->ports_htable_entry); hurd_ihash_locp_remove (&pi->bucket->htable, pi->hentry); pthread_rwlock_unlock (&_ports_htable_lock); + mach_port_mod_refs (mach_task_self (), pi->port_right, MACH_PORT_RIGHT_RECEIVE, -1); pi->port_right = MACH_PORT_NULL; } + pthread_mutex_lock (&_ports_lock); + pi->bucket->count--; pi->class->count--; |