Commit c6a6820e authored by Mikael Ronstrom's avatar Mikael Ronstrom

Add support for Atomic instructions for Windows

Enables Google patch support on Windows
parent ea9e898b
......@@ -25,6 +25,25 @@ IF(CMAKE_GENERATOR MATCHES "Visual Studio" AND CMAKE_SIZEOF_VOID_P MATCHES 8)
PROPERTIES COMPILE_FLAGS -Od)
ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio" AND CMAKE_SIZEOF_VOID_P MATCHES 8)
IF (NOT WITHOUT_ATOMICS)
# Check if this Windows version supports atomic instructions
IF (CMAKE_SIZEOF_VOID_P MATCHES 8)
# Check for 64 bit atomics
TRY_RUN(RUN_RES COMPILE_RES ${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}/storage/innobase/win_atomics64_test.c)
IF (RUN_RES)
ADD_DEFINTIONS(-DWIN_ATOMICS64)
ENDIF (RUN_RES)
ELSE (CMAKE_SIZEOF_VOID_P MATCHES 8)
# Check for 32 bit atomics
TRY_RUN(run_res compile_res ${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}/storage/innobase/win_atomics32_test.c)
IF (RUN_RES)
ADD_DEFINITIONS(-DWIN_ATOMICS32)
ENDIF (RUN_RES)
ENDIF (CMAKE_SIZEOF_VOID_P MATCHES 8)
ENDIF (NOT WITHOUT_ATOMICS)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/zlib
${CMAKE_SOURCE_DIR}/storage/innobase/include
${CMAKE_SOURCE_DIR}/storage/innobase/handler
......
......@@ -168,7 +168,8 @@ ha_innodb_la_SOURCES= $(libinnobase_a_SOURCES)
EXTRA_DIST= CMakeLists.txt plug.in \
pars/make_bison.sh pars/make_flex.sh \
pars/pars0grm.y pars/pars0lex.l
pars/pars0grm.y pars/pars0lex.l \
win_atomics32_test.c win_atomics64_test.c
# Don't update the files from bitkeeper
%::SCCS/s.%
......@@ -64,6 +64,12 @@ os_compare_and_swap(
lint retVal = (lint)atomic_cas_ulong((volatile ulong_t *)ptr,
oldVal, newVal);
return (retVal == oldVal);
#elif WIN_ATOMICS32
lint retVal = (lint)InterlockedCompareExchange(ptr, newVal, oldVal);
return (retVal == oldVal);
#elif WIN_ATOMICS64
lint retVal = (lint)InterlockedCompareExchange64(ptr, newVal, oldVal);
return (retVal == oldVal);
#else
#error "Need support for atomic ops"
#endif
......@@ -79,6 +85,10 @@ os_memory_barrier_load()
__sync_synchronize();
#elif HAVE_SOLARIS_ATOMIC
membar_consumer();
#elif WIN_ATOMICS32
MemoryBarrier();
#elif WIN_ATOMICS64
MemoryBarrier();
#endif
}
......@@ -92,6 +102,10 @@ os_memory_barrier_store()
__sync_synchronize();
#elif HAVE_SOLARIS_ATOMIC
membar_producer();
#elif WIN_ATOMICS32
MemoryBarrier();
#elif WIN_ATOMICS64
MemoryBarrier();
#endif
}
......@@ -105,6 +119,10 @@ os_memory_barrier()
__sync_synchronize();
#elif HAVE_SOLARIS_ATOMIC
membar_enter();
#elif WIN_ATOMICS32
MemoryBarrier();
#elif WIN_ATOMICS64
MemoryBarrier();
#endif
}
......@@ -123,9 +141,12 @@ os_atomic_increment(
return (__sync_add_and_fetch(ptr, amount));
#elif HAVE_SOLARIS_ATOMIC
return ((lint)atomic_add_long_nv((volatile ulong_t *)ptr, amount));
#elif WIN_ATOMICS32
return ((lint)InterlockedExchangeAdd(ptr, amount));
#elif WIN_ATOMICS64
return ((lint)InterlockedExchangeAdd64(ptr, amount));
#else
#error "Need support for atomic ops"
#endif
}
#endif /* UNIV_SYNC_ATOMIC */
......@@ -144,6 +144,14 @@ by one. */
#define UNIV_SYNC_ATOMIC
#endif
#if defined(WIN_ATOMICS32) || defined(WIN_ATOMICS64)
/*
* We have a full set of atomic ops available - we will use them
* This is on Windows
*/
#define UNIV_SYNC_ATOMIC
#endif
/*
#define UNIV_SQL_DEBUG
#define UNIV_LOG_DEBUG
......
# Copyright (C) 2009 Sun Microsystems AB
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <windows.h>
int main()
{
volatile long var32 = 0;
long add32 = 1;
long old32 = 0;
long exch32 = 1;
long ret_value;
ret_value = InterlockedExchangeAdd(&var32, add32);
ret_value = InterlockedCompareExchange(&var32, exch32, old32);
MemoryBarrier();
return EXIT_SUCCESS;
}
# Copyright (C) 2009 Sun Microsystems AB
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <windows.h>
int main()
{
volatile long long var64 = 0;
long long add64 = 1;
long long old64 = 0;
long long exch64 = 1;
long long ret_value;
ret_value = InterlockedExchangeAdd64(&var64, add64);
ret_value = InterlockedCompareExchange64(&var64, exch64, old64);
MemoryBarrier();
return EXIT_SUCCESS;
}
......@@ -58,6 +58,7 @@ The options right now are:
WITH_EXAMPLE_STORAGE_ENGINE
WITH_FEDERATED_STORAGE_ENGINE
__NT__ Enable named pipe support
WITHOUT_ATOMICS Do not use atomic instructions
MYSQL_SERVER_SUFFIX=<suffix> Server suffix, default none
COMPILATION_COMMENT=<comment> Server comment, default "Source distribution"
MYSQL_TCP_PORT=<port> Server port, default 3306
......
......@@ -50,6 +50,7 @@ try
case "EMBED_MANIFESTS":
case "EXTRA_DEBUG":
case "WITH_EMBEDDED_SERVER":
case "WITHOUT_ATOMICS":
configfile.WriteLine("SET (" + args.Item(i) + " TRUE)");
break;
case "MYSQL_SERVER_SUFFIX":
......
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