~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/mi_close.cc

  • Committer: Brian Aker
  • Date: 2010-12-18 18:24:57 UTC
  • mfrom: (1999.6.3 trunk)
  • Revision ID: brian@tangent.org-20101218182457-yi1wd0so2hml1k1w
Merge in Lee's copyright header fix

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
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 */
15
15
 
16
16
/* close a isam-database */
17
17
/*
20
20
   to open other files during the time we flush the cache and close this file
21
21
*/
22
22
 
23
 
#include "myisamdef.h"
24
 
 
25
 
int mi_close(register MI_INFO *info)
 
23
#include "myisam_priv.h"
 
24
#include <cstdlib>
 
25
 
 
26
using namespace drizzled;
 
27
 
 
28
int mi_close(MI_INFO *info)
26
29
{
27
30
  int error=0,flag;
28
31
  MYISAM_SHARE *share=info->s;
29
32
 
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 */
33
36
 
37
40
  if (info->lock_type != F_UNLCK)
38
41
  {
39
42
    if (mi_lock_database(info,F_UNLCK))
40
 
      error=my_errno;
 
43
      error=errno;
41
44
  }
42
 
  pthread_mutex_lock(&share->intern_lock);
43
45
 
44
46
  if (share->options & HA_OPTION_READ_ONLY_DATA)
45
47
  {
48
50
  }
49
51
  if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
50
52
  {
51
 
    if (end_io_cache(&info->rec_cache))
52
 
      error=my_errno;
 
53
    if (info->rec_cache.end_io_cache())
 
54
      error=errno;
53
55
    info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
54
56
  }
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);
58
59
 
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
    free(rec_buff_ptr);
60
63
  if (flag)
61
64
  {
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 :
65
68
                         FLUSH_RELEASE))
66
 
      error=my_errno;
 
69
      error=errno;
 
70
    end_key_cache(share->getKeyCache(), true);
67
71
    if (share->kfile >= 0)
68
72
    {
69
73
      /*
74
78
      */
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)))
78
 
        error = my_errno;
 
81
      if (internal::my_close(share->kfile,MYF(0)))
 
82
        error = errno;
79
83
    }
80
84
    if (share->decode_trees)
81
85
    {
82
 
      my_free((uchar*) share->decode_trees,MYF(0));
83
 
      my_free((uchar*) share->decode_tables,MYF(0));
84
 
    }
85
 
    thr_lock_delete(&share->lock);
86
 
    VOID(pthread_mutex_destroy(&share->intern_lock));
87
 
    {
88
 
      int i,keys;
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]));
93
 
      }
94
 
    }
95
 
    my_free((uchar*) info->s,MYF(0));
 
86
      free((unsigned char*) share->decode_trees);
 
87
      free((unsigned char*) share->decode_tables);
 
88
    }
 
89
    delete info->s->in_use;
 
90
    free((unsigned char*) info->s);
96
91
  }
97
 
  pthread_mutex_unlock(&THR_LOCK_myisam);
98
 
 
99
 
  if (info->dfile >= 0 && my_close(info->dfile,MYF(0)))
100
 
    error = my_errno;
101
 
 
102
 
  my_free((uchar*) info,MYF(0));
 
92
  THR_LOCK_myisam.unlock();
 
93
 
 
94
  if (info->dfile >= 0 && internal::my_close(info->dfile,MYF(0)))
 
95
    error = errno;
 
96
 
 
97
  free((unsigned char*) info);
103
98
 
104
99
  if (error)
105
100
  {
106
 
    return(my_errno=error);
 
101
    return(errno=error);
107
102
  }
108
103
  return(0);
109
104
} /* mi_close */