diff options
-rw-r--r-- | include/my_pthread.h | 22 | ||||
-rw-r--r-- | include/my_sys.h | 3 | ||||
-rw-r--r-- | mysys/my_fopen.c | 2 | ||||
-rw-r--r-- | mysys/my_open.c | 9 | ||||
-rw-r--r-- | mysys/my_static.c | 3 | ||||
-rw-r--r-- | sql/mysqld.cc | 2 | ||||
-rw-r--r-- | sql/mysqld.h | 20 | ||||
-rw-r--r-- | sql/sql_test.cc | 10 |
8 files changed, 36 insertions, 35 deletions
diff --git a/include/my_pthread.h b/include/my_pthread.h index 264125a8fe3..ecb758bdc1d 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -23,6 +23,8 @@ #define ETIME ETIMEDOUT /* For FreeBSD */ #endif +#include <my_atomic.h> + #ifdef __cplusplus #define EXTERNC extern "C" extern "C" { @@ -803,6 +805,26 @@ extern uint thd_lib_detected; #define statistic_sub(V,C,L) (V)-=(C) #endif /* SAFE_STATISTICS */ +static inline void thread_safe_increment32(int32 *value) +{ + (void) my_atomic_add32_explicit(value, 1, MY_MEMORY_ORDER_RELAXED); +} + +static inline void thread_safe_decrement32(int32 *value) +{ + (void) my_atomic_add32_explicit(value, -1, MY_MEMORY_ORDER_RELAXED); +} + +static inline void thread_safe_increment64(int64 *value) +{ + (void) my_atomic_add64_explicit(value, 1, MY_MEMORY_ORDER_RELAXED); +} + +static inline void thread_safe_decrement64(int64 *value) +{ + (void) my_atomic_add64_explicit(value, -1, MY_MEMORY_ORDER_RELAXED); +} + /* No locking needed, the counter is owned by the thread */ diff --git a/include/my_sys.h b/include/my_sys.h index ddaceff8708..bc9cf903361 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -261,10 +261,11 @@ extern ulonglong my_collation_statistics_get_use_count(uint id); extern const char *my_collation_get_tailoring(uint id); /* statistics */ -extern ulong my_file_opened,my_stream_opened, my_tmp_file_created; +extern ulong my_stream_opened, my_tmp_file_created; extern ulong my_file_total_opened; extern ulong my_sync_count; extern uint mysys_usage_id; +extern int32 my_file_opened; extern my_bool my_init_done, my_thr_key_mysys_exists; extern my_bool my_assert_on_error; extern myf my_global_flags; /* Set to MY_WME for more error messages */ diff --git a/mysys/my_fopen.c b/mysys/my_fopen.c index fbd84049700..e33d9d67925 100644 --- a/mysys/my_fopen.c +++ b/mysys/my_fopen.c @@ -223,7 +223,7 @@ FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags) { if (my_file_info[Filedes].type != UNOPEN) { - statistic_decrement(my_file_opened, &THR_LOCK_open); /* File is opened with my_open ! */ + thread_safe_decrement32(&my_file_opened); /* File is opened with my_open ! */ } else { diff --git a/mysys/my_open.c b/mysys/my_open.c index 92e46610100..aa3b0448cdb 100644 --- a/mysys/my_open.c +++ b/mysys/my_open.c @@ -105,7 +105,7 @@ int my_close(File fd, myf MyFlags) { my_free(name); } - statistic_decrement(my_file_opened, &THR_LOCK_open); + thread_safe_decrement32(&my_file_opened); DBUG_RETURN(err); } /* my_close */ @@ -133,13 +133,10 @@ File my_register_filename(File fd, const char *FileName, enum file_type DBUG_ENTER("my_register_filename"); if ((int) fd >= MY_FILE_MIN) { + thread_safe_increment32(&my_file_opened); if ((uint) fd >= my_file_limit) - { - statistic_increment(my_file_opened,&THR_LOCK_open); - DBUG_RETURN(fd); /* safeguard */ - } + DBUG_RETURN(fd); my_file_info[fd].name = (char*) my_strdup(FileName, MyFlags); - statistic_increment(my_file_opened,&THR_LOCK_open); statistic_increment(my_file_total_opened,&THR_LOCK_open); my_file_info[fd].type = type_of_file; DBUG_PRINT("exit",("fd: %d",fd)); diff --git a/mysys/my_static.c b/mysys/my_static.c index f2a9fbb7335..a8f520e656a 100644 --- a/mysys/my_static.c +++ b/mysys/my_static.c @@ -31,7 +31,7 @@ char *mysql_data_home= (char*) "."; const char *my_progname= NULL, *my_progname_short= NULL; char curr_dir[FN_REFLEN]= {0}, home_dir_buff[FN_REFLEN]= {0}; -ulong my_stream_opened=0,my_file_opened=0, my_tmp_file_created=0; +ulong my_stream_opened=0,my_tmp_file_created=0; ulong my_file_total_opened= 0; int my_umask=0664, my_umask_dir=0777; @@ -39,6 +39,7 @@ myf my_global_flags= 0; my_bool my_assert_on_error= 0; struct st_my_file_info my_file_info_default[MY_NFILE]; uint my_file_limit= MY_NFILE; +int32 my_file_opened=0; struct st_my_file_info *my_file_info= my_file_info_default; /* From mf_brkhant */ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 4f5026fd3b5..1c948f4563f 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -8630,7 +8630,7 @@ SHOW_VAR status_vars[]= { {"Memory_used", (char*) &show_memory_used, SHOW_SIMPLE_FUNC}, {"Memory_used_initial", (char*) &start_memory_used, SHOW_LONGLONG}, {"Not_flushed_delayed_rows", (char*) &delayed_rows_in_use, SHOW_LONG_NOFLUSH}, - {"Open_files", (char*) &my_file_opened, SHOW_LONG_NOFLUSH}, + {"Open_files", (char*) &my_file_opened, SHOW_SINT}, {"Open_streams", (char*) &my_stream_opened, SHOW_LONG_NOFLUSH}, {"Open_table_definitions", (char*) &show_table_definitions, SHOW_SIMPLE_FUNC}, {"Open_tables", (char*) &show_open_tables, SHOW_SIMPLE_FUNC}, diff --git a/sql/mysqld.h b/sql/mysqld.h index 9cb0a0fda39..dccf7436f80 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -790,26 +790,6 @@ inline void table_case_convert(char * name, uint length) name, length, name, length); } -inline void thread_safe_increment32(int32 *value) -{ - (void) my_atomic_add32_explicit(value, 1, MY_MEMORY_ORDER_RELAXED); -} - -inline void thread_safe_decrement32(int32 *value) -{ - (void) my_atomic_add32_explicit(value, -1, MY_MEMORY_ORDER_RELAXED); -} - -inline void thread_safe_increment64(int64 *value) -{ - (void) my_atomic_add64_explicit(value, 1, MY_MEMORY_ORDER_RELAXED); -} - -inline void thread_safe_decrement64(int64 *value) -{ - (void) my_atomic_add64_explicit(value, -1, MY_MEMORY_ORDER_RELAXED); -} - extern void set_server_version(char *buf, size_t size); #define current_thd _current_thd() diff --git a/sql/sql_test.cc b/sql/sql_test.cc index 3d43c35177d..e9f31571f2f 100644 --- a/sql/sql_test.cc +++ b/sql/sql_test.cc @@ -596,13 +596,13 @@ update: %10lu\n", tmp.ha_update_count); printf("\nTable status:\n\ Opened tables: %10lu\n\ -Open tables: %10lu\n\ -Open files: %10lu\n\ +Open tables: %10u\n\ +Open files: %10u\n\ Open streams: %10lu\n", tmp.opened_tables, - (ulong) tc_records(), - (ulong) my_file_opened, - (ulong) my_stream_opened); + tc_records(), + my_file_opened, + my_stream_opened); #ifndef DONT_USE_THR_ALARM ALARM_INFO alarm_info; |