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 |
||
212.5.13
by Monty Taylor
Moved my_sys/my_pthread/my_nosys and mysys_err to mysys. |
23 |
#include <mysys/my_sys.h> |
1
by brian
clean slate |
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 |
||
36 |
if (!(info= (HP_INFO*) my_malloc((uint) sizeof(HP_INFO) + |
|
37 |
2 * share->max_key_length, |
|
38 |
MYF(MY_ZEROFILL)))) |
|
39 |
{
|
|
51.3.1
by Jay Pipes
Removed all DBUG symbols from heap storage engine |
40 |
return(0); |
1
by brian
clean slate |
41 |
}
|
42 |
share->open_count++; |
|
43 |
thr_lock_data_init(&share->lock,&info->lock,NULL); |
|
44 |
info->s= share; |
|
45 |
info->lastkey= (uchar*) (info + 1); |
|
46 |
info->recbuf= (uchar*) (info->lastkey + share->max_key_length); |
|
47 |
info->mode= mode; |
|
48 |
info->current_record= (ulong) ~0L; /* No current record */ |
|
49 |
info->lastinx= info->errkey= -1; |
|
51.3.1
by Jay Pipes
Removed all DBUG symbols from heap storage engine |
50 |
return(info); |
1
by brian
clean slate |
51 |
}
|
52 |
||
53 |
||
54 |
/*
|
|
55 |
Open heap table based on HP_SHARE structure and register it
|
|
56 |
*/
|
|
57 |
||
58 |
HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode) |
|
59 |
{
|
|
60 |
HP_INFO *info; |
|
61 |
||
62 |
pthread_mutex_lock(&THR_LOCK_heap); |
|
63 |
if ((info= heap_open_from_share(share, mode))) |
|
64 |
{
|
|
65 |
info->open_list.data= (void*) info; |
|
66 |
heap_open_list= list_add(heap_open_list,&info->open_list); |
|
67 |
}
|
|
68 |
pthread_mutex_unlock(&THR_LOCK_heap); |
|
51.3.1
by Jay Pipes
Removed all DBUG symbols from heap storage engine |
69 |
return(info); |
1
by brian
clean slate |
70 |
}
|
71 |
||
72 |
||
73 |
/*
|
|
74 |
Open heap table based on name
|
|
75 |
||
76 |
NOTE
|
|
77 |
This register the table in the open table list. so that it can be
|
|
78 |
found by future heap_open() calls.
|
|
79 |
*/
|
|
80 |
||
81 |
HP_INFO *heap_open(const char *name, int mode) |
|
82 |
{
|
|
83 |
HP_INFO *info; |
|
84 |
HP_SHARE *share; |
|
85 |
||
86 |
pthread_mutex_lock(&THR_LOCK_heap); |
|
87 |
if (!(share= hp_find_named_heap(name))) |
|
88 |
{
|
|
89 |
my_errno= ENOENT; |
|
90 |
pthread_mutex_unlock(&THR_LOCK_heap); |
|
51.3.1
by Jay Pipes
Removed all DBUG symbols from heap storage engine |
91 |
return(0); |
1
by brian
clean slate |
92 |
}
|
93 |
if ((info= heap_open_from_share(share, mode))) |
|
94 |
{
|
|
95 |
info->open_list.data= (void*) info; |
|
96 |
heap_open_list= list_add(heap_open_list,&info->open_list); |
|
97 |
}
|
|
98 |
pthread_mutex_unlock(&THR_LOCK_heap); |
|
51.3.1
by Jay Pipes
Removed all DBUG symbols from heap storage engine |
99 |
return(info); |
1
by brian
clean slate |
100 |
}
|
101 |
||
102 |
||
103 |
/* map name to a heap-nr. If name isn't found return 0 */
|
|
104 |
||
105 |
HP_SHARE *hp_find_named_heap(const char *name) |
|
106 |
{
|
|
107 |
LIST *pos; |
|
108 |
HP_SHARE *info; |
|
109 |
||
110 |
for (pos= heap_share_list; pos; pos= pos->next) |
|
111 |
{
|
|
112 |
info= (HP_SHARE*) pos->data; |
|
113 |
if (!strcmp(name, info->name)) |
|
114 |
{
|
|
51.3.1
by Jay Pipes
Removed all DBUG symbols from heap storage engine |
115 |
return(info); |
1
by brian
clean slate |
116 |
}
|
117 |
}
|
|
51.3.1
by Jay Pipes
Removed all DBUG symbols from heap storage engine |
118 |
return((HP_SHARE *) 0); |
1
by brian
clean slate |
119 |
}
|
120 |
||
121 |