summaryrefslogtreecommitdiff
path: root/mysys/my_fopen.c
diff options
context:
space:
mode:
authorGalina Shalygina <galina.shalygina@mariadb.com>2018-06-01 21:57:10 +0200
committerGalina Shalygina <galina.shalygina@mariadb.com>2018-06-01 21:57:10 +0200
commit6db465d7ce455cf75ec224108cbe61ca8be63d3d (patch)
tree9648ff1fc677eebb60b278c2e2c13131934ed2a0 /mysys/my_fopen.c
parentffe83e8e7bef32eb2a80aad2d382f0b023dd3a44 (diff)
parent4a49f7f88cfa82ae6eb8e7b5a528e91416b33b52 (diff)
downloadmariadb-git-shagalla-10.4.tar.gz
Merge 10.3.7 into 10.4shagalla-10.4
Diffstat (limited to 'mysys/my_fopen.c')
-rw-r--r--mysys/my_fopen.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/mysys/my_fopen.c b/mysys/my_fopen.c
index 213eac82040..59baeaec744 100644
--- a/mysys/my_fopen.c
+++ b/mysys/my_fopen.c
@@ -61,15 +61,13 @@ FILE *my_fopen(const char *filename, int flags, myf MyFlags)
int filedesc= my_fileno(fd);
if ((uint)filedesc >= my_file_limit)
{
- thread_safe_increment(my_stream_opened,&THR_LOCK_open);
+ statistic_increment(my_stream_opened,&THR_LOCK_open);
DBUG_RETURN(fd); /* safeguard */
}
- mysql_mutex_lock(&THR_LOCK_open);
my_file_info[filedesc].name= (char*) my_strdup(filename,MyFlags);
- my_stream_opened++;
- my_file_total_opened++;
+ statistic_increment(my_stream_opened, &THR_LOCK_open);
+ statistic_increment(my_file_total_opened, &THR_LOCK_open);
my_file_info[filedesc].type= STREAM_BY_FOPEN;
- mysql_mutex_unlock(&THR_LOCK_open);
DBUG_PRINT("exit",("stream: %p", fd));
DBUG_RETURN(fd);
}
@@ -161,13 +159,22 @@ FILE *my_freopen(const char *path, const char *mode, FILE *stream)
int my_fclose(FILE *fd, myf MyFlags)
{
int err,file;
+ char *name= NULL;
DBUG_ENTER("my_fclose");
DBUG_PRINT("my",("stream: %p MyFlags: %lu", fd, MyFlags));
- mysql_mutex_lock(&THR_LOCK_open);
file= my_fileno(fd);
+ if ((uint) file < my_file_limit && my_file_info[file].type != UNOPEN)
+ {
+ name= my_file_info[file].name;
+ my_file_info[file].name= NULL;
+ my_file_info[file].type= UNOPEN;
+ }
#ifndef _WIN32
- err= fclose(fd);
+ do
+ {
+ err= fclose(fd);
+ } while (err == -1 && errno == EINTR);
#else
err= my_win_fclose(fd);
#endif
@@ -176,16 +183,15 @@ int my_fclose(FILE *fd, myf MyFlags)
my_errno=errno;
if (MyFlags & (MY_FAE | MY_WME))
my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG),
- my_filename(file),errno);
+ name,errno);
}
else
- my_stream_opened--;
- if ((uint) file < my_file_limit && my_file_info[file].type != UNOPEN)
+ statistic_decrement(my_stream_opened, &THR_LOCK_open);
+
+ if (name)
{
- my_file_info[file].type = UNOPEN;
- my_free(my_file_info[file].name);
+ my_free(name);
}
- mysql_mutex_unlock(&THR_LOCK_open);
DBUG_RETURN(err);
} /* my_fclose */
@@ -215,13 +221,12 @@ FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags)
}
else
{
- mysql_mutex_lock(&THR_LOCK_open);
- my_stream_opened++;
+ statistic_increment(my_stream_opened, &THR_LOCK_open);
if ((uint) Filedes < (uint) my_file_limit)
{
if (my_file_info[Filedes].type != UNOPEN)
{
- my_file_opened--; /* File is opened with my_open ! */
+ statistic_decrement(my_file_opened, &THR_LOCK_open); /* File is opened with my_open ! */
}
else
{
@@ -229,7 +234,6 @@ FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags)
}
my_file_info[Filedes].type = STREAM_BY_FDOPEN;
}
- mysql_mutex_unlock(&THR_LOCK_open);
}
DBUG_PRINT("exit",("stream: %p", fd));