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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 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 "myisamdef.h"
25
int mi_close(register MI_INFO *info)
23
#include "myisam_priv.h"
26
using namespace drizzled;
28
int mi_close(MI_INFO *info)
28
31
MYISAM_SHARE *share=info->s;
30
pthread_mutex_lock(&THR_LOCK_myisam);
33
THR_LOCK_myisam.lock();
31
34
if (info->lock_type == F_EXTRA_LCK)
32
35
info->lock_type=F_UNLCK; /* HA_EXTRA_NO_USER_CHANGE */
37
40
if (info->lock_type != F_UNLCK)
39
42
if (mi_lock_database(info,F_UNLCK))
42
pthread_mutex_lock(&share->intern_lock);
44
46
if (share->options & HA_OPTION_READ_ONLY_DATA)
49
51
if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
51
if (end_io_cache(&info->rec_cache))
53
if (info->rec_cache.end_io_cache())
53
55
info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
55
57
flag= !--share->reopen;
56
myisam_open_list=list_delete(myisam_open_list,&info->open_list);
57
pthread_mutex_unlock(&share->intern_lock);
58
myisam_open_list.remove(info);
59
my_free(mi_get_rec_buff_ptr(info, info->rec_buff), MYF(MY_ALLOW_ZERO_PTR));
60
void * rec_buff_ptr= mi_get_rec_buff_ptr(info, info->rec_buff);
61
if (rec_buff_ptr != NULL)
62
65
if (share->kfile >= 0 &&
63
flush_key_blocks(share->key_cache, share->kfile,
66
flush_key_blocks(share->getKeyCache(), share->kfile,
64
67
share->temporary ? FLUSH_IGNORE_CHANGED :
70
end_key_cache(share->getKeyCache(), true);
67
71
if (share->kfile >= 0)
75
79
if (share->mode != O_RDONLY && mi_is_crashed(info))
76
80
mi_state_info_write(share->kfile, &share->state, 1);
77
if (my_close(share->kfile,MYF(0)))
81
if (internal::my_close(share->kfile,MYF(0)))
80
84
if (share->decode_trees)
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));
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);
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));
92
THR_LOCK_myisam.unlock();
94
if (info->dfile >= 0 && internal::my_close(info->dfile,MYF(0)))
97
free((unsigned char*) info);
106
return(my_errno=error);