~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_close.c

  • Committer: Monty Taylor
  • Date: 2009-03-08 23:45:12 UTC
  • mto: (923.2.1 mordred)
  • mto: This revision was merged to the branch mainline in revision 921.
  • Revision ID: mordred@inaugust.com-20090308234512-tqkygxtu1iaig23s
Removed C99 isnan() usage, which allows us to remove the util/math.{cc,h} workarounds. Yay for standards!

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
59
  void * rec_buff_ptr= mi_get_rec_buff_ptr(info, info->rec_buff);
61
60
  if (rec_buff_ptr != NULL)
63
62
  if (flag)
64
63
  {
65
64
    if (share->kfile >= 0 &&
66
 
        flush_key_blocks(share->getKeyCache(), share->kfile,
 
65
        flush_key_blocks(share->key_cache, share->kfile,
67
66
                         share->temporary ? FLUSH_IGNORE_CHANGED :
68
67
                         FLUSH_RELEASE))
69
 
      error=errno;
70
 
    end_key_cache(share->getKeyCache(), true);
 
68
      error=my_errno;
71
69
    if (share->kfile >= 0)
72
70
    {
73
71
      /*
78
76
      */
79
77
      if (share->mode != O_RDONLY && mi_is_crashed(info))
80
78
        mi_state_info_write(share->kfile, &share->state, 1);
81
 
      if (internal::my_close(share->kfile,MYF(0)))
82
 
        error = errno;
 
79
      if (my_close(share->kfile,MYF(0)))
 
80
        error = my_errno;
83
81
    }
84
82
    if (share->decode_trees)
85
83
    {
86
84
      free((unsigned char*) share->decode_trees);
87
85
      free((unsigned char*) share->decode_tables);
88
86
    }
89
 
    delete info->s->in_use;
 
87
    thr_lock_delete(&share->lock);
 
88
    pthread_mutex_destroy(&share->intern_lock);
 
89
    {
 
90
      int i,keys;
 
91
      keys = share->state.header.keys;
 
92
      pthread_rwlock_destroy(&share->mmap_lock);
 
93
      for(i=0; i<keys; i++) {
 
94
        pthread_rwlock_destroy(&share->key_root_lock[i]);
 
95
      }
 
96
    }
90
97
    free((unsigned char*) info->s);
91
98
  }
92
 
  THR_LOCK_myisam.unlock();
 
99
  pthread_mutex_unlock(&THR_LOCK_myisam);
93
100
 
94
 
  if (info->dfile >= 0 && internal::my_close(info->dfile,MYF(0)))
95
 
    error = errno;
 
101
  if (info->dfile >= 0 && my_close(info->dfile,MYF(0)))
 
102
    error = my_errno;
96
103
 
97
104
  free((unsigned char*) info);
98
105
 
99
106
  if (error)
100
107
  {
101
 
    return(errno=error);
 
108
    return(my_errno=error);
102
109
  }
103
110
  return(0);
104
111
} /* mi_close */