~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/heap/hp_open.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 "heap_priv.h"
19
 
 
20
 
#include <string.h>
21
 
#include <cstdlib>
22
 
 
23
 
using namespace std;
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*) malloc(sizeof(HP_INFO) + 2 * share->max_key_length)))
37
 
  {
38
 
    return(0);
39
 
  }
40
 
  memset(info, 0, sizeof(HP_INFO) + 2 * share->max_key_length);
41
 
  share->open_count++;
42
 
  thr_lock_data_init(&share->lock,&info->lock,NULL);
43
 
  info->s= share;
44
 
  info->lastkey= (unsigned char*) (info + 1);
45
 
  info->recbuf= (unsigned char*) (info->lastkey + share->max_key_length);
46
 
  info->mode= mode;
47
 
  info->current_record= UINT32_MAX;             /* No current record */
48
 
  info->lastinx= info->errkey= -1;
49
 
  return(info);
50
 
}
51
 
 
52
 
 
53
 
/*
54
 
  Open heap table based on HP_SHARE structure and register it
55
 
*/
56
 
 
57
 
HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode)
58
 
{
59
 
  HP_INFO *info;
60
 
 
61
 
  pthread_mutex_lock(&THR_LOCK_heap);
62
 
  if ((info= heap_open_from_share(share, mode)))
63
 
  {
64
 
    heap_open_list.push_front(info);
65
 
  }
66
 
  pthread_mutex_unlock(&THR_LOCK_heap);
67
 
  return(info);
68
 
}
69
 
 
70
 
 
71
 
/*
72
 
  Open heap table based on name
73
 
 
74
 
  NOTE
75
 
    This register the table in the open table list. so that it can be
76
 
    found by future heap_open() calls.
77
 
*/
78
 
 
79
 
HP_INFO *heap_open(const char *name, int mode)
80
 
{
81
 
  HP_INFO *info;
82
 
  HP_SHARE *share;
83
 
 
84
 
  pthread_mutex_lock(&THR_LOCK_heap);
85
 
  if (!(share= hp_find_named_heap(name)))
86
 
  {
87
 
    errno= ENOENT;
88
 
    pthread_mutex_unlock(&THR_LOCK_heap);
89
 
    return(0);
90
 
  }
91
 
  if ((info= heap_open_from_share(share, mode)))
92
 
  {
93
 
    heap_open_list.push_front(info);
94
 
  }
95
 
  pthread_mutex_unlock(&THR_LOCK_heap);
96
 
  return(info);
97
 
}
98
 
 
99
 
 
100
 
/* map name to a heap-nr. If name isn't found return 0 */
101
 
 
102
 
HP_SHARE *hp_find_named_heap(const char *name)
103
 
{
104
 
  list<HP_SHARE *>::iterator it= heap_share_list.begin();
105
 
  while (it != heap_share_list.end())
106
 
  {
107
 
    if (!strcmp(name, (*it)->name))
108
 
    {
109
 
      return (*it);
110
 
    }
111
 
    ++it;
112
 
  }
113
 
  return((HP_SHARE *) 0);
114
 
}
115
 
 
116