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 |
#ifdef VMS
|
|
20 |
#include "hp_static.c" /* Stupid vms-linker */ |
|
21 |
#endif
|
|
22 |
||
23 |
#include "my_sys.h" |
|
24 |
||
25 |
/*
|
|
26 |
Open heap table based on HP_SHARE structure
|
|
27 |
|
|
28 |
NOTE
|
|
29 |
This doesn't register the table in the open table list.
|
|
30 |
*/
|
|
31 |
||
32 |
HP_INFO *heap_open_from_share(HP_SHARE *share, int mode) |
|
33 |
{
|
|
34 |
HP_INFO *info; |
|
35 |
DBUG_ENTER("heap_open_from_share"); |
|
36 |
||
37 |
if (!(info= (HP_INFO*) my_malloc((uint) sizeof(HP_INFO) + |
|
38 |
2 * share->max_key_length, |
|
39 |
MYF(MY_ZEROFILL)))) |
|
40 |
{
|
|
41 |
DBUG_RETURN(0); |
|
42 |
}
|
|
43 |
share->open_count++; |
|
44 |
#ifdef THREAD
|
|
45 |
thr_lock_data_init(&share->lock,&info->lock,NULL); |
|
46 |
#endif
|
|
47 |
info->s= share; |
|
48 |
info->lastkey= (uchar*) (info + 1); |
|
49 |
info->recbuf= (uchar*) (info->lastkey + share->max_key_length); |
|
50 |
info->mode= mode; |
|
51 |
info->current_record= (ulong) ~0L; /* No current record */ |
|
52 |
info->lastinx= info->errkey= -1; |
|
53 |
#ifndef DBUG_OFF
|
|
54 |
info->opt_flag= READ_CHECK_USED; /* Check when changing */ |
|
55 |
#endif
|
|
56 |
DBUG_PRINT("exit",("heap: 0x%lx reclength: %d records_in_block: %d", |
|
57 |
(long) info, share->reclength, |
|
58 |
share->block.records_in_block)); |
|
59 |
DBUG_RETURN(info); |
|
60 |
}
|
|
61 |
||
62 |
||
63 |
/*
|
|
64 |
Open heap table based on HP_SHARE structure and register it
|
|
65 |
*/
|
|
66 |
||
67 |
HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode) |
|
68 |
{
|
|
69 |
HP_INFO *info; |
|
70 |
DBUG_ENTER("heap_open_from_share_and_register"); |
|
71 |
||
72 |
pthread_mutex_lock(&THR_LOCK_heap); |
|
73 |
if ((info= heap_open_from_share(share, mode))) |
|
74 |
{
|
|
75 |
info->open_list.data= (void*) info; |
|
76 |
heap_open_list= list_add(heap_open_list,&info->open_list); |
|
77 |
}
|
|
78 |
pthread_mutex_unlock(&THR_LOCK_heap); |
|
79 |
DBUG_RETURN(info); |
|
80 |
}
|
|
81 |
||
82 |
||
83 |
/*
|
|
84 |
Open heap table based on name
|
|
85 |
||
86 |
NOTE
|
|
87 |
This register the table in the open table list. so that it can be
|
|
88 |
found by future heap_open() calls.
|
|
89 |
*/
|
|
90 |
||
91 |
HP_INFO *heap_open(const char *name, int mode) |
|
92 |
{
|
|
93 |
HP_INFO *info; |
|
94 |
HP_SHARE *share; |
|
95 |
DBUG_ENTER("heap_open"); |
|
96 |
||
97 |
pthread_mutex_lock(&THR_LOCK_heap); |
|
98 |
if (!(share= hp_find_named_heap(name))) |
|
99 |
{
|
|
100 |
my_errno= ENOENT; |
|
101 |
pthread_mutex_unlock(&THR_LOCK_heap); |
|
102 |
DBUG_RETURN(0); |
|
103 |
}
|
|
104 |
if ((info= heap_open_from_share(share, mode))) |
|
105 |
{
|
|
106 |
info->open_list.data= (void*) info; |
|
107 |
heap_open_list= list_add(heap_open_list,&info->open_list); |
|
108 |
}
|
|
109 |
pthread_mutex_unlock(&THR_LOCK_heap); |
|
110 |
DBUG_RETURN(info); |
|
111 |
}
|
|
112 |
||
113 |
||
114 |
/* map name to a heap-nr. If name isn't found return 0 */
|
|
115 |
||
116 |
HP_SHARE *hp_find_named_heap(const char *name) |
|
117 |
{
|
|
118 |
LIST *pos; |
|
119 |
HP_SHARE *info; |
|
120 |
DBUG_ENTER("heap_find"); |
|
121 |
DBUG_PRINT("enter",("name: %s",name)); |
|
122 |
||
123 |
for (pos= heap_share_list; pos; pos= pos->next) |
|
124 |
{
|
|
125 |
info= (HP_SHARE*) pos->data; |
|
126 |
if (!strcmp(name, info->name)) |
|
127 |
{
|
|
128 |
DBUG_PRINT("exit", ("Old heap_database: 0x%lx", (long) info)); |
|
129 |
DBUG_RETURN(info); |
|
130 |
}
|
|
131 |
}
|
|
132 |
DBUG_RETURN((HP_SHARE *) 0); |
|
133 |
}
|
|
134 |
||
135 |