From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7384 Path: news.gmane.org!not-for-mail From: Alexander Monakov Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] Use CAS instead of atomic swap to implement spinlock Date: Wed, 15 Apr 2015 01:44:53 +0300 Message-ID: <1429051493-2821-1-git-send-email-amonakov@ispras.ru> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1429051517 22859 80.91.229.3 (14 Apr 2015 22:45:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 14 Apr 2015 22:45:17 +0000 (UTC) Cc: Alexander Monakov To: musl@lists.openwall.com Original-X-From: musl-return-7397-gllmg-musl=m.gmane.org@lists.openwall.com Wed Apr 15 00:45:17 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Yi9a0-0006aH-En for gllmg-musl@m.gmane.org; Wed, 15 Apr 2015 00:45:16 +0200 Original-Received: (qmail 10054 invoked by uid 550); 14 Apr 2015 22:45:14 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 9999 invoked from network); 14 Apr 2015 22:45:11 -0000 X-Mailer: git-send-email 2.1.3 Xref: news.gmane.org gmane.linux.lib.musl.general:7384 Archived-At: This should allow spinning without constantly dirtying cache lines holding the spinlock value. On architectures without native atomic swap, musl implement a_swap by looping around a_cas. --- If I'm not mistaken this was also suggested by nsz on IRC. src/thread/pthread_spin_lock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread/pthread_spin_lock.c b/src/thread/pthread_spin_lock.c index df575f0..dabcb31 100644 --- a/src/thread/pthread_spin_lock.c +++ b/src/thread/pthread_spin_lock.c @@ -2,6 +2,6 @@ int pthread_spin_lock(pthread_spinlock_t *s) { - while (a_swap(s, 1)) a_spin(); + while (a_cas(s, 0, 1)) a_spin(); return 0; } -- 2.1.3