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 if (rec_buff_ptr != NULL)
00062 free(rec_buff_ptr);
00063 if (flag)
00064 {
00065 if (share->kfile >= 0 &&
00066 flush_key_blocks(share->getKeyCache(), share->kfile,
00067 share->temporary ? FLUSH_IGNORE_CHANGED :
00068 FLUSH_RELEASE))
00069 error=errno;
00070 end_key_cache(share->getKeyCache(), true);
00071 if (share->kfile >= 0)
00072 {
00073
00074
00075
00076
00077
00078
00079 if (share->mode != O_RDONLY && mi_is_crashed(info))
00080 mi_state_info_write(share->kfile, &share->state, 1);
00081 if (internal::my_close(share->kfile,MYF(0)))
00082 error = errno;
00083 }
00084 if (share->decode_trees)
00085 {
00086 free((unsigned char*) share->decode_trees);
00087 free((unsigned char*) share->decode_tables);
00088 }
00089 delete info->s->in_use;
00090 free((unsigned char*) info->s);
00091 }
00092 THR_LOCK_myisam.unlock();
00093
00094 if (info->dfile >= 0 && internal::my_close(info->dfile,MYF(0)))
00095 error = errno;
00096
00097 free((unsigned char*) info);
00098
00099 if (error)
00100 {
00101 return(errno=error);
00102 }
00103 return(0);
00104 }