~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_open.c

  • Committer: Monty Taylor
  • Date: 2009-03-03 07:39:39 UTC
  • mto: This revision was merged to the branch mainline in revision 910.
  • Revision ID: mordred@inaugust.com-20090303073939-rfswfdo68klfcp1o
Updated comment version indicators to handle drizzle versions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/* open a heap-database */
17
17
 
18
 
#include "heap_priv.h"
 
18
#include "heapdef.h"
19
19
 
20
20
#include <string.h>
21
 
#include <cstdlib>
22
 
 
23
 
using namespace std;
24
21
 
25
22
/*
26
23
  Open heap table based on HP_SHARE structure
31
28
 
32
29
HP_INFO *heap_open_from_share(HP_SHARE *share, int mode)
33
30
{
34
 
  HP_INFO *info= new HP_INFO;
 
31
  HP_INFO *info;
35
32
 
 
33
  if (!(info= (HP_INFO*) malloc(sizeof(HP_INFO) + 2 * share->max_key_length)))
 
34
  {
 
35
    return(0);
 
36
  }
 
37
  memset(info, 0, sizeof(HP_INFO) + 2 * share->max_key_length);
36
38
  share->open_count++;
37
 
  info->setShare(share);
38
 
  info->lastkey.resize(share->max_key_length);
 
39
  thr_lock_data_init(&share->lock,&info->lock,NULL);
 
40
  info->s= share;
 
41
  info->lastkey= (unsigned char*) (info + 1);
 
42
  info->recbuf= (unsigned char*) (info->lastkey + share->max_key_length);
39
43
  info->mode= mode;
40
44
  info->current_record= UINT32_MAX;             /* No current record */
41
45
  info->lastinx= info->errkey= -1;
42
 
  return info;
 
46
  return(info);
43
47
}
44
48
 
45
49
 
51
55
{
52
56
  HP_INFO *info;
53
57
 
54
 
  THR_LOCK_heap.lock();
 
58
  pthread_mutex_lock(&THR_LOCK_heap);
55
59
  if ((info= heap_open_from_share(share, mode)))
56
60
  {
57
 
    heap_open_list.push_front(info);
 
61
    info->open_list.data= (void*) info;
 
62
    heap_open_list= list_add(heap_open_list,&info->open_list);
58
63
  }
59
 
  THR_LOCK_heap.unlock();
 
64
  pthread_mutex_unlock(&THR_LOCK_heap);
60
65
  return(info);
61
66
}
62
67
 
74
79
  HP_INFO *info;
75
80
  HP_SHARE *share;
76
81
 
77
 
  THR_LOCK_heap.lock();
 
82
  pthread_mutex_lock(&THR_LOCK_heap);
78
83
  if (!(share= hp_find_named_heap(name)))
79
84
  {
80
 
    errno= ENOENT;
81
 
    THR_LOCK_heap.unlock();
 
85
    my_errno= ENOENT;
 
86
    pthread_mutex_unlock(&THR_LOCK_heap);
82
87
    return(0);
83
88
  }
84
89
  if ((info= heap_open_from_share(share, mode)))
85
90
  {
86
 
    heap_open_list.push_front(info);
 
91
    info->open_list.data= (void*) info;
 
92
    heap_open_list= list_add(heap_open_list,&info->open_list);
87
93
  }
88
 
  THR_LOCK_heap.unlock();
 
94
  pthread_mutex_unlock(&THR_LOCK_heap);
89
95
  return(info);
90
96
}
91
97
 
94
100
 
95
101
HP_SHARE *hp_find_named_heap(const char *name)
96
102
{
97
 
  list<HP_SHARE *>::iterator it= heap_share_list.begin();
98
 
  while (it != heap_share_list.end())
 
103
  LIST *pos;
 
104
  HP_SHARE *info;
 
105
 
 
106
  for (pos= heap_share_list; pos; pos= pos->next)
99
107
  {
100
 
    if (not (*it)->name.compare(name))
 
108
    info= (HP_SHARE*) pos->data;
 
109
    if (!strcmp(name, info->name))
101
110
    {
102
 
      return (*it);
 
111
      return(info);
103
112
    }
104
 
    ++it;
105
113
  }
106
114
  return((HP_SHARE *) 0);
107
115
}