1
/* Copyright (C) 2000-2004, 2006 MySQL AB
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.
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.
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 */
16
/* open a heap-database */
20
#include "hp_static.c" /* Stupid vms-linker */
26
Open heap table based on HP_SHARE structure
29
This doesn't register the table in the open table list.
32
HP_INFO *heap_open_from_share(HP_SHARE *share, int mode)
35
DBUG_ENTER("heap_open_from_share");
37
if (!(info= (HP_INFO*) my_malloc((uint) sizeof(HP_INFO) +
38
2 * share->max_key_length,
45
thr_lock_data_init(&share->lock,&info->lock,NULL);
48
info->lastkey= (uchar*) (info + 1);
49
info->recbuf= (uchar*) (info->lastkey + share->max_key_length);
51
info->current_record= (ulong) ~0L; /* No current record */
52
info->lastinx= info->errkey= -1;
54
info->opt_flag= READ_CHECK_USED; /* Check when changing */
56
DBUG_PRINT("exit",("heap: 0x%lx reclength: %d records_in_block: %d",
57
(long) info, share->reclength,
58
share->block.records_in_block));
64
Open heap table based on HP_SHARE structure and register it
67
HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode)
70
DBUG_ENTER("heap_open_from_share_and_register");
72
pthread_mutex_lock(&THR_LOCK_heap);
73
if ((info= heap_open_from_share(share, mode)))
75
info->open_list.data= (void*) info;
76
heap_open_list= list_add(heap_open_list,&info->open_list);
78
pthread_mutex_unlock(&THR_LOCK_heap);
84
Open heap table based on name
87
This register the table in the open table list. so that it can be
88
found by future heap_open() calls.
91
HP_INFO *heap_open(const char *name, int mode)
95
DBUG_ENTER("heap_open");
97
pthread_mutex_lock(&THR_LOCK_heap);
98
if (!(share= hp_find_named_heap(name)))
101
pthread_mutex_unlock(&THR_LOCK_heap);
104
if ((info= heap_open_from_share(share, mode)))
106
info->open_list.data= (void*) info;
107
heap_open_list= list_add(heap_open_list,&info->open_list);
109
pthread_mutex_unlock(&THR_LOCK_heap);
114
/* map name to a heap-nr. If name isn't found return 0 */
116
HP_SHARE *hp_find_named_heap(const char *name)
120
DBUG_ENTER("heap_find");
121
DBUG_PRINT("enter",("name: %s",name));
123
for (pos= heap_share_list; pos; pos= pos->next)
125
info= (HP_SHARE*) pos->data;
126
if (!strcmp(name, info->name))
128
DBUG_PRINT("exit", ("Old heap_database: 0x%lx", (long) info));
132
DBUG_RETURN((HP_SHARE *) 0);