From patchwork Tue Jul 28 09:02:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 7886 X-Patchwork-Delegate: vapier@gentoo.org Received: (qmail 66984 invoked by alias); 28 Jul 2015 09:02:59 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 66968 invoked by uid 89); 28 Jul 2015 09:02:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: smtp.gentoo.org From: Mike Frysinger To: libc-alpha@sourceware.org Subject: [PATCH/committed] ia64: atomic.h: fix atomic_exchange_and_add 64bit handling Date: Tue, 28 Jul 2015 05:02:57 -0400 Message-Id: <1438074177-11274-1-git-send-email-vapier@gentoo.org> Way back in 2005 the atomic_exchange_and_add function was cleaned up to avoid the explicit size checking and instead let gcc handle things itself. Unfortunately that change ended up leaving beyond a cast to int, even when the incoming value was a long. This has flown under the radar for a long time due to the function not being heavily used in the tree (especially as a full 64bit field), but a recent change to semaphores made some nptl tests fail reliably. This is due to the code packing two 32bit values into one 64bit variable (where the high 32bits contained the number of waiters), and then the whole variable being atomically updated between threads. On ia64, that meant we never atomically updated the count, so sometimes the sem_post would not wake up the waiters. --- ChangeLog | 5 +++++ sysdeps/ia64/bits/atomic.h | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index b177adc..cd2d827 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2015-07-27 Mike Frysinger + * sysdeps/ia64/bits/atomic.h (atomic_exchange_and_add): Define + directly in terms of __sync_fetch_and_add and delete (int) cast. + +2015-07-27 Mike Frysinger + * sysdeps/unix/sysv/linux/ia64/Makefile (CPPFLAGS): Delete the -D_ASM_IA64_CURRENT_H flag. diff --git a/sysdeps/ia64/bits/atomic.h b/sysdeps/ia64/bits/atomic.h index 0e9dfc7..4c2b540 100644 --- a/sysdeps/ia64/bits/atomic.h +++ b/sysdeps/ia64/bits/atomic.h @@ -82,9 +82,7 @@ typedef uintmax_t uatomic_max_t; (__sync_synchronize (), __sync_lock_test_and_set (mem, value)) #define atomic_exchange_and_add(mem, value) \ - ({ __typeof (*mem) __result; \ - __result = __sync_fetch_and_add ((mem), (int) (value)); \ - __result; }) + __sync_fetch_and_add ((mem), (value)) #define atomic_decrement_if_positive(mem) \ ({ __typeof (*mem) __oldval, __val; \