From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/9365 Path: news.gmane.org!not-for-mail From: Bobby Bingham Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] allow implementing a_cas_p with pointer-sized ll/sc Date: Mon, 22 Feb 2016 21:14:23 -0600 Message-ID: <1456197263-24464-1-git-send-email-koorogi@koorogi.info> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1456197291 10187 80.91.229.3 (23 Feb 2016 03:14:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 23 Feb 2016 03:14:51 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-9378-gllmg-musl=m.gmane.org@lists.openwall.com Tue Feb 23 04:14:51 2016 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 1aY3R4-0004lp-02 for gllmg-musl@m.gmane.org; Tue, 23 Feb 2016 04:14:50 +0100 Original-Received: (qmail 19510 invoked by uid 550); 23 Feb 2016 03:14:45 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 19469 invoked from network); 23 Feb 2016 03:14:42 -0000 X-Mailer: git-send-email 2.7.1 Xref: news.gmane.org gmane.linux.lib.musl.general:9365 Archived-At: No current ports do this, but it will be useful for porting to 64-bit ll/sc architectures, such as mips64 and powerpc64. --- src/internal/atomic.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/internal/atomic.h b/src/internal/atomic.h index 2097247..6f37d25 100644 --- a/src/internal/atomic.h +++ b/src/internal/atomic.h @@ -82,6 +82,23 @@ static inline int a_fetch_or(volatile int *p, int v) #endif +#ifdef a_ll_p + +#ifndef a_cas_p +#define a_cas_p a_cas_p +static inline void *a_cas_p(volatile void *p, void *t, void *s) +{ + void *old; + a_pre_llsc(); + do old = a_ll_p(p); + while (old==t && !a_sc_p(p, s)); + a_post_llsc(); + return old; +} +#endif + +#endif + #ifndef a_cas #error missing definition of a_cas #endif @@ -209,6 +226,7 @@ static inline void a_or_64(volatile uint64_t *p, uint64_t v) #endif #ifndef a_cas_p +typedef char a_cas_p_undefined_but_pointer_not_32bit[-sizeof(char) == 0xffffffff ? 1 : -1]; #define a_cas_p a_cas_p static inline void *a_cas_p(volatile void *p, void *t, void *s) { -- 2.7.1