12
12
You should have received a copy of the GNU General Public License
13
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 */
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
16
/* close a isam-database */
20
20
to open other files during the time we flush the cache and close this file
23
#include "myisam_priv.h"
26
using namespace drizzled;
28
int mi_close(MI_INFO *info)
23
#include "myisamdef.h"
25
int mi_close(register MI_INFO *info)
31
28
MYISAM_SHARE *share=info->s;
33
THR_LOCK_myisam.lock();
30
pthread_mutex_lock(&THR_LOCK_myisam);
34
31
if (info->lock_type == F_EXTRA_LCK)
35
32
info->lock_type=F_UNLCK; /* HA_EXTRA_NO_USER_CHANGE */
40
37
if (info->lock_type != F_UNLCK)
42
39
if (mi_lock_database(info,F_UNLCK))
42
pthread_mutex_lock(&share->intern_lock);
46
44
if (share->options & HA_OPTION_READ_ONLY_DATA)
51
49
if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
53
if (info->rec_cache.end_io_cache())
51
if (end_io_cache(&info->rec_cache))
55
53
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
57
55
flag= !--share->reopen;
58
myisam_open_list.remove(info);
56
myisam_open_list=list_delete(myisam_open_list,&info->open_list);
57
pthread_mutex_unlock(&share->intern_lock);
60
void * rec_buff_ptr= mi_get_rec_buff_ptr(info, info->rec_buff);
61
if (rec_buff_ptr != NULL)
59
my_free(mi_get_rec_buff_ptr(info, info->rec_buff), MYF(MY_ALLOW_ZERO_PTR));
65
62
if (share->kfile >= 0 &&
66
flush_key_blocks(share->getKeyCache(), share->kfile,
63
flush_key_blocks(share->key_cache, share->kfile,
67
64
share->temporary ? FLUSH_IGNORE_CHANGED :
70
end_key_cache(share->getKeyCache(), true);
71
67
if (share->kfile >= 0)
79
75
if (share->mode != O_RDONLY && mi_is_crashed(info))
80
76
mi_state_info_write(share->kfile, &share->state, 1);
81
if (internal::my_close(share->kfile,MYF(0)))
77
if (my_close(share->kfile,MYF(0)))
84
80
if (share->decode_trees)
86
free((unsigned char*) share->decode_trees);
87
free((unsigned char*) share->decode_tables);
89
delete info->s->in_use;
90
free((unsigned char*) info->s);
82
my_free((uchar*) share->decode_trees,MYF(0));
83
my_free((uchar*) share->decode_tables,MYF(0));
85
thr_lock_delete(&share->lock);
86
VOID(pthread_mutex_destroy(&share->intern_lock));
89
keys = share->state.header.keys;
90
VOID(rwlock_destroy(&share->mmap_lock));
91
for(i=0; i<keys; i++) {
92
VOID(rwlock_destroy(&share->key_root_lock[i]));
95
my_free((uchar*) info->s,MYF(0));
92
THR_LOCK_myisam.unlock();
94
if (info->dfile >= 0 && internal::my_close(info->dfile,MYF(0)))
97
free((unsigned char*) info);
97
pthread_mutex_unlock(&THR_LOCK_myisam);
99
if (info->dfile >= 0 && my_close(info->dfile,MYF(0)))
102
my_free((uchar*) info,MYF(0));
106
return(my_errno=error);