[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[hurd] 02/09: libports: avoid acquiring global lock in message dispatch
From: |
Samuel Thibault |
Subject: |
[hurd] 02/09: libports: avoid acquiring global lock in message dispatch |
Date: |
Sun, 19 Apr 2015 14:13:42 +0000 |
This is an automated email from the git hooks/post-receive script.
sthibault pushed a commit to branch upstream
in repository hurd.
commit fb8c531ddeef55c8581d3882bd1b1f501d980a30
Author: Justus Winter <address@hidden>
Date: Mon Dec 15 11:53:26 2014 +0100
libports: avoid acquiring global lock in message dispatch
* libports/interrupt-operation.c (ports_S_interrupt_operation): Update
`cancel_threshold' using atomic operations.
* libports/manage-multithread.c (internal_demuxer): Avoid taking the lock.
* libports/ports.h (struct port_info): Mention that one needs atomic
operations to access `cancel_threshold'.
---
libports/interrupt-operation.c | 14 ++++++++++----
libports/manage-multithread.c | 8 +++++---
libports/ports.h | 2 +-
3 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/libports/interrupt-operation.c b/libports/interrupt-operation.c
index 943bd4f..5d4b0b7 100644
--- a/libports/interrupt-operation.c
+++ b/libports/interrupt-operation.c
@@ -27,12 +27,18 @@ kern_return_t
ports_S_interrupt_operation (struct port_info *pi,
mach_port_seqno_t seqno)
{
+ mach_port_seqno_t old;
+
if (!pi)
return EOPNOTSUPP;
- pthread_mutex_lock (&_ports_lock);
- if (pi->cancel_threshold < seqno)
- pi->cancel_threshold = seqno;
- pthread_mutex_unlock (&_ports_lock);
+
+ retry:
+ old = __atomic_load_n (&pi->cancel_threshold, __ATOMIC_SEQ_CST);
+ if (old < seqno
+ && ! __atomic_compare_exchange_n (&pi->cancel_threshold, &old, seqno,
+ 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
+ goto retry;
+
ports_interrupt_rpcs (pi);
return 0;
}
diff --git a/libports/manage-multithread.c b/libports/manage-multithread.c
index ad22991..58814d2 100644
--- a/libports/manage-multithread.c
+++ b/libports/manage-multithread.c
@@ -178,10 +178,12 @@ ports_manage_port_operations_multithread (struct
port_bucket *bucket,
}
else
{
- pthread_mutex_lock (&_ports_lock);
- if (inp->msgh_seqno < pi->cancel_threshold)
+ mach_port_seqno_t cancel_threshold =
+ __atomic_load_n (&pi->cancel_threshold, __ATOMIC_SEQ_CST);
+
+ if (inp->msgh_seqno < cancel_threshold)
hurd_thread_cancel (link.thread);
- pthread_mutex_unlock (&_ports_lock);
+
status = demuxer (inp, outheadp);
ports_end_rpc (pi, &link);
}
diff --git a/libports/ports.h b/libports/ports.h
index a625b47..f02edb4 100644
--- a/libports/ports.h
+++ b/libports/ports.h
@@ -48,7 +48,7 @@ struct port_info
struct port_class *class;
refcounts_t refcounts;
mach_port_mscount_t mscount;
- mach_msg_seqno_t cancel_threshold;
+ mach_msg_seqno_t cancel_threshold; /* needs atomic operations */
int flags;
mach_port_t port_right;
struct rpc_info *current_rpcs;
--
Alioth's /usr/local/bin/git-commit-notice on
/srv/git.debian.org/git/pkg-hurd/hurd.git
- [hurd] branch upstream updated (9e8c1ba -> b69862c), Samuel Thibault, 2015/04/19
- [hurd] 06/09: procfs: fix runtime option parsing, Samuel Thibault, 2015/04/19
- [hurd] 01/09: TODO: drop obsolete item, Samuel Thibault, 2015/04/19
- [hurd] 02/09: libports: avoid acquiring global lock in message dispatch,
Samuel Thibault <=
- [hurd] 07/09: NEWS: mention that the init server has been split, Samuel Thibault, 2015/04/19
- [hurd] 04/09: procfs: fix argument parsing, Samuel Thibault, 2015/04/19
- [hurd] 09/09: Merge tag 'v0.6' into upstream, Samuel Thibault, 2015/04/19
- [hurd] 08/09: GNU Hurd 0.6., Samuel Thibault, 2015/04/19
- [hurd] 05/09: libports: use protected payloads to optimize the object lookup, Samuel Thibault, 2015/04/19
- [hurd] 03/09: Fix space style, Samuel Thibault, 2015/04/19