~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_open.cc

  • Committer: Brian Aker
  • Date: 2009-05-23 16:15:00 UTC
  • mto: This revision was merged to the branch mainline in revision 1038.
  • Revision ID: brian@gaz-20090523161500-nldnoav8b7x1iz1b
Remove locks around my_open(). Open file counts are now "best effort" (not
that they were ever exact, since Innodb didn't use the calls).

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
  fd = open((char *) FileName, Flags);
48
48
#endif
49
49
 
50
 
  return(my_register_filename(fd, FileName, FILE_BY_OPEN,
51
 
                                   EE_FILENOTFOUND, MyFlags));
 
50
  return(my_register_filename(fd, FileName, EE_FILENOTFOUND, MyFlags));
52
51
} /* my_open */
53
52
 
54
53
 
66
65
{
67
66
  int err;
68
67
 
69
 
  pthread_mutex_lock(&THR_LOCK_open);
70
68
  do
71
69
  {
72
70
    err= close(fd);
76
74
  {
77
75
    my_errno=errno;
78
76
    if (MyFlags & (MY_FAE | MY_WME))
79
 
      my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG),my_filename(fd),errno);
80
 
  }
81
 
  if ((uint32_t) fd < my_file_limit && my_file_info[fd].type != UNOPEN)
82
 
  {
83
 
    free(my_file_info[fd].name);
84
 
#if !defined(HAVE_PREAD)
85
 
    pthread_mutex_destroy(&my_file_info[fd].mutex);
86
 
#endif
87
 
    my_file_info[fd].type = UNOPEN;
 
77
      my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG), "unknown", errno);
88
78
  }
89
79
  my_file_opened--;
90
 
  pthread_mutex_unlock(&THR_LOCK_open);
 
80
 
91
81
  return(err);
92
82
} /* my_close */
93
83
 
94
84
 
95
85
/*
96
 
  Register file in my_file_info[]
 
86
  TODO: Get rid of
97
87
 
98
88
  SYNOPSIS
99
89
    my_register_filename()
109
99
 
110
100
*/
111
101
 
112
 
File my_register_filename(File fd, const char *FileName, enum file_type
113
 
                          type_of_file, uint32_t error_message_number, myf MyFlags)
 
102
File my_register_filename(File fd, const char *FileName, uint32_t error_message_number, myf MyFlags)
114
103
{
115
104
  if ((int) fd >= 0)
116
105
  {
117
 
    if ((uint32_t) fd >= my_file_limit)
118
 
    {
119
 
#if !defined(HAVE_PREAD)
120
 
      my_errno= EMFILE;
121
 
#else
122
 
      thread_safe_increment(my_file_opened,&THR_LOCK_open);
123
 
      return(fd);                               /* safeguard */
124
 
#endif
125
 
    }
126
 
    else
127
 
    {
128
 
      pthread_mutex_lock(&THR_LOCK_open);
129
 
      if ((my_file_info[fd].name = (char*) strdup(FileName)))
130
 
      {
131
 
        my_file_opened++;
132
 
        my_file_total_opened++;
133
 
        my_file_info[fd].type = type_of_file;
134
 
#if !defined(HAVE_PREAD)
135
 
        pthread_mutex_init(&my_file_info[fd].mutex,MY_MUTEX_INIT_FAST);
136
 
#endif
137
 
        pthread_mutex_unlock(&THR_LOCK_open);
138
 
        return(fd);
139
 
      }
140
 
      pthread_mutex_unlock(&THR_LOCK_open);
141
 
      my_errno= ENOMEM;
142
 
    }
143
 
    (void) my_close(fd, MyFlags);
 
106
    my_file_opened++;
 
107
    my_file_total_opened++;
 
108
 
 
109
    return fd;
144
110
  }
145
111
  else
146
112
    my_errno= errno;
152
118
    my_error(error_message_number, MYF(ME_BELL+ME_WAITTANG),
153
119
             FileName, my_errno);
154
120
  }
155
 
  return(-1);
156
 
}
157
 
 
158
 
 
159
 
#ifdef EXTRA_DEBUG
160
 
 
161
 
void my_print_open_files(void)
162
 
{
163
 
  if (my_file_opened | my_stream_opened)
164
 
  {
165
 
    uint32_t i;
166
 
    for (i= 0 ; i < my_file_limit ; i++)
167
 
    {
168
 
      if (my_file_info[i].type != UNOPEN)
169
 
      {
170
 
        fprintf(stderr, EE(EE_FILE_NOT_CLOSED), my_file_info[i].name, i);
171
 
        fputc('\n', stderr);
172
 
      }
173
 
    }
174
 
  }
175
 
}
176
 
 
177
 
#endif
 
121
  return -1;
 
122
}