00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "myisam_priv.h"
00024 #include <cstdlib>
00025
00026 using namespace drizzled;
00027
00028 int mi_close(MI_INFO *info)
00029 {
00030 int error=0,flag;
00031 MYISAM_SHARE *share=info->s;
00032
00033 THR_LOCK_myisam.lock();
00034 if (info->lock_type == F_EXTRA_LCK)
00035 info->lock_type=F_UNLCK;
00036
00037 if (share->reopen == 1 && share->kfile >= 0)
00038 _mi_decrement_open_count(info);
00039
00040 if (info->lock_type != F_UNLCK)
00041 {
00042 if (mi_lock_database(info,F_UNLCK))
00043 error=errno;
00044 }
00045
00046 if (share->options & HA_OPTION_READ_ONLY_DATA)
00047 {
00048 share->r_locks--;
00049 share->tot_locks--;
00050 }
00051 if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
00052 {
00053 if (info->rec_cache.end_io_cache())
00054 error=errno;
00055 info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
00056 }
00057 flag= !--share->reopen;
00058 myisam_open_list.remove(info);
00059
00060 void * rec_buff_ptr= mi_get_rec_buff_ptr(info, info->rec_buff);
00061 free(rec_buff_ptr);
00062 if (flag)
00063 {
00064 if (share->kfile >= 0)
00065 {
00066
00067
00068
00069
00070
00071
00072 if (share->mode != O_RDONLY && mi_is_crashed(info))
00073 mi_state_info_write(share->kfile, &share->state, 1);
00074 if (internal::my_close(share->kfile,MYF(0)))
00075 error = errno;
00076 }
00077 if (share->decode_trees)
00078 {
00079 free((unsigned char*) share->decode_trees);
00080 free((unsigned char*) share->decode_tables);
00081 }
00082 delete info->s->in_use;
00083 free((unsigned char*) info->s);
00084 }
00085 THR_LOCK_myisam.unlock();
00086
00087 if (info->dfile >= 0 && internal::my_close(info->dfile,MYF(0)))
00088 error = errno;
00089
00090 free((unsigned char*) info);
00091
00092 if (error)
00093 {
00094 return(errno=error);
00095 }
00096 return(0);
00097 }