~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_close.c

  • Committer: Monty Taylor
  • Date: 2008-09-16 00:00:48 UTC
  • mto: This revision was merged to the branch mainline in revision 391.
  • Revision ID: monty@inaugust.com-20080916000048-3rvrv3gv9l0ad3gs
Fixed copyright headers in drizzled/

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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 "myisam_priv.h"
24
 
#include <cstdlib>
25
 
 
26
 
using namespace drizzled;
27
 
 
28
 
int mi_close(MI_INFO *info)
 
23
#include "myisamdef.h"
 
24
 
 
25
int mi_close(register MI_INFO *info)
29
26
{
30
27
  int error=0,flag;
31
28
  MYISAM_SHARE *share=info->s;
32
29
 
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 */
36
33
 
40
37
  if (info->lock_type != F_UNLCK)
41
38
  {
42
39
    if (mi_lock_database(info,F_UNLCK))
43
 
      error=errno;
 
40
      error=my_errno;
44
41
  }
 
42
  pthread_mutex_lock(&share->intern_lock);
45
43
 
46
44
  if (share->options & HA_OPTION_READ_ONLY_DATA)
47
45
  {
50
48
  }
51
49
  if (info->opt_flag & (READ_CACHE_USED | WRITE_CACHE_USED))
52
50
  {
53
 
    if (info->rec_cache.end_io_cache())
54
 
      error=errno;
 
51
    if (end_io_cache(&info->rec_cache))
 
52
      error=my_errno;
55
53
    info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
56
54
  }
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);
59
58
 
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);
 
59
  my_free(mi_get_rec_buff_ptr(info, info->rec_buff), MYF(MY_ALLOW_ZERO_PTR));
63
60
  if (flag)
64
61
  {
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 :
68
65
                         FLUSH_RELEASE))
69
 
      error=errno;
70
 
    end_key_cache(share->getKeyCache(), true);
 
66
      error=my_errno;
71
67
    if (share->kfile >= 0)
72
68
    {
73
69
      /*
78
74
      */
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)))
82
 
        error = errno;
 
77
      if (my_close(share->kfile,MYF(0)))
 
78
        error = my_errno;
83
79
    }
84
80
    if (share->decode_trees)
85
81
    {
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);
 
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));
91
96
  }
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);
 
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));
98
103
 
99
104
  if (error)
100
105
  {
101
 
    return(errno=error);
 
106
    return(my_errno=error);
102
107
  }
103
108
  return(0);
104
109
} /* mi_close */