~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/hp_open.c

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* open a heap-database */
17
17
 
18
 
#include "heap_priv.h"
19
 
 
20
 
#include <string.h>
21
 
#include <cstdlib>
22
 
 
23
 
using namespace std;
 
18
#include "heapdef.h"
 
19
#ifdef VMS
 
20
#include "hp_static.c"                  /* Stupid vms-linker */
 
21
#endif
 
22
 
 
23
#include "my_sys.h"
24
24
 
25
25
/*
26
26
  Open heap table based on HP_SHARE structure
27
 
 
 
27
  
28
28
  NOTE
29
29
    This doesn't register the table in the open table list.
30
30
*/
32
32
HP_INFO *heap_open_from_share(HP_SHARE *share, int mode)
33
33
{
34
34
  HP_INFO *info;
 
35
  DBUG_ENTER("heap_open_from_share");
35
36
 
36
 
  if (!(info= (HP_INFO*) malloc(sizeof(HP_INFO) + 2 * share->max_key_length)))
 
37
  if (!(info= (HP_INFO*) my_malloc((uint) sizeof(HP_INFO) +
 
38
                                  2 * share->max_key_length,
 
39
                                  MYF(MY_ZEROFILL))))
37
40
  {
38
 
    return(0);
 
41
    DBUG_RETURN(0);
39
42
  }
40
 
  memset(info, 0, sizeof(HP_INFO) + 2 * share->max_key_length);
41
 
  share->open_count++;
 
43
  share->open_count++; 
 
44
#ifdef THREAD
42
45
  thr_lock_data_init(&share->lock,&info->lock,NULL);
 
46
#endif
43
47
  info->s= share;
44
 
  info->lastkey= (unsigned char*) (info + 1);
45
 
  info->recbuf= (unsigned char*) (info->lastkey + share->max_key_length);
 
48
  info->lastkey= (uchar*) (info + 1);
 
49
  info->recbuf= (uchar*) (info->lastkey + share->max_key_length);
46
50
  info->mode= mode;
47
 
  info->current_record= UINT32_MAX;             /* No current record */
 
51
  info->current_record= (ulong) ~0L;            /* No current record */
48
52
  info->lastinx= info->errkey= -1;
49
 
  return(info);
 
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);
50
60
}
51
61
 
52
62
 
57
67
HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode)
58
68
{
59
69
  HP_INFO *info;
 
70
  DBUG_ENTER("heap_open_from_share_and_register");
60
71
 
61
72
  pthread_mutex_lock(&THR_LOCK_heap);
62
73
  if ((info= heap_open_from_share(share, mode)))
63
74
  {
64
 
    heap_open_list.push_front(info);
 
75
    info->open_list.data= (void*) info;
 
76
    heap_open_list= list_add(heap_open_list,&info->open_list);
65
77
  }
66
78
  pthread_mutex_unlock(&THR_LOCK_heap);
67
 
  return(info);
 
79
  DBUG_RETURN(info);
68
80
}
69
81
 
70
82
 
80
92
{
81
93
  HP_INFO *info;
82
94
  HP_SHARE *share;
 
95
  DBUG_ENTER("heap_open");
83
96
 
84
97
  pthread_mutex_lock(&THR_LOCK_heap);
85
98
  if (!(share= hp_find_named_heap(name)))
86
99
  {
87
 
    errno= ENOENT;
 
100
    my_errno= ENOENT;
88
101
    pthread_mutex_unlock(&THR_LOCK_heap);
89
 
    return(0);
 
102
    DBUG_RETURN(0);
90
103
  }
91
104
  if ((info= heap_open_from_share(share, mode)))
92
105
  {
93
 
    heap_open_list.push_front(info);
 
106
    info->open_list.data= (void*) info;
 
107
    heap_open_list= list_add(heap_open_list,&info->open_list);
94
108
  }
95
109
  pthread_mutex_unlock(&THR_LOCK_heap);
96
 
  return(info);
 
110
  DBUG_RETURN(info);
97
111
}
98
112
 
99
113
 
101
115
 
102
116
HP_SHARE *hp_find_named_heap(const char *name)
103
117
{
104
 
  list<HP_SHARE *>::iterator it= heap_share_list.begin();
105
 
  while (it != heap_share_list.end())
 
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)
106
124
  {
107
 
    if (!strcmp(name, (*it)->name))
 
125
    info= (HP_SHARE*) pos->data;
 
126
    if (!strcmp(name, info->name))
108
127
    {
109
 
      return (*it);
 
128
      DBUG_PRINT("exit", ("Old heap_database: 0x%lx", (long) info));
 
129
      DBUG_RETURN(info);
110
130
    }
111
 
    ++it;
112
131
  }
113
 
  return((HP_SHARE *) 0);
 
132
  DBUG_RETURN((HP_SHARE *) 0);
114
133
}
115
134
 
116
135