12
12
You should have received a copy of the GNU General Public License
13
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 */
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
16
/* open a heap-database */
18
#include "heap_priv.h"
20
20
#include <string.h>
23
26
Open heap table based on HP_SHARE structure
26
29
This doesn't register the table in the open table list.
29
32
HP_INFO *heap_open_from_share(HP_SHARE *share, int mode)
34
HP_INFO *info= new HP_INFO;
33
if (!(info= (HP_INFO*) my_malloc((uint) sizeof(HP_INFO) +
34
2 * share->max_key_length,
40
thr_lock_data_init(&share->lock,&info->lock,NULL);
42
info->lastkey= (unsigned char*) (info + 1);
43
info->recbuf= (unsigned char*) (info->lastkey + share->max_key_length);
37
info->setShare(share);
38
info->lastkey.resize(share->max_key_length);
45
40
info->current_record= UINT32_MAX; /* No current record */
46
41
info->lastinx= info->errkey= -1;
59
pthread_mutex_lock(&THR_LOCK_heap);
60
55
if ((info= heap_open_from_share(share, mode)))
62
info->open_list.data= (void*) info;
63
heap_open_list= list_add(heap_open_list,&info->open_list);
57
heap_open_list.push_front(info);
65
pthread_mutex_unlock(&THR_LOCK_heap);
59
THR_LOCK_heap.unlock();
83
pthread_mutex_lock(&THR_LOCK_heap);
84
78
if (!(share= hp_find_named_heap(name)))
87
pthread_mutex_unlock(&THR_LOCK_heap);
81
THR_LOCK_heap.unlock();
90
84
if ((info= heap_open_from_share(share, mode)))
92
info->open_list.data= (void*) info;
93
heap_open_list= list_add(heap_open_list,&info->open_list);
86
heap_open_list.push_front(info);
95
pthread_mutex_unlock(&THR_LOCK_heap);
88
THR_LOCK_heap.unlock();
102
95
HP_SHARE *hp_find_named_heap(const char *name)
107
for (pos= heap_share_list; pos; pos= pos->next)
97
list<HP_SHARE *>::iterator it= heap_share_list.begin();
98
while (it != heap_share_list.end())
109
info= (HP_SHARE*) pos->data;
110
if (!strcmp(name, info->name))
100
if (not (*it)->name.compare(name))
115
106
return((HP_SHARE *) 0);