diff options
-rwxr-xr-x | storage/innobase/CMakeLists.txt | 19 | ||||
-rw-r--r-- | storage/innobase/Makefile.am | 3 | ||||
-rw-r--r-- | storage/innobase/include/os0sync.ic | 23 | ||||
-rw-r--r-- | storage/innobase/include/univ.i | 8 | ||||
-rw-r--r-- | storage/innobase/win_atomics32_test.c | 30 | ||||
-rw-r--r-- | storage/innobase/win_atomics64_test.c | 29 | ||||
-rw-r--r-- | win/README | 1 | ||||
-rw-r--r-- | win/configure.js | 1 |
8 files changed, 112 insertions, 2 deletions
diff --git a/storage/innobase/CMakeLists.txt b/storage/innobase/CMakeLists.txt index 021a47f0398..dc1d87963fa 100755 --- a/storage/innobase/CMakeLists.txt +++ b/storage/innobase/CMakeLists.txt @@ -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 diff --git a/storage/innobase/Makefile.am b/storage/innobase/Makefile.am index 7410bf7e591..180d2ca0b87 100644 --- a/storage/innobase/Makefile.am +++ b/storage/innobase/Makefile.am @@ -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.% diff --git a/storage/innobase/include/os0sync.ic b/storage/innobase/include/os0sync.ic index 58593789e0d..5c1b473ad6d 100644 --- a/storage/innobase/include/os0sync.ic +++ b/storage/innobase/include/os0sync.ic @@ -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 */ diff --git a/storage/innobase/include/univ.i b/storage/innobase/include/univ.i index 6415e3dc6b3..d1d5439349f 100644 --- a/storage/innobase/include/univ.i +++ b/storage/innobase/include/univ.i @@ -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 diff --git a/storage/innobase/win_atomics32_test.c b/storage/innobase/win_atomics32_test.c new file mode 100644 index 00000000000..28b1754f6db --- /dev/null +++ b/storage/innobase/win_atomics32_test.c @@ -0,0 +1,30 @@ +# 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; +} diff --git a/storage/innobase/win_atomics64_test.c b/storage/innobase/win_atomics64_test.c new file mode 100644 index 00000000000..9114776e121 --- /dev/null +++ b/storage/innobase/win_atomics64_test.c @@ -0,0 +1,29 @@ +# 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; +} diff --git a/win/README b/win/README index 916f64913ac..63923a6d7e2 100644 --- a/win/README +++ b/win/README @@ -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 diff --git a/win/configure.js b/win/configure.js index ac51b15b9f0..c80645a73b2 100644 --- a/win/configure.js +++ b/win/configure.js @@ -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": |