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 */
18
#include "heap_priv.h"
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)
36
if (!(info= (HP_INFO*) malloc(sizeof(HP_INFO) + 2 * share->max_key_length)))
40
memset(info, 0, sizeof(HP_INFO) + 2 * share->max_key_length);
42
thr_lock_data_init(&share->lock,&info->lock,NULL);
44
info->lastkey= (unsigned char*) (info + 1);
45
info->recbuf= (unsigned char*) (info->lastkey + share->max_key_length);
47
info->current_record= UINT32_MAX; /* No current record */
48
info->lastinx= info->errkey= -1;
54
Open heap table based on HP_SHARE structure and register it
57
HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode)
61
pthread_mutex_lock(&THR_LOCK_heap);
62
if ((info= heap_open_from_share(share, mode)))
64
heap_open_list.push_front(info);
66
pthread_mutex_unlock(&THR_LOCK_heap);
72
Open heap table based on name
75
This register the table in the open table list. so that it can be
76
found by future heap_open() calls.
79
HP_INFO *heap_open(const char *name, int mode)
84
pthread_mutex_lock(&THR_LOCK_heap);
85
if (!(share= hp_find_named_heap(name)))
88
pthread_mutex_unlock(&THR_LOCK_heap);
91
if ((info= heap_open_from_share(share, mode)))
93
heap_open_list.push_front(info);
95
pthread_mutex_unlock(&THR_LOCK_heap);
100
/* map name to a heap-nr. If name isn't found return 0 */
102
HP_SHARE *hp_find_named_heap(const char *name)
104
list<HP_SHARE *>::iterator it= heap_share_list.begin();
105
while (it != heap_share_list.end())
107
if (!strcmp(name, (*it)->name))
113
return((HP_SHARE *) 0);