~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2004, 2006 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
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 */
15
16
/* open a heap-database */
17
18
#include "heapdef.h"
19
612.2.13 by Monty Taylor
Work on removing global.h from headers that should be installed.
20
#include <string.h>
1 by brian
clean slate
21
916.1.26 by Padraig O'Sullivan
Initial work on removing LIST from the heap storage engine.
22
using namespace std;
23
1 by brian
clean slate
24
/*
25
  Open heap table based on HP_SHARE structure
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
26
1 by brian
clean slate
27
  NOTE
28
    This doesn't register the table in the open table list.
29
*/
30
31
HP_INFO *heap_open_from_share(HP_SHARE *share, int mode)
32
{
33
  HP_INFO *info;
34
656.1.25 by Monty Taylor
Removed my_malloc stuff from storage/
35
  if (!(info= (HP_INFO*) malloc(sizeof(HP_INFO) + 2 * share->max_key_length)))
1 by brian
clean slate
36
  {
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
37
    return(0);
1 by brian
clean slate
38
  }
656.1.25 by Monty Taylor
Removed my_malloc stuff from storage/
39
  memset(info, 0, sizeof(HP_INFO) + 2 * share->max_key_length);
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
40
  share->open_count++;
1 by brian
clean slate
41
  thr_lock_data_init(&share->lock,&info->lock,NULL);
42
  info->s= share;
481 by Brian Aker
Remove all of uchar.
43
  info->lastkey= (unsigned char*) (info + 1);
44
  info->recbuf= (unsigned char*) (info->lastkey + share->max_key_length);
1 by brian
clean slate
45
  info->mode= mode;
365.2.8 by Monty Taylor
More MAX macros.
46
  info->current_record= UINT32_MAX;		/* No current record */
1 by brian
clean slate
47
  info->lastinx= info->errkey= -1;
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
48
  return(info);
1 by brian
clean slate
49
}
50
51
52
/*
53
  Open heap table based on HP_SHARE structure and register it
54
*/
55
56
HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode)
57
{
58
  HP_INFO *info;
59
60
  pthread_mutex_lock(&THR_LOCK_heap);
61
  if ((info= heap_open_from_share(share, mode)))
62
  {
916.1.26 by Padraig O'Sullivan
Initial work on removing LIST from the heap storage engine.
63
    heap_open_list.push_front(info);
1 by brian
clean slate
64
  }
65
  pthread_mutex_unlock(&THR_LOCK_heap);
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
66
  return(info);
1 by brian
clean slate
67
}
68
69
70
/*
71
  Open heap table based on name
72
73
  NOTE
74
    This register the table in the open table list. so that it can be
75
    found by future heap_open() calls.
76
*/
77
78
HP_INFO *heap_open(const char *name, int mode)
79
{
80
  HP_INFO *info;
81
  HP_SHARE *share;
82
83
  pthread_mutex_lock(&THR_LOCK_heap);
84
  if (!(share= hp_find_named_heap(name)))
85
  {
86
    my_errno= ENOENT;
87
    pthread_mutex_unlock(&THR_LOCK_heap);
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
88
    return(0);
1 by brian
clean slate
89
  }
90
  if ((info= heap_open_from_share(share, mode)))
91
  {
916.1.26 by Padraig O'Sullivan
Initial work on removing LIST from the heap storage engine.
92
    heap_open_list.push_front(info);
1 by brian
clean slate
93
  }
94
  pthread_mutex_unlock(&THR_LOCK_heap);
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
95
  return(info);
1 by brian
clean slate
96
}
97
98
99
/* map name to a heap-nr. If name isn't found return 0 */
100
101
HP_SHARE *hp_find_named_heap(const char *name)
102
{
916.1.26 by Padraig O'Sullivan
Initial work on removing LIST from the heap storage engine.
103
  list<HP_SHARE *>::iterator it= heap_share_list.begin();
104
  while (it != heap_share_list.end())
1 by brian
clean slate
105
  {
916.1.26 by Padraig O'Sullivan
Initial work on removing LIST from the heap storage engine.
106
    if (!strcmp(name, (*it)->name))
1 by brian
clean slate
107
    {
916.1.26 by Padraig O'Sullivan
Initial work on removing LIST from the heap storage engine.
108
      return (*it);
1 by brian
clean slate
109
    }
916.1.26 by Padraig O'Sullivan
Initial work on removing LIST from the heap storage engine.
110
    ++it;
1 by brian
clean slate
111
  }
51.3.1 by Jay Pipes
Removed all DBUG symbols from heap storage engine
112
  return((HP_SHARE *) 0);
1 by brian
clean slate
113
}
114
115