diff options
author | Daniel Black <daniel@linux.vnet.ibm.com> | 2018-03-14 15:33:47 +1100 |
---|---|---|
committer | Vladislav Vaintroub <wlad@mariadb.com> | 2018-05-21 16:34:11 +0000 |
commit | 5c81cb880a054f34803e2821489533274ebf6c4e (patch) | |
tree | d2e55ef82e57cbe0777590c8cb63a2341591d928 /mysys/my_open.c | |
parent | f165077aa9b9df874a712d731e16968eb30875d4 (diff) | |
download | mariadb-git-5c81cb880a054f34803e2821489533274ebf6c4e.tar.gz |
MDEV-15635 mysys: THR_LOCK_open reduce usage
Change the following to statistic counters:
* my_file_opened
* my_file_total_opened
* my_stream_opened
* my_tmp_file_created
There is one non-statistics use of my_file_opened/my_stream_opened
in my_end which prints a warning if we shutdown and its still open.
It seems excessive to hold locks to prevent this warning.
A file descriptor is already a unique element per process - in Windows,
protection occurs at fd allocation using THR_LOCK_open in my_win_{,f}open
and in other OSes, a unique fd to file map exists at the OS level.
So accesses to my_file_info[fd] don't need to be protected by the
THR_LOCK_open.
my_close/my_fclose where restructured to clear out the my_file_info
before the close/my_win_close/my_win_fclose. After these calls another
thread could gain the same file descriptor. So for Windows this
the file_info elements available to the my_win_{,f}_open are released
during the invalidate_fd call within my_win_close. No locking is needed
as the my_win_{,f}open is searching for a invalidate entry which is
determined by a single value change.
my_fclose also changed for non-Windows to retry closing if EINTR was
returned, same as my_close.
Closes #657
Diffstat (limited to 'mysys/my_open.c')
-rw-r--r-- | mysys/my_open.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/mysys/my_open.c b/mysys/my_open.c index 3999810eb2e..6fc8f6d07fc 100644 --- a/mysys/my_open.c +++ b/mysys/my_open.c @@ -76,12 +76,18 @@ File my_open(const char *FileName, int Flags, myf MyFlags) int my_close(File fd, myf MyFlags) { int err; + char *name= NULL; DBUG_ENTER("my_close"); DBUG_PRINT("my",("fd: %d MyFlags: %lu",fd, MyFlags)); if (!(MyFlags & (MY_WME | MY_FAE))) MyFlags|= my_global_flags; - mysql_mutex_lock(&THR_LOCK_open); + if ((uint) fd < my_file_limit && my_file_info[fd].type != UNOPEN) + { + name= my_file_info[fd].name; + my_file_info[fd].name= NULL; + my_file_info[fd].type= UNOPEN; + } #ifndef _WIN32 do { @@ -96,15 +102,13 @@ int my_close(File fd, myf MyFlags) my_errno=errno; if (MyFlags & (MY_FAE | MY_WME)) my_error(EE_BADCLOSE, MYF(ME_BELL | ME_WAITTANG | (MyFlags & (ME_JUST_INFO | ME_NOREFRESH))), - my_filename(fd),errno); + name,errno); } - if ((uint) fd < my_file_limit && my_file_info[fd].type != UNOPEN) + if (name) { - my_free(my_file_info[fd].name); - my_file_info[fd].type = UNOPEN; + my_free(name); } - my_file_opened--; - mysql_mutex_unlock(&THR_LOCK_open); + statistic_decrement(my_file_opened, &THR_LOCK_open); DBUG_RETURN(err); } /* my_close */ @@ -134,15 +138,13 @@ File my_register_filename(File fd, const char *FileName, enum file_type { if ((uint) fd >= my_file_limit) { - thread_safe_increment(my_file_opened,&THR_LOCK_open); + statistic_increment(my_file_opened,&THR_LOCK_open); DBUG_RETURN(fd); /* safeguard */ } - mysql_mutex_lock(&THR_LOCK_open); my_file_info[fd].name = (char*) my_strdup(FileName, MyFlags); - my_file_opened++; - my_file_total_opened++; + 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; - mysql_mutex_unlock(&THR_LOCK_open); DBUG_PRINT("exit",("fd: %d",fd)); DBUG_RETURN(fd); } |