~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_panic.c

Removed/replaced DBUG symbols and TRUE/FALSE

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include "myisam_priv.h"
17
 
 
18
 
using namespace std;
19
 
using namespace drizzled;
 
16
#include "myisamdef.h"
20
17
 
21
18
        /* if flag == HA_PANIC_CLOSE then all misam files are closed */
22
19
        /* if flag == HA_PANIC_WRITE then all misam files are unlocked and
29
26
int mi_panic(enum ha_panic_function flag)
30
27
{
31
28
  int error=0;
 
29
  LIST *list_element,*next_open;
32
30
  MI_INFO *info;
 
31
  DBUG_ENTER("mi_panic");
33
32
 
34
 
  THR_LOCK_myisam.lock();
35
 
  list<MI_INFO *>::iterator it= myisam_open_list.begin();
36
 
  while (it != myisam_open_list.end())
 
33
  pthread_mutex_lock(&THR_LOCK_myisam);
 
34
  for (list_element=myisam_open_list ; list_element ; list_element=next_open)
37
35
  {
38
 
    info= *it;
 
36
    next_open=list_element->next;               /* Save if close */
 
37
    info=(MI_INFO*) list_element->data;
39
38
    switch (flag) {
40
39
    case HA_PANIC_CLOSE:
41
 
      THR_LOCK_myisam.unlock(); /* Not exactly right... */
 
40
      pthread_mutex_unlock(&THR_LOCK_myisam);   /* Not exactly right... */
42
41
      if (mi_close(info))
43
 
        error=errno;
44
 
      THR_LOCK_myisam.lock();
 
42
        error=my_errno;
 
43
      pthread_mutex_lock(&THR_LOCK_myisam);
45
44
      break;
46
45
    case HA_PANIC_WRITE:                /* Do this to free databases */
47
46
#ifdef CANT_OPEN_FILES_TWICE
48
47
      if (info->s->options & HA_OPTION_READ_ONLY_DATA)
49
48
        break;
50
49
#endif
51
 
      if (flush_key_blocks(info->s->getKeyCache(), info->s->kfile, FLUSH_RELEASE))
52
 
        error=errno;
 
50
      if (flush_key_blocks(info->s->key_cache, info->s->kfile, FLUSH_RELEASE))
 
51
        error=my_errno;
53
52
      if (info->opt_flag & WRITE_CACHE_USED)
54
53
        if (flush_io_cache(&info->rec_cache))
55
 
          error=errno;
 
54
          error=my_errno;
56
55
      if (info->opt_flag & READ_CACHE_USED)
57
56
      {
58
57
        if (flush_io_cache(&info->rec_cache))
59
 
          error=errno;
60
 
        reinit_io_cache(&info->rec_cache,internal::READ_CACHE,0,
61
 
                       (bool) (info->lock_type != F_UNLCK),1);
 
58
          error=my_errno;
 
59
        reinit_io_cache(&info->rec_cache,READ_CACHE,0,
 
60
                       (pbool) (info->lock_type != F_UNLCK),1);
62
61
      }
63
62
      if (info->lock_type != F_UNLCK && ! info->was_locked)
64
63
      {
65
64
        info->was_locked=info->lock_type;
66
65
        if (mi_lock_database(info,F_UNLCK))
67
 
          error=errno;
 
66
          error=my_errno;
68
67
      }
69
68
#ifdef CANT_OPEN_FILES_TWICE
70
 
      if (info->s->kfile >= 0 && internal::my_close(info->s->kfile,MYF(0)))
71
 
        error = errno;
72
 
      if (info->dfile >= 0 && internal::my_close(info->dfile,MYF(0)))
73
 
        error = errno;
 
69
      if (info->s->kfile >= 0 && my_close(info->s->kfile,MYF(0)))
 
70
        error = my_errno;
 
71
      if (info->dfile >= 0 && my_close(info->dfile,MYF(0)))
 
72
        error = my_errno;
74
73
      info->s->kfile=info->dfile= -1;   /* Files aren't open anymore */
75
74
      break;
76
75
#endif
79
78
      {                                 /* Open closed files */
80
79
        char name_buff[FN_REFLEN];
81
80
        if (info->s->kfile < 0)
82
 
          if ((info->s->kfile= internal::my_open(internal::fn_format(name_buff,info->filename,"",
 
81
          if ((info->s->kfile= my_open(fn_format(name_buff,info->filename,"",
83
82
                                              N_NAME_IEXT,4),info->mode,
84
83
                                    MYF(MY_WME))) < 0)
85
 
            error = errno;
 
84
            error = my_errno;
86
85
        if (info->dfile < 0)
87
86
        {
88
 
          if ((info->dfile= internal::my_open(internal::fn_format(name_buff,info->filename,"",
 
87
          if ((info->dfile= my_open(fn_format(name_buff,info->filename,"",
89
88
                                              N_NAME_DEXT,4),info->mode,
90
89
                                    MYF(MY_WME))) < 0)
91
 
            error = errno;
 
90
            error = my_errno;
92
91
          info->rec_cache.file=info->dfile;
93
92
        }
94
93
      }
96
95
      if (info->was_locked)
97
96
      {
98
97
        if (mi_lock_database(info, info->was_locked))
99
 
          error=errno;
 
98
          error=my_errno;
100
99
        info->was_locked=0;
101
100
      }
102
101
      break;
103
102
    }
104
 
    ++it;
105
 
  }
106
 
  THR_LOCK_myisam.unlock();
 
103
  }
 
104
  if (flag == HA_PANIC_CLOSE)
 
105
  {
 
106
    VOID(mi_log(0));                            /* Close log if neaded */
 
107
  }
 
108
  pthread_mutex_unlock(&THR_LOCK_myisam);
107
109
  if (!error)
108
 
    return(0);
109
 
  return(errno=error);
 
110
    DBUG_RETURN(0);
 
111
  DBUG_RETURN(my_errno=error);
110
112
} /* mi_panic */