diff options
Diffstat (limited to 'mysys/my_fopen.c')
-rw-r--r-- | mysys/my_fopen.c | 38 |
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)); |