summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/Makefile.am2
-rw-r--r--include/atomic/gcc_builtins.h33
-rw-r--r--include/atomic/nolock.h7
-rw-r--r--include/my_bitmap.h16
-rw-r--r--include/my_sys.h5
5 files changed, 60 insertions, 3 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index 400c6976e5b..2155571cd5a 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -36,7 +36,7 @@ noinst_HEADERS = config-win.h config-netware.h lf.h my_bit.h \
mysql_version.h.in my_handler.h my_time.h \
my_vle.h my_user.h my_atomic.h atomic/nolock.h \
atomic/rwlock.h atomic/x86-gcc.h atomic/generic-msvc.h \
- my_libwrap.h wqueue.h
+ atomic/gcc_builtins.h my_libwrap.h wqueue.h
# Remove built files and the symlinked directories
CLEANFILES = $(BUILT_SOURCES) readline openssl
diff --git a/include/atomic/gcc_builtins.h b/include/atomic/gcc_builtins.h
new file mode 100644
index 00000000000..509701b30a5
--- /dev/null
+++ b/include/atomic/gcc_builtins.h
@@ -0,0 +1,33 @@
+/* Copyright (C) 2008 MySQL 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#define make_atomic_add_body(S) \
+ v= __sync_fetch_and_add(a, v);
+#define make_atomic_swap_body(S) \
+ v= __sync_lock_test_and_set(a, v);
+#define make_atomic_cas_body(S) \
+ int ## S sav; \
+ sav= __sync_val_compare_and_swap(a, *cmp, set); \
+ if (!(ret= (sav == *cmp))) *cmp= sav;
+
+#ifdef MY_ATOMIC_MODE_DUMMY
+#define make_atomic_load_body(S) ret= *a
+#define make_atomic_store_body(S) *a= v
+#else
+#define make_atomic_load_body(S) \
+ ret= __sync_fetch_and_or(a, 0);
+#define make_atomic_store_body(S) \
+ (void) __sync_lock_test_and_set(a, v);
+#endif
diff --git a/include/atomic/nolock.h b/include/atomic/nolock.h
index 59497d34c11..cafd916981d 100644
--- a/include/atomic/nolock.h
+++ b/include/atomic/nolock.h
@@ -13,7 +13,8 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-#if defined(__i386__) || defined(_MSC_VER) || defined(__x86_64__)
+#if defined(__i386__) || defined(_MSC_VER) || \
+ defined(__x86_64__) || defined(HAVE_GCC_ATOMIC_BUILTINS)
# ifdef MY_ATOMIC_MODE_DUMMY
# define LOCK_prefix ""
@@ -21,7 +22,9 @@
# define LOCK_prefix "lock"
# endif
-# ifdef __GNUC__
+# ifdef HAVE_GCC_ATOMIC_BUILTINS
+# include "gcc_builtins.h"
+# elif __GNUC__
# include "x86-gcc.h"
# elif defined(_MSC_VER)
# include "generic-msvc.h"
diff --git a/include/my_bitmap.h b/include/my_bitmap.h
index ab69b2d671d..78642df3362 100644
--- a/include/my_bitmap.h
+++ b/include/my_bitmap.h
@@ -159,6 +159,22 @@ static inline my_bool bitmap_cmp(const MY_BITMAP *map1, const MY_BITMAP *map2)
#define bitmap_set_all(MAP) \
(memset((MAP)->bitmap, 0xFF, 4*no_words_in_map((MAP))))
+/**
+ check, set and clear a bit of interest of an integer.
+
+ If the bit is out of range @retval -1. Otherwise
+ bit_is_set @return 0 or 1 reflecting the bit is set or not;
+ bit_do_set @return 1 (bit is set 1)
+ bit_do_clear @return 0 (bit is cleared to 0)
+*/
+
+#define bit_is_set(I,B) (sizeof(I) * CHAR_BIT > (B) ? \
+ (((I) & (ULL(1) << (B))) == 0 ? 0 : 1) : -1)
+#define bit_do_set(I,B) (sizeof(I) * CHAR_BIT > (B) ? \
+ ((I) |= (ULL(1) << (B)), 1) : -1)
+#define bit_do_clear(I,B) (sizeof(I) * CHAR_BIT > (B) ? \
+ ((I) &= ~(ULL(1) << (B)), 0) : -1)
+
#ifdef __cplusplus
}
#endif
diff --git a/include/my_sys.h b/include/my_sys.h
index 363f3a12e64..0e670f4d965 100644
--- a/include/my_sys.h
+++ b/include/my_sys.h
@@ -539,6 +539,11 @@ typedef int (*qsort2_cmp)(const void *, const void *, const void *);
#define my_b_tell(info) ((info)->pos_in_file + \
(size_t) (*(info)->current_pos - (info)->request_pos))
+#define my_b_get_buffer_start(info) (info)->request_pos
+#define my_b_get_bytes_in_buffer(info) (char*) (info)->read_end - \
+ (char*) my_b_get_buffer_start(info)
+#define my_b_get_pos_in_file(info) (info)->pos_in_file
+
/* tell write offset in the SEQ_APPEND cache */
int my_b_copy_to_file(IO_CACHE *cache, FILE *file);
my_off_t my_b_append_tell(IO_CACHE* info);