Drizzled Public API Documentation

mi_close.cc
1 /* Copyright (C) 2000-2004 MySQL AB
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 /* close a isam-database */
17 /*
18  TODO:
19  We need to have a separate mutex on the closed file to allow other threads
20  to open other files during the time we flush the cache and close this file
21 */
22 
23 #include "myisam_priv.h"
24 #include <cstdlib>
25 
26 using namespace drizzled;
27 
28 int mi_close(MI_INFO *info)
29 {
30  int error=0,flag;
31  MYISAM_SHARE *share=info->s;
32 
33  THR_LOCK_myisam.lock();
34  if (info->lock_type == F_EXTRA_LCK)
35  info->lock_type=F_UNLCK; /* HA_EXTRA_NO_USER_CHANGE */
36 
37  if (share->reopen == 1 && share->kfile >= 0)
38  _mi_decrement_open_count(info);
39 
40  if (info->lock_type != F_UNLCK)
41  {
42  if (mi_lock_database(info,F_UNLCK))
43  error=errno;
44  }
45 
46  if (share->options & HA_OPTION_READ_ONLY_DATA)
47  {
48  share->r_locks--;
49  share->tot_locks--;
50  }
51  if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
52  {
53  if (info->rec_cache.end_io_cache())
54  error=errno;
55  info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
56  }
57  flag= !--share->reopen;
58  myisam_open_list.remove(info);
59 
60  void * rec_buff_ptr= mi_get_rec_buff_ptr(info, info->rec_buff);
61  free(rec_buff_ptr);
62  if (flag)
63  {
64  if (share->kfile >= 0)
65  {
66  /*
67  If we are crashed, we can safely flush the current state as it will
68  not change the crashed state.
69  We can NOT write the state in other cases as other threads
70  may be using the file at this point
71  */
72  if (share->mode != O_RDONLY && mi_is_crashed(info))
73  mi_state_info_write(share->kfile, &share->state, 1);
74  if (internal::my_close(share->kfile,MYF(0)))
75  error = errno;
76  }
77  if (share->decode_trees)
78  {
79  free((unsigned char*) share->decode_trees);
80  free((unsigned char*) share->decode_tables);
81  }
82  delete info->s->in_use;
83  free((unsigned char*) info->s);
84  }
85  THR_LOCK_myisam.unlock();
86 
87  if (info->dfile >= 0 && internal::my_close(info->dfile,MYF(0)))
88  error = errno;
89 
90  free((unsigned char*) info);
91 
92  if (error)
93  {
94  return(errno=error);
95  }
96  return(0);
97 } /* mi_close */
TODO: Rename this file - func.h is stupid.
int end_io_cache()
Free an io_cache_st object.
Definition: mf_iocache.cc:685