From ece032d044e0b0e20dae1639381eb66a9ffd6ea6 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Tue, 8 Nov 2011 21:23:52 +0400 Subject: Generalize AO_compare_and_swap primitives via AO_fetch_compare_and_swap * src/atomic_ops.c (AO_compare_and_swap_emulation): Remove. * src/atomic_ops/sysdeps/emul_cas.h (AO_compare_and_swap_emulation, AO_compare_and_swap_full, AO_HAVE_compare_and_swap_full): Likewise. * src/atomic_ops/sysdeps/gcc/ia64.h (AO_compare_and_swap_acquire, AO_HAVE_compare_and_swap_acquire, AO_compare_and_swap_release, AO_HAVE_compare_and_swap_release, AO_char_compare_and_swap_acquire, AO_HAVE_char_compare_and_swap_acquire, AO_char_compare_and_swap_release, AO_HAVE_char_compare_and_swap_release, AO_short_compare_and_swap_acquire, AO_HAVE_short_compare_and_swap_acquire, AO_short_compare_and_swap_release, AO_HAVE_short_compare_and_swap_release, AO_int_compare_and_swap_acquire, AO_HAVE_int_compare_and_swap_acquire, AO_int_compare_and_swap_release, AO_HAVE_int_compare_and_swap_release): Likewise. * src/atomic_ops/sysdeps/generic_pthread.h (AO_compare_and_swap_full): Likewise. * src/atomic_ops/sysdeps/hpc/ia64.h (AO_compare_and_swap_acquire, AO_HAVE_compare_and_swap_acquire, AO_compare_and_swap_release, AO_HAVE_compare_and_swap_release, AO_char_compare_and_swap_acquire, AO_HAVE_char_compare_and_swap_acquire, AO_char_compare_and_swap_release, AO_HAVE_char_compare_and_swap_release, AO_short_compare_and_swap_acquire, AO_HAVE_short_compare_and_swap_acquire, AO_short_compare_and_swap_release, AO_HAVE_short_compare_and_swap_release): Likewise. * src/atomic_ops/sysdeps/ibmc/powerpc.h (AO_compare_and_swap_acquire, AO_HAVE_compare_and_swap_acquire, AO_compare_and_swap_release, AO_HAVE_compare_and_swap_release, AO_compare_and_swap_full, AO_HAVE_compare_and_swap_full): Likewise. * src/atomic_ops/sysdeps/icc/ia64.h (AO_compare_and_swap_acquire, AO_HAVE_compare_and_swap_acquire, AO_compare_and_swap_release, AO_HAVE_compare_and_swap_release, AO_char_compare_and_swap_acquire, AO_HAVE_char_compare_and_swap_acquire, AO_char_compare_and_swap_release, AO_HAVE_char_compare_and_swap_release, AO_short_compare_and_swap_acquire, AO_HAVE_short_compare_and_swap_acquire, AO_short_compare_and_swap_release, AO_HAVE_short_compare_and_swap_release, AO_int_compare_and_swap_acquire, AO_HAVE_int_compare_and_swap_acquire, AO_int_compare_and_swap_release, AO_HAVE_int_compare_and_swap_release): Likewise. * src/atomic_ops/sysdeps/msftc/common32_defs.h (AO_compare_and_swap_full, AO_HAVE_compare_and_swap_full): Likewise. * src/atomic_ops/sysdeps/msftc/x86_64.h (AO_compare_and_swap_full, AO_HAVE_compare_and_swap_full): Likewise. * src/atomic_ops.h: Do not include emul_cas.h if any of AO_HAVE_fetch_compare_and_swap_... is defined. * src/atomic_ops.h (AO_HAVE_fetch_compare_and_swap_full): Do not define AO_GENERALIZE_TWICE if AO_HAVE_fetch_compare_and_swap_full and AO_CAN_EMUL_CAS are both defined. * src/atomic_ops/generalize-small.template (AO_XSIZE_compare_and_swap_full, AO_XSIZE_compare_and_swap_acquire, AO_XSIZE_compare_and_swap_release): New template (based on the corresponding AO_XSIZE_fetch_compare_and_swap primitive). * src/atomic_ops/generalize-small.template (AO_HAVE_XSIZE_compare_and_swap_full, AO_HAVE_XSIZE_compare_and_swap_acquire, AO_HAVE_XSIZE_compare_and_swap_release): Define. * src/atomic_ops/generalize.h (AO_HAVE_compare_and_swap, AO_HAVE_compare_and_swap_full, AO_HAVE_compare_and_swap_acquire, AO_HAVE_compare_and_swap_release): Likewise. * src/atomic_ops/generalize-small.h: Regenerate. * src/atomic_ops/generalize.h (AO_compare_and_swap, AO_compare_and_swap_full, AO_compare_and_swap_acquire, AO_compare_and_swap_release): New function implementation (based on the corresponding AO_fetch_compare_and_swap primitive). --- src/atomic_ops.c | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) (limited to 'src/atomic_ops.c') diff --git a/src/atomic_ops.c b/src/atomic_ops.c index fb262b8..79ae28f 100644 --- a/src/atomic_ops.c +++ b/src/atomic_ops.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003 Hewlett-Packard Development Company, L.P. + * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -185,32 +185,6 @@ AO_INLINE void unlock(volatile AO_TS_t *l) } #endif /* !AO_USE_NO_SIGNALS */ -int AO_compare_and_swap_emulation(volatile AO_t *addr, AO_t old, - AO_t new_val) -{ - AO_TS_t *my_lock = AO_locks + AO_HASH(addr); - int result; - -# ifndef AO_USE_NO_SIGNALS - sigset_t old_sigs; - block_all_signals(&old_sigs); -# endif - - lock(my_lock); - if (*addr == old) - { - *addr = new_val; - result = 1; - } - else - result = 0; - unlock(my_lock); -# ifndef AO_USE_NO_SIGNALS - sigprocmask(SIG_SETMASK, &old_sigs, NULL); -# endif - return result; -} - AO_t AO_fetch_compare_and_swap_emulation(volatile AO_t *addr, AO_t old_val, AO_t new_val) { -- cgit v1.2.1