~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/memory/hp_open.cc

  • Committer: Daniel Nichter
  • Date: 2011-10-23 16:01:37 UTC
  • mto: This revision was merged to the branch mainline in revision 2448.
  • Revision ID: daniel@percona.com-20111023160137-7ac3blgz8z4tf8za
Add Administration Getting Started and Logging.  Capitalize SQL clause keywords.

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
/* open a heap-database */
17
17
 
18
 
#include "heapdef.h"
 
18
#include "heap_priv.h"
19
19
 
20
20
#include <string.h>
 
21
#include <cstdlib>
 
22
 
 
23
using namespace std;
21
24
 
22
25
/*
23
26
  Open heap table based on HP_SHARE structure
24
 
  
 
27
 
25
28
  NOTE
26
29
    This doesn't register the table in the open table list.
27
30
*/
28
31
 
29
32
HP_INFO *heap_open_from_share(HP_SHARE *share, int mode)
30
33
{
31
 
  HP_INFO *info;
 
34
  HP_INFO *info= new HP_INFO;
32
35
 
33
 
  if (!(info= (HP_INFO*) my_malloc((uint) sizeof(HP_INFO) +
34
 
                                  2 * share->max_key_length,
35
 
                                  MYF(MY_ZEROFILL))))
36
 
  {
37
 
    return(0);
38
 
  }
39
 
  share->open_count++; 
40
 
  thr_lock_data_init(&share->lock,&info->lock,NULL);
41
 
  info->s= share;
42
 
  info->lastkey= (unsigned char*) (info + 1);
43
 
  info->recbuf= (unsigned char*) (info->lastkey + share->max_key_length);
 
36
  share->open_count++;
 
37
  info->setShare(share);
 
38
  info->lastkey.resize(share->max_key_length);
44
39
  info->mode= mode;
45
40
  info->current_record= UINT32_MAX;             /* No current record */
46
41
  info->lastinx= info->errkey= -1;
47
 
  return(info);
 
42
  return info;
48
43
}
49
44
 
50
45
 
56
51
{
57
52
  HP_INFO *info;
58
53
 
59
 
  pthread_mutex_lock(&THR_LOCK_heap);
 
54
  THR_LOCK_heap.lock();
60
55
  if ((info= heap_open_from_share(share, mode)))
61
56
  {
62
 
    info->open_list.data= (void*) info;
63
 
    heap_open_list= list_add(heap_open_list,&info->open_list);
 
57
    heap_open_list.push_front(info);
64
58
  }
65
 
  pthread_mutex_unlock(&THR_LOCK_heap);
 
59
  THR_LOCK_heap.unlock();
66
60
  return(info);
67
61
}
68
62
 
80
74
  HP_INFO *info;
81
75
  HP_SHARE *share;
82
76
 
83
 
  pthread_mutex_lock(&THR_LOCK_heap);
 
77
  THR_LOCK_heap.lock();
84
78
  if (!(share= hp_find_named_heap(name)))
85
79
  {
86
 
    my_errno= ENOENT;
87
 
    pthread_mutex_unlock(&THR_LOCK_heap);
 
80
    errno= ENOENT;
 
81
    THR_LOCK_heap.unlock();
88
82
    return(0);
89
83
  }
90
84
  if ((info= heap_open_from_share(share, mode)))
91
85
  {
92
 
    info->open_list.data= (void*) info;
93
 
    heap_open_list= list_add(heap_open_list,&info->open_list);
 
86
    heap_open_list.push_front(info);
94
87
  }
95
 
  pthread_mutex_unlock(&THR_LOCK_heap);
 
88
  THR_LOCK_heap.unlock();
96
89
  return(info);
97
90
}
98
91
 
101
94
 
102
95
HP_SHARE *hp_find_named_heap(const char *name)
103
96
{
104
 
  LIST *pos;
105
 
  HP_SHARE *info;
106
 
 
107
 
  for (pos= heap_share_list; pos; pos= pos->next)
 
97
  list<HP_SHARE *>::iterator it= heap_share_list.begin();
 
98
  while (it != heap_share_list.end())
108
99
  {
109
 
    info= (HP_SHARE*) pos->data;
110
 
    if (!strcmp(name, info->name))
 
100
    if (not (*it)->name.compare(name))
111
101
    {
112
 
      return(info);
 
102
      return (*it);
113
103
    }
 
104
    ++it;
114
105
  }
115
106
  return((HP_SHARE *) 0);
116
107
}