Commit 3c6d9917 authored by vasil's avatar vasil

branches/zip:

(followup to r4145) Non-functional change:

Change the os_atomic_increment() and os_compare_and_swap() functions
to macros to avoid artificial limitations on the types of those
functions' arguments. As a consequence typecasts from the source
code can be removed.

Also remove Google's copyright from os0sync.ic because that file no longer
contains code from Google.

Approved by:	Marko (rb://88), also ok from Inaam via IM
parent a805ee5f
......@@ -295,24 +295,18 @@ os_fast_mutex_free(
#ifdef HAVE_GCC_ATOMIC_BUILTINS
/**************************************************************
Atomic compare-and-swap for InnoDB. Currently requires GCC atomic builtins. */
UNIV_INLINE
ibool
os_compare_and_swap(
/*================*/
/* out: true if swapped */
volatile lint* ptr, /* in: pointer to target */
lint oldVal, /* in: value to compare to */
lint newVal); /* in: value to swap in */
Atomic compare-and-swap for InnoDB. Currently requires GCC atomic builtins.
Returns true if swapped, ptr is pointer to target, old_val is value to
compare to, new_val is the value to swap in. */
#define os_compare_and_swap(ptr, old_val, new_val) \
__sync_bool_compare_and_swap(ptr, old_val, new_val)
/**************************************************************
Atomic increment for InnoDB. Currently requires GCC atomic builtins. */
UNIV_INLINE
lint
os_atomic_increment(
/*================*/
/* out: resulting value */
volatile lint* ptr, /* in: pointer to target */
lint amount); /* in: amount of increment */
Atomic increment for InnoDB. Currently requires GCC atomic builtins.
Returns the resulting value, ptr is pointer to target, amount is the
amount of increment. */
#define os_atomic_increment(ptr, amount) \
__sync_add_and_fetch(ptr, amount)
#endif /* HAVE_GCC_ATOMIC_BUILTINS */
......
......@@ -5,38 +5,6 @@ The interface to the operating system synchronization primitives.
Created 9/6/1995 Heikki Tuuri
*******************************************************/
/***********************************************************************
# Copyright (c) 2008, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
# * Neither the name of the Google Inc. nor the names of its
# contributors may be used to endorse or promote products
# derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Note, the BSD license applies to the new code. The old code is GPL.
***********************************************************************/
#ifdef __WIN__
#include <winbase.h>
......@@ -76,38 +44,3 @@ os_fast_mutex_trylock(
#endif
#endif
}
#ifdef HAVE_GCC_ATOMIC_BUILTINS
/**************************************************************
Atomic compare-and-swap for InnoDB. Currently requires GCC atomic builtins. */
UNIV_INLINE
ibool
os_compare_and_swap(
/*================*/
/* out: true if swapped */
volatile lint* ptr, /* in: pointer to target */
lint oldVal, /* in: value to compare to */
lint newVal) /* in: value to swap in */
{
if(__sync_bool_compare_and_swap(ptr, oldVal, newVal)) {
return(TRUE);
}
return(FALSE);
}
/**************************************************************
Atomic increment for InnoDB. Currently requires GCC atomic builtins. */
UNIV_INLINE
lint
os_atomic_increment(
/*================*/
/* out: resulting value */
volatile lint* ptr, /* in: pointer to target */
lint amount) /* in: amount of increment */
{
lint newVal = __sync_add_and_fetch(ptr, amount);
return newVal;
}
#endif /* HAVE_GCC_ATOMIC_BUILTINS */
......@@ -98,7 +98,7 @@ rw_lock_set_waiter_flag(
rw_lock_t* lock) /* in: rw-lock */
{
#ifdef INNODB_RW_LOCKS_USE_ATOMICS
os_compare_and_swap((lint*)&(lock->waiters), 0, 1);
os_compare_and_swap(&lock->waiters, 0, 1);
#else /* INNODB_RW_LOCKS_USE_ATOMICS */
lock->waiters = 1;
#endif /* INNODB_RW_LOCKS_USE_ATOMICS */
......@@ -115,7 +115,7 @@ rw_lock_reset_waiter_flag(
rw_lock_t* lock) /* in: rw-lock */
{
#ifdef INNODB_RW_LOCKS_USE_ATOMICS
os_compare_and_swap((lint*)&(lock->waiters), 1, 0);
os_compare_and_swap(&lock->waiters, 1, 0);
#else /* INNODB_RW_LOCKS_USE_ATOMICS */
lock->waiters = 0;
#endif /* INNODB_RW_LOCKS_USE_ATOMICS */
......@@ -290,9 +290,9 @@ rw_lock_set_writer_id_and_recursion_flag(
#ifdef INNODB_RW_LOCKS_USE_ATOMICS
os_thread_id_t local_thread = lock->writer_thread;
ibool success = os_compare_and_swap((lint*)&(lock->writer_thread),
(lint)local_thread,
(lint)curr_thread);
ibool success = os_compare_and_swap(&lock->writer_thread,
local_thread,
curr_thread);
ut_a(success);
lock->recursive = recursive;
......
......@@ -866,7 +866,7 @@ sync_array_object_signalled(
sync_array_t* arr) /* in: wait array */
{
#ifdef HAVE_GCC_ATOMIC_BUILTINS
os_atomic_increment((lint*) &arr->sg_count, 1);
os_atomic_increment(&arr->sg_count, 1);
#else
sync_array_enter(arr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment