summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2015-05-22 14:07:35 +0200
committerSergei Golubchik <serg@mariadb.org>2015-06-02 18:53:37 +0200
commit6309a30dc96f6c3615b8c5609f07f9bc3898352c (patch)
treeef69b4283b9aa0412bad9979bbf5077a4483f008 /include
parent196e8529837558a72baf31d012285cc283b8e95d (diff)
downloadmariadb-git-6309a30dc96f6c3615b8c5609f07f9bc3898352c.tar.gz
my_b_fill, inline my_b_* functions instead of hairy macros
Diffstat (limited to 'include')
-rw-r--r--include/my_sys.h141
-rw-r--r--include/thr_lock.h1
2 files changed, 97 insertions, 45 deletions
diff --git a/include/my_sys.h b/include/my_sys.h
index 3d930d31bc2..8e0e34f2796 100644
--- a/include/my_sys.h
+++ b/include/my_sys.h
@@ -19,6 +19,8 @@
#include "my_global.h" /* C_MODE_START, C_MODE_END */
+#include <m_string.h>
+
C_MODE_START
#ifdef HAVE_AIOWAIT
@@ -507,52 +509,108 @@ typedef void (*my_error_reporter)(enum loglevel level, const char *format, ...)
extern my_error_reporter my_charset_error_reporter;
- /* defines for mf_iocache */
+/* inline functions for mf_iocache */
+
+extern int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock);
+extern int _my_b_get(IO_CACHE *info);
+extern int _my_b_read(IO_CACHE *info,uchar *Buffer,size_t Count);
+extern int _my_b_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
- /* Test if buffer is inited */
-#define my_b_clear(info) (info)->buffer=0
-#define my_b_inited(info) (info)->buffer
+/* Test if buffer is inited */
+static inline void my_b_clear(IO_CACHE *info) { info->buffer= 0; }
+static inline int my_b_inited(IO_CACHE *info) { return MY_TEST(info->buffer); }
#define my_b_EOF INT_MIN
-#define my_b_read(info,Buffer,Count) \
- ((info)->read_pos + (Count) <= (info)->read_end ?\
- (memcpy(Buffer,(info)->read_pos,(size_t) (Count)), \
- ((info)->read_pos+=(Count)), 0) : _my_b_read((info), (Buffer), (Count)))
-
-#define my_b_write(info,Buffer,Count) \
- ((info)->write_pos + (Count) <=(info)->write_end ?\
- (memcpy((info)->write_pos, (Buffer), (size_t)(Count)),\
- ((info)->write_pos+=(Count)), 0) : _my_b_write((info), (Buffer), (Count)))
-
-#define my_b_get(info) \
- ((info)->read_pos != (info)->read_end ?\
- ((info)->read_pos++, (int) (uchar) (info)->read_pos[-1]) :\
- _my_b_get(info))
-
- /* my_b_write_byte dosn't have any err-check */
-#define my_b_write_byte(info,chr) \
- (((info)->write_pos < (info)->write_end) ?\
- ((*(info)->write_pos++)=(chr)) :\
- ((my_b_flush_io_cache(info, 1)), ((*(info)->write_pos++)=(chr))))
-
-#define my_b_tell(info) ((info)->pos_in_file + \
- (size_t) (*(info)->current_pos - (info)->request_pos))
-#define my_b_write_tell(info) ((info)->pos_in_file + \
- ((info)->write_pos - (info)->write_buffer))
-
-#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 */
+static inline int my_b_read(IO_CACHE *info, uchar *Buffer, size_t Count)
+{
+ if (info->read_pos + Count <= info->read_end)
+ {
+ memcpy(Buffer, info->read_pos, Count);
+ info->read_pos+= Count;
+ return 0;
+ }
+ return _my_b_read(info, Buffer, Count);
+}
+
+static inline int my_b_write(IO_CACHE *info, const uchar *Buffer, size_t Count)
+{
+ if (info->write_pos + Count <= info->write_end)
+ {
+ memcpy(info->write_pos, Buffer, Count);
+ info->write_pos+= Count;
+ return 0;
+ }
+ return _my_b_write(info, Buffer, Count);
+}
+
+static inline int my_b_get(IO_CACHE *info)
+{
+ if (info->read_pos != info->read_end)
+ {
+ info->read_pos++;
+ return info->read_pos[-1];
+ }
+ return _my_b_get(info);
+}
+
+/* my_b_write_byte dosn't have any err-check */
+static inline void my_b_write_byte(IO_CACHE *info, uchar chr)
+{
+ if (info->write_pos >= info->write_end)
+ my_b_flush_io_cache(info, 1);
+ *info->write_pos++= chr;
+}
+
+/**
+ Fill buffer of the cache.
+
+ @note It assumes that you have already used all characters in the CACHE,
+ independent of the read_pos value!
+
+ @returns
+ 0 On error or EOF (info->error = -1 on error)
+ # Number of characters
+*/
+static inline size_t my_b_fill(IO_CACHE *info)
+{
+ info->read_pos= info->read_end;
+ return _my_b_read(info,0,0) ? 0 : info->read_end - info->read_pos;
+}
+
+static inline my_off_t my_b_tell(const IO_CACHE *info)
+{
+ return info->pos_in_file + (*info->current_pos - info->request_pos);
+}
+
+static inline my_off_t my_b_write_tell(const IO_CACHE *info)
+{
+ return info->pos_in_file + (info->write_pos - info->write_buffer);
+}
+
+static inline uchar* my_b_get_buffer_start(const IO_CACHE *info)
+{
+ return info->request_pos;
+}
+
+static inline size_t my_b_get_bytes_in_buffer(const IO_CACHE *info)
+{
+ return info->read_end - info->request_pos;
+}
+
+static inline my_off_t my_b_get_pos_in_file(const IO_CACHE *info)
+{
+ return info->pos_in_file;
+}
+
+static inline size_t my_b_bytes_in_cache(const IO_CACHE *info)
+{
+ return *info->current_end - *info->current_pos;
+}
+
int my_b_copy_to_file(IO_CACHE *cache, FILE *file);
my_off_t my_b_append_tell(IO_CACHE* info);
my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */
-#define my_b_bytes_in_cache(info) (size_t) (*(info)->current_end - \
- *(info)->current_pos)
-
typedef uint32 ha_checksum;
extern ulong my_crc_dbug_check;
@@ -741,24 +799,19 @@ extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
my_off_t seek_offset, my_bool use_async_io,
my_bool clear_cache);
extern void setup_io_cache(IO_CACHE* info);
-extern int _my_b_read(IO_CACHE *info,uchar *Buffer,size_t Count);
extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
IO_CACHE *write_cache, uint num_threads);
extern void remove_io_thread(IO_CACHE *info);
-extern int _my_b_get(IO_CACHE *info);
extern int _my_b_async_read(IO_CACHE *info,uchar *Buffer,size_t Count);
-extern int _my_b_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
extern int my_b_append(IO_CACHE *info,const uchar *Buffer,size_t Count);
extern int my_b_safe_write(IO_CACHE *info,const uchar *Buffer,size_t Count);
extern int my_block_write(IO_CACHE *info, const uchar *Buffer,
size_t Count, my_off_t pos);
-extern int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock);
#define flush_io_cache(info) my_b_flush_io_cache((info),1)
extern int end_io_cache(IO_CACHE *info);
-extern size_t my_b_fill(IO_CACHE *info);
extern void my_b_seek(IO_CACHE *info,my_off_t pos);
extern size_t my_b_gets(IO_CACHE *info, char *to, size_t max_length);
extern my_off_t my_b_filelength(IO_CACHE *info);
diff --git a/include/thr_lock.h b/include/thr_lock.h
index 2561709285f..bc916b8ec9c 100644
--- a/include/thr_lock.h
+++ b/include/thr_lock.h
@@ -166,7 +166,6 @@ void thr_set_lock_wait_callback(void (*before_wait)(void),
void (*after_wait)(void));
#ifdef WITH_WSREP
-#include <my_sys.h>
typedef my_bool (* wsrep_thd_is_brute_force_fun)(void *, my_bool);
typedef int (* wsrep_abort_thd_fun)(void *, void *, my_bool);
typedef int (* wsrep_on_fun)(void *);