~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/heap/hp_open.cc

  • Committer: Brian Aker
  • Date: 2010-02-07 01:33:54 UTC
  • Revision ID: brian@gaz-20100207013354-d2pg1n68u5c09pgo
Remove giant include header to its own file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* open a heap-database */
17
17
 
18
 
#include "heapdef.h"
19
 
#ifdef VMS
20
 
#include "hp_static.c"                  /* Stupid vms-linker */
21
 
#endif
22
 
 
23
 
#include <mysys/my_sys.h>
 
18
#include "heap_priv.h"
 
19
 
 
20
#include <string.h>
 
21
#include <cstdlib>
 
22
 
 
23
using namespace std;
24
24
 
25
25
/*
26
26
  Open heap table based on HP_SHARE structure
27
 
  
 
27
 
28
28
  NOTE
29
29
    This doesn't register the table in the open table list.
30
30
*/
33
33
{
34
34
  HP_INFO *info;
35
35
 
36
 
  if (!(info= (HP_INFO*) my_malloc((uint) sizeof(HP_INFO) +
37
 
                                  2 * share->max_key_length,
38
 
                                  MYF(MY_ZEROFILL))))
 
36
  if (!(info= (HP_INFO*) malloc(sizeof(HP_INFO) + 2 * share->max_key_length)))
39
37
  {
40
38
    return(0);
41
39
  }
42
 
  share->open_count++; 
 
40
  memset(info, 0, sizeof(HP_INFO) + 2 * share->max_key_length);
 
41
  share->open_count++;
43
42
  thr_lock_data_init(&share->lock,&info->lock,NULL);
44
43
  info->s= share;
45
 
  info->lastkey= (uchar*) (info + 1);
46
 
  info->recbuf= (uchar*) (info->lastkey + share->max_key_length);
 
44
  info->lastkey= (unsigned char*) (info + 1);
 
45
  info->recbuf= (unsigned char*) (info->lastkey + share->max_key_length);
47
46
  info->mode= mode;
48
 
  info->current_record= (uint32_t) ~0L;         /* No current record */
 
47
  info->current_record= UINT32_MAX;             /* No current record */
49
48
  info->lastinx= info->errkey= -1;
50
49
  return(info);
51
50
}
62
61
  pthread_mutex_lock(&THR_LOCK_heap);
63
62
  if ((info= heap_open_from_share(share, mode)))
64
63
  {
65
 
    info->open_list.data= (void*) info;
66
 
    heap_open_list= list_add(heap_open_list,&info->open_list);
 
64
    heap_open_list.push_front(info);
67
65
  }
68
66
  pthread_mutex_unlock(&THR_LOCK_heap);
69
67
  return(info);
86
84
  pthread_mutex_lock(&THR_LOCK_heap);
87
85
  if (!(share= hp_find_named_heap(name)))
88
86
  {
89
 
    my_errno= ENOENT;
 
87
    errno= ENOENT;
90
88
    pthread_mutex_unlock(&THR_LOCK_heap);
91
89
    return(0);
92
90
  }
93
91
  if ((info= heap_open_from_share(share, mode)))
94
92
  {
95
 
    info->open_list.data= (void*) info;
96
 
    heap_open_list= list_add(heap_open_list,&info->open_list);
 
93
    heap_open_list.push_front(info);
97
94
  }
98
95
  pthread_mutex_unlock(&THR_LOCK_heap);
99
96
  return(info);
104
101
 
105
102
HP_SHARE *hp_find_named_heap(const char *name)
106
103
{
107
 
  LIST *pos;
108
 
  HP_SHARE *info;
109
 
 
110
 
  for (pos= heap_share_list; pos; pos= pos->next)
 
104
  list<HP_SHARE *>::iterator it= heap_share_list.begin();
 
105
  while (it != heap_share_list.end())
111
106
  {
112
 
    info= (HP_SHARE*) pos->data;
113
 
    if (!strcmp(name, info->name))
 
107
    if (!strcmp(name, (*it)->name))
114
108
    {
115
 
      return(info);
 
109
      return (*it);
116
110
    }
 
111
    ++it;
117
112
  }
118
113
  return((HP_SHARE *) 0);
119
114
}